feat: 支持本地媒体存储与上传回退

This commit is contained in:
que01 committed 2026-10-12 01:39:56 +08:00
1 parent aa42e7b866
commit 6ac2d9421b
10 files changed
+256 -30

No files matched your search

+20
View File
@@ -2,10 +2,30 @@ import "reflect-metadata";
import { NestFactory } from "@nestjs/core";
import type { NestFastifyApplication } from "@nestjs/platform-fastify";
import { FastifyAdapter } from "@nestjs/platform-fastify";
import multipart from "@fastify/multipart";
import fastifyStatic from "@fastify/static";
import path from "node:path";
import { AppModule, configureApp } from "./app.module.js";
export async function createApp(): Promise<NestFastifyApplication> {
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
app
.getHttpAdapter()
.getInstance()
.addContentTypeParser(
["image/jpeg", "image/png", "image/webp", "image/avif"],
{ parseAs: "buffer", bodyLimit: 10 * 1024 * 1024 },
(_request: unknown, body: Buffer, done: (error: Error | null, body?: Buffer) => void) =>
done(null, body),
);
await app.register(multipart);
if (process.env.LOCAL_MEDIA_ROOT) {
await app.register(fastifyStatic, {
root: path.resolve(process.env.LOCAL_MEDIA_ROOT),
prefix: "/media/",
decorateReply: false,
});
}
configureApp(app);
return app;
}