|
|
@@ -4,21 +4,13 @@ import path from "path";
|
|
|
|
|
|
const ROOT = process.env.NAS_ROOT_PATH;
|
|
|
|
|
|
-if (!ROOT) {
|
|
|
- console.warn(
|
|
|
- "[storage] NAS_ROOT_PATH ist nicht gesetzt – Dateizugriff wird fehlschlagen"
|
|
|
- );
|
|
|
-}
|
|
|
-
|
|
|
function fullPath(...segments) {
|
|
|
if (!ROOT) {
|
|
|
throw new Error("NAS_ROOT_PATH ist nicht gesetzt");
|
|
|
}
|
|
|
-
|
|
|
return path.join(ROOT, ...segments.map(String));
|
|
|
}
|
|
|
|
|
|
-// Hilfsfunktion: sortiert numerische Strings wie "1","2","10" korrekt
|
|
|
function sortNumericStrings(a, b) {
|
|
|
const na = parseInt(a, 10);
|
|
|
const nb = parseInt(b, 10);
|
|
|
@@ -30,7 +22,6 @@ function sortNumericStrings(a, b) {
|
|
|
|
|
|
export async function listBranches() {
|
|
|
const entries = await fs.readdir(fullPath(), { withFileTypes: true });
|
|
|
-
|
|
|
return entries
|
|
|
.filter(
|
|
|
(e) =>
|
|
|
@@ -47,7 +38,6 @@ export async function listBranches() {
|
|
|
export async function listYears(branch) {
|
|
|
const dir = fullPath(branch);
|
|
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
|
-
|
|
|
return entries
|
|
|
.filter((e) => e.isDirectory() && /^\d{4}$/.test(e.name))
|
|
|
.map((e) => e.name)
|
|
|
@@ -57,7 +47,6 @@ export async function listYears(branch) {
|
|
|
export async function listMonths(branch, year) {
|
|
|
const dir = fullPath(branch, year);
|
|
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
|
-
|
|
|
return entries
|
|
|
.filter((e) => e.isDirectory() && /^\d{1,2}$/.test(e.name))
|
|
|
.map((e) => e.name.padStart(2, "0"))
|
|
|
@@ -65,9 +54,8 @@ export async function listMonths(branch, year) {
|
|
|
}
|
|
|
|
|
|
export async function listDays(branch, year, month) {
|
|
|
- const dir = fullPath(branch, month.length === 1 ? year : year, month);
|
|
|
+ const dir = fullPath(branch, year, month);
|
|
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
|
-
|
|
|
return entries
|
|
|
.filter((e) => e.isDirectory() && /^\d{1,2}$/.test(e.name))
|
|
|
.map((e) => e.name.padStart(2, "0"))
|
|
|
@@ -76,14 +64,13 @@ export async function listDays(branch, year, month) {
|
|
|
|
|
|
export async function listFiles(branch, year, month, day) {
|
|
|
const dir = fullPath(branch, year, month, day);
|
|
|
- const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
|
+ const entries = await fs.readdir(dir);
|
|
|
|
|
|
return entries
|
|
|
.filter((name) => name.toLowerCase().endsWith(".pdf"))
|
|
|
.sort((a, b) => a.localeCompare(b, "de"))
|
|
|
.map((name) => ({
|
|
|
name,
|
|
|
- // relativer Pfad, den du später für Downloads nutzen kannst
|
|
|
relativePath: `${branch}/${year}/${month}/${day}/${name}`,
|
|
|
}));
|
|
|
}
|