Add site-scoped file manager navigation and original file downloads
DC CMS qualification / qualify (push) Successful in 1m53s
DC CMS qualification / qualify (push) Successful in 1m53s
This commit is contained in:
@@ -11,6 +11,7 @@ import SftpClient from "ssh2-sftp-client";
|
||||
import AdmZip from "adm-zip";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { createSiteBackup, siteBackupFilename } from "./site-backup.mjs";
|
||||
import { openMediaDownload } from "./media-download.mjs";
|
||||
|
||||
const cmsRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const port = Number(process.env.PORT || 8090);
|
||||
@@ -3034,6 +3035,21 @@ async function handle(req, res) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "GET" && url.pathname === "/api/media/download") {
|
||||
let download;
|
||||
try {
|
||||
download = await openMediaDownload(repoRoot, url.searchParams.get("path"));
|
||||
} catch (error) {
|
||||
const status = error.status || (["ENOENT", "ENOTDIR"].includes(error.code) ? 404 : 500);
|
||||
sendJson(res, status, { ok: false, error: status === 404 ? "Файл не найден" : status === 500 ? "Не удалось скачать файл" : error.message });
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, download.headers);
|
||||
// Stream large videos directly to the browser; do not hold a Blob in memory.
|
||||
pipeline(download.handle.createReadStream(), res).catch(() => {});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "GET" && url.pathname === "/api/media/site-size") {
|
||||
sendJson(res, 200, await calculateProjectSize());
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user