feat: support local storage

This commit is contained in:
Hk-Gosuto
2024-01-05 18:41:16 +08:00
parent 8e10354109
commit 296df592e0
18 changed files with 181 additions and 56 deletions

View File

@@ -1,5 +1,7 @@
import { getServerSideConfig } from "@/app/config/server";
import LocalFileStorage from "@/app/utils/local_file_storage";
import S3FileStorage from "@/app/utils/s3_file_storage";
import { NextRequest, NextResponse } from "next/server";
import S3FileStorage from "../../../utils/s3_file_storage";
async function handle(
req: NextRequest,
@@ -10,12 +12,22 @@ async function handle(
}
try {
var file = await S3FileStorage.get(params.path[0]);
return new Response(file?.transformToWebStream(), {
headers: {
"Content-Type": "image/png",
},
});
const serverConfig = getServerSideConfig();
if (serverConfig.isStoreFileToLocal) {
var fileBuffer = await LocalFileStorage.get(params.path[0]);
return new Response(fileBuffer, {
headers: {
"Content-Type": "image/png",
},
});
} else {
var file = await S3FileStorage.get(params.path[0]);
return new Response(file?.transformToWebStream(), {
headers: {
"Content-Type": "image/png",
},
});
}
} catch (e) {
return new Response("not found", {
status: 404,
@@ -25,5 +37,5 @@ async function handle(
export const GET = handle;
export const runtime = "edge";
export const runtime = "nodejs";
export const revalidate = 0;