fix(admin): serve media from private storage
This commit is contained in:
parent
d9da86dd46
commit
faddaa91d0
14 changed files with 114 additions and 20 deletions
|
|
@ -6,7 +6,7 @@ STAMP="$(date +%Y%m%d-%H%M%S)"
|
|||
TARGET="${BACKUP_DIR}/funktechnik-data-${STAMP}.tar.gz"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
tar -czf "$TARGET" data public/uploads
|
||||
tar -czf "$TARGET" data storage
|
||||
|
||||
echo "Backup erstellt: $TARGET"
|
||||
echo "Hinweis: .env wird aus Sicherheitsgruenden nicht automatisch gesichert."
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const path = require("path");
|
|||
const requiredEnv = ["ADMIN_EMAIL", "ADMIN_PASSWORD", "ADMIN_SESSION_SECRET"];
|
||||
const requiredDirs = [
|
||||
path.join(process.cwd(), "data"),
|
||||
path.join(process.cwd(), "public", "uploads", "images"),
|
||||
path.join(process.cwd(), "storage", "uploads", "images"),
|
||||
path.join(process.cwd(), ".next", "cache"),
|
||||
];
|
||||
|
||||
|
|
@ -21,6 +21,26 @@ function ensureWritableDirectory(directory) {
|
|||
fs.rmSync(probe, { force: true });
|
||||
}
|
||||
|
||||
function migrateLegacyUploads() {
|
||||
const legacyDirectory = path.join(process.cwd(), "public", "uploads", "images");
|
||||
const storageDirectory = path.join(process.cwd(), "storage", "uploads", "images");
|
||||
|
||||
if (!fs.existsSync(legacyDirectory)) return;
|
||||
|
||||
fs.mkdirSync(storageDirectory, { recursive: true });
|
||||
for (const fileName of fs.readdirSync(legacyDirectory)) {
|
||||
if (fileName.startsWith(".")) continue;
|
||||
|
||||
const source = path.join(legacyDirectory, fileName);
|
||||
const target = path.join(storageDirectory, fileName);
|
||||
const sourceStat = fs.statSync(source);
|
||||
|
||||
if (sourceStat.isFile() && !fs.existsSync(target)) {
|
||||
fs.copyFileSync(source, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const missingEnv = requiredEnv.filter((name) => !process.env[name]);
|
||||
if (missingEnv.length > 0) {
|
||||
fail(`Start abgebrochen: fehlende Umgebungsvariablen: ${missingEnv.join(", ")}. Bitte .env anhand von .env.example konfigurieren.`);
|
||||
|
|
@ -28,6 +48,7 @@ if (missingEnv.length > 0) {
|
|||
|
||||
try {
|
||||
for (const directory of requiredDirs) ensureWritableDirectory(directory);
|
||||
migrateLegacyUploads();
|
||||
} catch (error) {
|
||||
fail(`Start abgebrochen: Runtime-Verzeichnis ist nicht beschreibbar. Details: ${error instanceof Error ? error.message : "unbekannter Fehler"}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue