feature: Initial functional build

This commit is contained in:
Keith Solomon
2026-01-03 12:23:47 -06:00
parent cef53f2f2d
commit 046f08d559
10 changed files with 4672 additions and 2 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules/
.vscode/
notes/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -1,3 +1,14 @@
# Open Directory Downloader # OD-DL
A simple GUI for downloading from open web directories. GUI downloader for open directory listings (Apache/Nginx autoindex). No extra software required; uses built-in HTTP and optionally `wget` if available.
## Getting started
1. Install Node.js (LTS recommended).
2. Run `npm install`.
3. Run `npm start`.
## Notes
- The remote listing parser expects an autoindex HTML page (like Apache "Index of").
- Folder downloads can use `wget` automatically if detected and the checkbox is enabled.

4098
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
package.json Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "od-dl",
"version": "0.1.0",
"description": "GUI downloader for open directory listings",
"main": "src/main.js",
"author": "",
"license": "MIT",
"scripts": {
"start": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder"
},
"devDependencies": {
"electron": "^30.0.0",
"electron-builder": "^24.13.3"
}
}

49
src/index.html Normal file
View File

@@ -0,0 +1,49 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OD-DL</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<header class="toolbar">
<label for="remote-url">Contents of:</label>
<input id="remote-url" type="text" placeholder="http://example.com/" />
<button id="remote-submit">Submit</button>
</header>
<main class="grid">
<section class="panel">
<div class="panel-head">
<strong>Local Folder Tree</strong>
<div class="path-row">
<input id="local-path" type="text" readonly />
<button id="local-browse">Browse</button>
</div>
</div>
<div class="panel-body" id="local-list"></div>
</section>
<section class="panel">
<div class="panel-head">
<strong>Remote Folder Tree</strong>
<div class="path-row">
<button id="download-btn">Download Selected</button>
<label class="checkbox">
<input id="use-wget" type="checkbox" /> Use wget if available
</label>
</div>
</div>
<div class="panel-body" id="remote-list"></div>
</section>
</main>
<details class="log">
<summary>Log Section (Collapsed)</summary>
<div id="log-list"></div>
</details>
<script src="renderer.js"></script>
</body>
</html>

220
src/main.js Normal file
View File

