rashevskyv / dbi

Author is duckbill
2.19k stars 93 forks source link

Support home network directoryListing from NodeJS #257

Closed Clearmist closed 1 year ago

Clearmist commented 1 year ago

DBI version: 598

NodeJS has a built-in webserver like Apache and nginx. I created a directoryListing using NodeJS and Express, but DBI does not recognize the contents being served. I see the notification "This view contains no items".

Reproduce

Install dependencies

Install NodeJS then run this command inside of a new directory: npm install express serve-index

Create test.mjs file

Customize the script by giving it a path to some of your NSP files. This is done by editing the const source variable.

Examples Windows: C:\\Users\\Test\\Switch Linux: /users/Test/Switch

import path from 'path';
import os from 'os';
import express from 'express';
import serveIndex from 'serve-index';

// Get the local address of this computer.
const localAddress = Object.entries(os.networkInterfaces()).reduce(
  (acc, iface) => [
    ...acc,
    ...(iface[1].reduce((acc, address) => acc || (address.family === 'IPv4' && !address.internal), false)
      ? [
          {
            name: iface[0],
            ip: iface[1]
              .filter((address) => address.family === 'IPv4' && !address.internal)
              .map((address) => address.address)[0],
          },
        ]
      : []),
  ],
  []
);

const app = express();
const port = 3000;
const source = path.normalize('C:\\Users\\Test\\Switch');

app.use(express.static(source), serveIndex(source));

app.listen(port, localAddress, () => {
  console.log(`Serving from port ${port} and source directory ${source}`);
});

Run the server

node test.mjs

Connect within DBI

Connect to the server from within DBI using your computer's local network address.

http://192.168.1.10:3000

Example html response

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>listing directory /</title>
    <style>...</style>
    <script>...</script>
  </head>
  <body class="directory">
    <input id="search" type="text" placeholder="Search" autocomplete="off" />
    <div id="wrapper">
      <h1><a href="/">~</a> / </h1>
      <ul id="files" class="view-tiles">
        <li>
          <a class="" href="/test.nsz" title="test.nsz">
            <span class="name">test.nsz</span>
            <span class="size">102791564</span>
            <span class="date">9/22/2021 7:55:20 PM</span>
          </a>
        </li>
      </ul>
    </div>
  </body>
</html>
ghost commented 1 year ago

Dbi поддерживает формат листинга у apache. Другие форматы листинга не поддерживаются.