✨feature: Directory tree and multi-column file listing
This commit is contained in:
19
src/main.js
19
src/main.js
@@ -88,9 +88,11 @@ 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 preLines = preMatch ? preMatch[0].split(/\r?\n/) : block.split(/\r?\n/);
|
||||
const linkRegex = /<a href="([^"]+)">([^<]+)<\/a>/i;
|
||||
for (const line of preLines) {
|
||||
const match = line.match(linkRegex);
|
||||
if (!match) continue;
|
||||
const href = match[1];
|
||||
const anchorText = match[2];
|
||||
if (href === '../' || anchorText === '../') continue;
|
||||
@@ -110,7 +112,16 @@ function parseApacheIndex(html, baseUrl) {
|
||||
} catch (err) {
|
||||
name = anchorText;
|
||||
}
|
||||
results.push({ name, href: fullUrl, isDir });
|
||||
let size = '-';
|
||||
const rest = line.slice(match.index + match[0].length).trim();
|
||||
if (rest) {
|
||||
const tokens = rest.split(/\s+/);
|
||||
const sizeToken = tokens[tokens.length - 1];
|
||||
if (sizeToken && sizeToken !== '-') {
|
||||
size = sizeToken;
|
||||
}
|
||||
}
|
||||
results.push({ name, href: fullUrl, isDir, size });
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user