@@ -0,0 +1,220 @@
const { app, BrowserWindow, dialog, ipcMain } = require('electron');
const path = require('path');
const fs = require('fs');
const os = require('os');
const http = require('http');
const https = require('https');
const { execFile } = require('child_process');
const state = {
hasWget: false,
};
function detectWget() {
return new Promise((resolve) => {
const cmd = process.platform === 'win32' ? 'where' : 'which';
execFile(cmd, ['wget'], (err, stdout) => {
if (err) {
resolve(false);
return;
}
resolve(Boolean(stdout && stdout.trim()));
});
});
}
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
});
win.loadFile(path.join(__dirname, 'index.html'));
}
function logToRenderer(message) {
const windows = BrowserWindow.getAllWindows();
if (!windows.length) return;
windows[0].webContents.send('log', message);
}
function listLocalDir(dirPath) {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
return entries.map((entry) => {
const fullPath = path.join(dirPath, entry.name);
let size = 0;
if (!entry.isDirectory()) {
try {
size = fs.statSync(fullPath).size;
} catch (err) {
size = 0;
}
}
return {
name: entry.name,
path: fullPath,
isDir: entry.isDirectory(),
size,
};
});
}
function fetchUrl(url) {
const client = url.startsWith('https') ? https : http;
return new Promise((resolve, reject) => {
const req = client.get(url, (res) => {
if (res.statusCode !== 200) {
reject(new Error(`HTTP ${res.statusCode}`));
res.resume();
return;
}
let data = '';
res.setEncoding('utf8');
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => resolve(data));
});
req.on('error', reject);
});
}
function parseApacheIndex(html, baseUrl) {
const results = [];
const preMatch = html.match(/<pre>[\s\S]*?<\/pre>/i);
const block = preMatch ? preMatch[0] : html;
const linkRegex = /<a href="([^"]+)">([^<]+)<\/a>/gi;
let match;
while ((match = linkRegex.exec(block)) !== null) {
const href = match[1];
const anchorText = match[2];
if (href === '../' || anchorText === '../') continue;
const isDir = href.endsWith('/');
const fullUrl = new URL(href, baseUrl).toString();
let name = anchorText;
try {
const urlObj = new URL(href, baseUrl);
let pathname = decodeURIComponent(urlObj.pathname);
if (pathname.endsWith('/')) {
pathname = pathname.slice(0, -1);
}
const derived = pathname.split('/').pop();
if (derived) {
name = isDir ? `${derived}/` : derived;
}
} catch (err) {
name = anchorText;
}
results.push({ name, href: fullUrl, isDir });
}
return results;
}
function downloadFile(url, destPath) {
const client = url.startsWith('https') ? https : http;
return new Promise((resolve, reject) => {
const fileStream = fs.createWriteStream(destPath);
const req = client.get(url, (res) => {
if (res.statusCode !== 200) {
reject(new Error(`HTTP ${res.statusCode}`));
res.resume();
return;
}
res.pipe(fileStream);
fileStream.on('finish', () => {
fileStream.close(resolve);
});
});
req.on('error', (err) => {
fs.unlink(destPath, () => reject(err));
});
});
}
async function downloadFolderRecursive(baseUrl, destDir) {
const html = await fetchUrl(baseUrl);
const items = parseApacheIndex(html, baseUrl);
for (const item of items) {
const targetPath = path.join(destDir, item.name.replace(/\/$/, ''));
if (item.isDir) {
fs.mkdirSync(targetPath, { recursive: true });
logToRenderer(`Entering ${item.href}`);
await downloadFolderRecursive(item.href, targetPath);
} else {
logToRenderer(`Downloading ${item.href}`);
await downloadFile(item.href, targetPath);
}
}
}
async function downloadWithWget(url, destDir) {
return new Promise((resolve, reject) => {
const args = ['-r', '-np', '-nH', '--cut-dirs=0', '-P', destDir, url];
const proc = execFile('wget', args, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
proc.stdout.on('data', (data) => logToRenderer(data.toString()));
proc.stderr.on('data', (data) => logToRenderer(data.toString()));
});
}
app.whenReady().then(async () => {
state.hasWget = await detectWget();
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.handle('get-capabilities', () => {
return { hasWget: state.hasWget };
});
ipcMain.handle('select-local-dir', async () => {
const result = await dialog.showOpenDialog({ properties: ['openDirectory'] });
if (result.canceled || result.filePaths.length === 0) return null;
return result.filePaths[0];
});
ipcMain.handle('list-local-dir', (_event, dirPath) => {
return listLocalDir(dirPath);
});
ipcMain.handle('list-remote-dir', async (_event, url) => {
const html = await fetchUrl(url);
return parseApacheIndex(html, url);
});
ipcMain.handle('download-item', async (_event, payload) => {
const { url, destDir, isDir, useWget } = payload;
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
if (isDir) {
if (useWget && state.hasWget) {
logToRenderer(`wget: ${url}`);
await downloadWithWget(url, destDir);
return;
}
await downloadFolderRecursive(url, destDir);
return;
}
const fileName = path.basename(new URL(url).pathname);
const destPath = path.join(destDir, fileName);
logToRenderer(`Downloading ${url}`);
await downloadFile(url, destPath);
});

10
src/preload.js Normal file
View File

@@ -0,0 +1,10 @@
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('oddl', {
getCapabilities: () => ipcRenderer.invoke('get-capabilities'),
selectLocalDir: () => ipcRenderer.invoke('select-local-dir'),
listLocalDir: (dirPath) => ipcRenderer.invoke('list-local-dir', dirPath),
listRemoteDir: (url) => ipcRenderer.invoke('list-remote-dir', url),
downloadItem: (payload) => ipcRenderer.invoke('download-item', payload),
onLog: (callback) => ipcRenderer.on('log', (_event, message) => callback(message)),
});

133
src/renderer.js Normal file
View File

@@ -0,0 +1,133 @@
const state = {
localDir: '',
remoteUrl: '',
localEntries: [],
remoteEntries: [],
hasWget: false,
};
const el = {
remoteInput: document.querySelector('#remote-url'),
remoteSubmit: document.querySelector('#remote-submit'),
remoteList: document.querySelector('#remote-list'),
localPath: document.querySelector('#local-path'),
localBrowse: document.querySelector('#local-browse'),
localList: document.querySelector('#local-list'),
downloadBtn: document.querySelector('#download-btn'),
useWget: document.querySelector('#use-wget'),
logList: document.querySelector('#log-list'),
};
function log(message) {
const line = document.createElement('div');
line.textContent = message;
el.logList.prepend(line);
}
function renderLocal() {
el.localList.innerHTML = '';
state.localEntries.forEach((entry) => {
const row = document.createElement('div');
row.className = 'row';
row.textContent = entry.isDir ? `[${entry.name}]` : entry.name;
row.addEventListener('dblclick', async () => {
if (!entry.isDir) return;
state.localDir = entry.path;
await refreshLocal();
});
el.localList.appendChild(row);
});
}
function renderRemote() {
el.remoteList.innerHTML = '';
state.remoteEntries.forEach((entry) => {
const row = document.createElement('div');
row.className = 'row';
row.textContent = entry.isDir ? `[${entry.name}]` : entry.name;
row.addEventListener('dblclick', async () => {
if (!entry.isDir) return;
state.remoteUrl = entry.href;
el.remoteInput.value = state.remoteUrl;
await refreshRemote();
});
row.addEventListener('click', () => {
el.remoteList.querySelectorAll('.selected').forEach((n) => n.classList.remove('selected'));
row.classList.add('selected');
row.dataset.href = entry.href;
row.dataset.isDir = entry.isDir ? '1' : '0';
});
el.remoteList.appendChild(row);
});
}
async function refreshLocal() {
if (!state.localDir) return;
const entries = await window.oddl.listLocalDir(state.localDir);
state.localEntries = entries;
el.localPath.value = state.localDir;
renderLocal();
}
async function refreshRemote() {
if (!state.remoteUrl) return;
const entries = await window.oddl.listRemoteDir(state.remoteUrl);
state.remoteEntries = entries;
renderRemote();
}
async function init() {
const caps = await window.oddl.getCapabilities();
state.hasWget = caps.hasWget;
el.useWget.disabled = !state.hasWget;
if (!state.hasWget) {
el.useWget.checked = false;
}
const home = await window.oddl.selectLocalDir();
if (home) {
state.localDir = home;
await refreshLocal();
}
}
el.localBrowse.addEventListener('click', async () => {
const dir = await window.oddl.selectLocalDir();
if (!dir) return;
state.localDir = dir;
await refreshLocal();
});
el.remoteSubmit.addEventListener('click', async () => {
const url = el.remoteInput.value.trim();
if (!url) return;
state.remoteUrl = url;
await refreshRemote();
});
el.downloadBtn.addEventListener('click', async () => {
const selected = el.remoteList.querySelector('.selected');
if (!selected) {
log('Select a remote file or folder first.');
return;
}
if (!state.localDir) {
log('Choose a local destination first.');
return;
}
const href = selected.dataset.href;
const isDir = selected.dataset.isDir === '1';
log(`Queueing ${href}`);
await window.oddl.downloadItem({
url: href,
destDir: state.localDir,
isDir,
useWget: el.useWget.checked,
});
log('Done.');
await refreshLocal();
});
window.oddl.onLog((message) => log(message));
init().catch((err) => log(err.message));

129
src/styles.css Normal file
View File

@@ -0,0 +1,129 @@
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
}
body {
margin: 0;
font-family: "Segoe UI", Tahoma, sans-serif;
background: #f4f6f8;
color: #111;
display: flex;
flex-direction: column;
overflow: hidden;
}
.toolbar {
display: flex;
align-items: center;
gap: 12px;
padding: 16px 24px;
background: #ffffff;
border-bottom: 1px solid #d5d7db;
}
.toolbar input {
flex: 1;
padding: 8px 10px;
border: 1px solid #c6c8cc;
border-radius: 4px;
}
.toolbar button {
padding: 8px 12px;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
padding: 24px;
flex: 1;
min-height: 0;
}
.panel {
background: #ffffff;
border: 1px solid #d5d7db;
border-radius: 6px;
display: flex;
flex-direction: column;
min-height: 520px;
}
.panel-head {
padding: 16px;
border-bottom: 1px solid #e1e3e6;
display: flex;
flex-direction: column;
gap: 12px;
}
.panel-body {
padding: 12px 16px;
overflow-y: auto;
overflow-x: auto;
flex: 1;
min-height: 0;
}
.path-row {
display: flex;
gap: 8px;
align-items: center;
}
.path-row input {
flex: 1;
padding: 6px 10px;
border: 1px solid #c6c8cc;
border-radius: 4px;
}
.row {
padding: 6px 8px;
border-radius: 4px;
cursor: pointer;
white-space: nowrap;
}
.row:hover {
background: #eef2f6;
}
.row.selected {
background: #dbe7ff;
}
.log {
margin: 0 24px 24px;
border: 1px solid #d5d7db;
border-radius: 6px;
background: #ffffff;
flex-shrink: 0;
}
#log-list {
padding: 12px 16px;
font-family: Consolas, monospace;
font-size: 12px;
max-height: 200px;
overflow-y: auto;
}
.checkbox {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
}
@media (max-width: 900px) {
.grid {
grid-template-columns: 1fr;
}
}