Refactor image upload handling by moving upload directory outside of public folder for better compatibility with Next.js. Update related Docker configurations and scripts to reflect new upload paths. Replace instances of Next.js Image component with CmsImage for consistent image handling across the application.

This commit is contained in:
smhk1376 committed 2026-10-22 12:51:18 +03:30
1 parent 0a57ef2b80
commit 1641edfd01
19 files changed
+162 -39

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import Image from "next/image";
import { getTranslations } from "next-intl/server";
import { CmsImage } from "@/components/atoms/CmsImage";
import { Container } from "@/components/atoms/Container";
import { Heading } from "@/components/atoms/Heading";
import { Section } from "@/components/atoms/Section";
@@ -41,7 +41,7 @@ export default async function AlumniPage() {
className="scroll-mt-24"
>
<div className="relative aspect-[16/10] bg-muted">
<Image
<CmsImage
src={story.imageUrl}
alt={story.name}
fill
+2 -2
View File
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import Image from "next/image";
import { notFound } from "next/navigation";
import { CmsImage } from "@/components/atoms/CmsImage";
import { Container } from "@/components/atoms/Container";
import { Section } from "@/components/atoms/Section";
import { TextLink } from "@/components/atoms/TextLink";
@@ -56,7 +56,7 @@ export default async function InsightDetailPage({ params }: Props) {
<Section tone="subtle">
<Container narrow>
<div className="relative mb-10 aspect-[16/9] overflow-hidden rounded-2xl bg-muted ring-1 ring-foreground/10">
<Image
<CmsImage
src={article.imageUrl}
alt={article.title}
fill
+60
View File
@@ -0,0 +1,60 @@
import { readFile, stat } from "node:fs/promises";
import path from "node:path";
import { NextResponse } from "next/server";
import {
mimeForUploadExt,
resolveStoredUploadPath,
} from "@/lib/uploads/image";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
type RouteParams = { params: Promise<{ path: string[] }> };
async function lookupUpload(segments: string[]) {
const absolutePath = resolveStoredUploadPath(segments);
if (!absolutePath) return null;
try {
const info = await stat(absolutePath);
if (!info.isFile()) return null;
const mime = mimeForUploadExt(path.extname(absolutePath));
if (!mime) return null;
return { absolutePath, info, mime };
} catch {
return null;
}
}
function headersFor(file: { info: { size: number }; mime: string }) {
return {
"Content-Type": file.mime,
"Content-Length": String(file.info.size),
"Cache-Control": "public, max-age=31536000, immutable",
};
}
export async function GET(_request: Request, { params }: RouteParams) {
const { path: segments } = await params;
const file = await lookupUpload(segments);
if (!file) {
return new NextResponse("Not found", { status: 404 });
}
const buffer = await readFile(file.absolutePath);
return new NextResponse(buffer, {
status: 200,
headers: headersFor(file),
});
}
export async function HEAD(_request: Request, { params }: RouteParams) {
const { path: segments } = await params;
const file = await lookupUpload(segments);
if (!file) {
return new NextResponse(null, { status: 404 });
}
return new NextResponse(null, {
status: 200,
headers: headersFor(file),
});
}