Persist media uploads outside public/ to survive rebuilds and redeploys
Local Build and Deploy / deploy (push) Successful in 1m9s

Move media storage from public/assets/images/media to storage/media
(outside Git and public/), so uploaded images, favicons and logos are
preserved across rebuilds and git clean. Add a shared media-storage helper,
update the upload/serve actions and API routes, and gitignore storage/.
This commit is contained in:
openhands committed 2026-07-18 17:04:48 +02:00
1 parent 0d82f1325e
commit 1bbbf6e5a4
693 files changed
+38 -19

No files matched your search

+4 -3
View File
@@ -5,8 +5,9 @@ import path from "node:path";
import { revalidatePath } from "next/cache";
import { prisma } from "@/lib/prisma";
import { siteSettings } from "@/lib/services/site-settings";
import { resolveMediaPath } from "@/lib/media-storage";
const FAVICON_DIR = "public/assets/images/media/favicon";
const FAVICON_DIR = resolveMediaPath("favicon");
const MAX_SIZE = 2 * 1024 * 1024; // 2MB
const ALLOWED = [
"image/png",
@@ -42,7 +43,7 @@ export async function saveFavicon(
};
const ext = mimeExt[file.type] ?? "png";
const filename = `favicon-${Date.now()}.${ext}`;
const baseDir = path.resolve(process.cwd(), FAVICON_DIR);
const baseDir = FAVICON_DIR;
const filePath = path.resolve(baseDir, filename);
if (!filePath.startsWith(baseDir + path.sep)) {
return { success: false, error: "Invalid path" };
@@ -99,7 +100,7 @@ export async function deleteFavicon(): Promise<{
try {
const oldUrl = await siteSettings.get("cms_favicon");
if (oldUrl?.startsWith("/api/media/favicon/")) {
const baseDir = path.resolve(process.cwd(), FAVICON_DIR);
const baseDir = FAVICON_DIR;
const oldName = oldUrl.replace("/api/media/favicon/", "");
if (!oldName.includes("..") && !oldName.includes("/")) {
const oldPath = path.resolve(baseDir, oldName);