update
This commit is contained in:
22
assistant/src/module/get-header-token.ts
Normal file
22
assistant/src/module/get-header-token.ts
Normal 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;
|
||||
}
|
||||
32
assistant/src/module/upload/mv.ts
Normal file
32
assistant/src/module/upload/mv.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user