feat: 添加 sendOss 函数和文件流读取路由,支持文件发送功能

This commit is contained in:
2026-03-30 21:46:15 +08:00
parent 5b0a68ad67
commit 67ebed8d73
2 changed files with 46 additions and 0 deletions

View File

@@ -391,3 +391,20 @@ export const aiProxy = async (req: IncomingMessage, res: ServerResponse, opts: P
return getAiProxy(req, res, opts);
};
type SendOssOptions = {
/**
* 文件路径,必须
* 例如:/root/resources/demo/1.0.0/readme.md
*/
filepath: string;
user?: {
username?: string;
id?: string;
}
}
// TODO: 这个函数需要重构,应该放在一个独立的模块中,需要完善权限校验等功能,单实现文件发送功能
export const sendOss = async (res: ServerResponse, opts: SendOssOptions) => {
}

29
src/routes/file/stream.ts Normal file
View File

@@ -0,0 +1,29 @@
import { app } from '@/app.ts';
import { getFileStat, getMinioList, deleteFile, updateFileStat, deleteFileByPrefix } from './module/get-minio-list.ts';
import path from 'path';
import { CustomError } from '@kevisual/router';
import { callDetectAppVersion } from '../app-manager/export.ts';
import { UserId } from '../user/modules/user-id.ts';
import { z } from 'zod';
import { sendOss } from '@/modules/fm-manager/index.ts';
app.route({
path: 'file',
key: 'stream',
description: '文件读取图片文件等非文本文件的读取返回文件流send file 到前端',
middleware: ['auth'],
metadata: {
args: {
name: z.string().describe('文件路径, 例如/root/resources/demo/1.0.0/readme.md'),
}
}
}).define(async (ctx) => {
const name = ctx.args.name
if (!name) {
ctx.res.statusCode = 400
ctx.res.end('文件路径是必填项')
return
}
let objectName = name;
const tokenUser = ctx.state.tokenUser;
await sendOss(ctx.res, { filepath: objectName, user: tokenUser });
}).addTo(app)