This commit is contained in:
2026-01-17 14:48:49 +08:00
parent b9b4c993f4
commit 0b5a0557ee
14 changed files with 613 additions and 233 deletions

View File

@@ -0,0 +1,22 @@
import http from 'http';
import * as cookie from '@kevisual/router/src/server/cookie.ts';
export const getTokenFromRequest = (req: http.IncomingMessage) => {
let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || '';
const url = new URL(req.url || '', 'http://localhost');
if (!token) {
token = url.searchParams.get('token') || '';
}
if (!token) {
const parsedCookies = cookie.parse(req.headers.cookie || '');
token = parsedCookies.token || '';
}
if (token) {
token = token.replace('Bearer ', '');
}
return token;
}
export const getTokenFromContext = (ctx: any) => {
return ctx.query.token;
}

View File

@@ -0,0 +1,32 @@
import type { AssistantConfig } from '@/module/assistant/index.ts';
import fs from 'node:fs';
import path from 'node:path';
export class UploadManager {
config: AssistantConfig;
constructor(config: AssistantConfig) {
this.config = config;
}
mvFile(opts: {
temppath: string;
type: 'file' | 's3';
targetPath: string;
}) {
const { type, temppath, targetPath } = opts;
if (type === 'file') {
const pageDir = this.config.configPath?.pagesDir!;
const fullTargetPath = targetPath.startsWith('/')
? targetPath
: path.join(pageDir, targetPath);
const targetDir = fullTargetPath.substring(0, fullTargetPath.lastIndexOf('/'));
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
fs.renameSync(temppath, fullTargetPath);
return fullTargetPath;
}
}
}
export const uploadManager = (config: AssistantConfig) => {
return new UploadManager(config);
}