前端修饰与渲染处理

This commit is contained in:
2026-04-26 03:34:47 +08:00
parent 35eff3faf6
commit 6b5ddac178
114 changed files with 18465 additions and 132 deletions

View File

@@ -0,0 +1,24 @@
import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common';
@Controller('characters')
export class CharacterController {
@Get()
findAll() {
return [];
}
@Get(':id')
findOne(@Param('id') id: string) {
return { id };
}
@Post()
create(@Body() body: any) {
return body;
}
@Delete(':id')
remove(@Param('id') id: string) {
return { id, deleted: true };
}
}

View File

@@ -0,0 +1,14 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
@Controller('chat')
export class ChatController {
@Get('history')
getHistory() {
return [];
}
@Post('message')
sendMessage(@Body() body: any) {
return { message: 'OK' };
}
}

View File

@@ -0,0 +1,14 @@
import { Controller, Get, Post } from '@nestjs/common';
@Controller('import-export')
export class ImportExportController {
@Get('export')
exportData() {
return { data: [] };
}
@Post('import')
importData() {
return { success: true };
}
}

View File

@@ -0,0 +1,14 @@
import { Controller, Get, Post, Body } from '@nestjs/common';
@Controller('llm')
export class LLMController {
@Get('providers')
getProviders() {
return ['openai', 'anthropic'];
}
@Post('chat')
chat(@Body() body: any) {
return { response: 'Hello' };
}
}

View File

@@ -0,0 +1,26 @@
import { ExceptionFilter, Catch, ArgumentsHost, HttpException, HttpStatus } from '@nestjs/common';
import { Request, Response } from 'express';
@Catch()
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest<Request>();
const status = exception instanceof HttpException
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
const message = exception instanceof HttpException
? exception.getResponse()
: 'Internal server error';
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message,
});
}
}

View File

@@ -0,0 +1,2 @@
export { LoggingInterceptor } from './logging.interceptor';
export { ResponseInterceptor } from './response.interceptor';

View File

@@ -0,0 +1,19 @@
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
@Injectable()
export class LoggingInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const request = context.switchToHttp().getRequest();
const method = request.method;
const url = request.url;
const now = Date.now();
return next.handle().pipe(
tap(() => {
console.log(`${method} ${url} - ${Date.now() - now}ms`);
}),
);
}
}

View File

@@ -0,0 +1,15 @@
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
export class ResponseInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map((data) => ({
success: true,
data,
})),
);
}
}

View File

@@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';
import * as fs from 'fs/promises';
import * as path from 'path';
@Injectable()
export class FileSystemRepository {
private dataDir: string;
constructor() {
this.dataDir = process.env.DATA_DIR || './data';
}
async readFile(filePath: string): Promise<string> {
const fullPath = path.join(this.dataDir, filePath);
return fs.readFile(fullPath, 'utf-8');
}
async writeFile(filePath: string, content: string): Promise<void> {
const fullPath = path.join(this.dataDir, filePath);
await fs.mkdir(path.dirname(fullPath), { recursive: true });
await fs.writeFile(fullPath, content, 'utf-8');
}
async deleteFile(filePath: string): Promise<void> {
const fullPath = path.join(this.dataDir, filePath);
await fs.unlink(fullPath);
}
async listFiles(dir: string): Promise<string[]> {
const fullPath = path.join(this.dataDir, dir);
return fs.readdir(fullPath);
}
}

View File

@@ -0,0 +1,20 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class CharacterService {
findAll() {
return [];
}
findOne(id: string) {
return { id };
}
create(data: any) {
return data;
}
remove(id: string) {
return { id };
}
}

View File

@@ -0,0 +1,12 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class ChatService {
getHistory() {
return [];
}
sendMessage(data: any) {
return data;
}
}