feat: save logos to media/logo/ subdir, add Logo generator link to admin dropdown
This commit is contained in:
1 parent
917437c5ef
commit
f3367e9b7b
4 files changed
+17
-11
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 711 B |
@@ -1,12 +1,12 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { writeFile } from "fs/promises";
|
||||
import { mkdir, writeFile } from "fs/promises";
|
||||
import path from "path";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
|
||||
const MEDIA_DIR = "public/assets/images/media";
|
||||
const MEDIA_DIR = "public/assets/images/media/logo";
|
||||
|
||||
export async function saveLogo(formData: FormData): Promise<{ success: boolean; url?: string; error?: string }> {
|
||||
try {
|
||||
@@ -20,9 +20,10 @@ export async function saveLogo(formData: FormData): Promise<{ success: boolean;
|
||||
const filePath = path.join(dir, filename);
|
||||
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
await mkdir(dir, { recursive: true });
|
||||
await writeFile(filePath, buffer);
|
||||
|
||||
const url = `/api/media/${filename}`;
|
||||
const url = `/api/media/logo/${filename}`;
|
||||
|
||||
await prisma.websiteSetting.upsert({
|
||||
where: { key: "cms_logo" },
|
||||
@@ -53,9 +54,10 @@ export async function saveLogoFromUrl(gifUrl: string): Promise<{ success: boolea
|
||||
const dir = path.join(process.cwd(), MEDIA_DIR);
|
||||
const filePath = path.join(dir, filename);
|
||||
|
||||
await mkdir(dir, { recursive: true });
|
||||
await writeFile(filePath, buffer);
|
||||
|
||||
const url = `/api/media/${filename}`;
|
||||
const url = `/api/media/logo/${filename}`;
|
||||
|
||||
await prisma.websiteSetting.upsert({
|
||||
where: { key: "cms_logo" },
|
||||
|
||||
@@ -10,11 +10,12 @@ const ALLOWED_EXT = [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp"];
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ name: string }> },
|
||||
{ params }: { params: Promise<{ path: string[] }> },
|
||||
) {
|
||||
const { name } = await params;
|
||||
const { path: segments } = await params;
|
||||
const name = segments.join("/");
|
||||
// Prevent path traversal
|
||||
if (name.includes("..") || name.includes("/") || name.includes("\\")) {
|
||||
if (name.includes("..") || name.includes("\\")) {
|
||||
return new NextResponse("Forbidden", { status: 403 });
|
||||
}
|
||||
const ext = path.extname(name).toLowerCase();
|
||||
@@ -76,10 +76,13 @@ export async function TopHeader() {
|
||||
<Link href="/admin/commandocentrum" className="dropdown-item" role="menuitem">
|
||||
Commandocentrum
|
||||
</Link>
|
||||
<Link href="/admin/logs" className="dropdown-item" role="menuitem">
|
||||
Logs
|
||||
</Link>
|
||||
</div>
|
||||
<Link href="/admin/logs" className="dropdown-item" role="menuitem">
|
||||
Logs
|
||||
</Link>
|
||||
<Link href="/logo" className="dropdown-item" role="menuitem">
|
||||
Logo generator
|
||||
</Link>
|
||||
</div>
|
||||
</details>
|
||||
) : null}
|
||||
|
||||
|
||||
Reference in new issue
Block a user