feat: 添加 sendOss 函数和文件流读取路由,支持文件发送功能
This commit is contained in:
@@ -391,3 +391,20 @@ export const aiProxy = async (req: IncomingMessage, res: ServerResponse, opts: P
|
|||||||
|
|
||||||
return getAiProxy(req, res, opts);
|
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
29
src/routes/file/stream.ts
Normal 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)
|
||||||
Reference in New Issue
Block a user