|
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
import { promises as fs } from 'fs';
|
|
import { promises as fs } from 'fs';
|
|
|
import path from 'path';
|
|
import path from 'path';
|
|
|
import { WorldStateFile, NovelProject } from '@/app/lib/novel-types';
|
|
import { WorldStateFile, NovelProject } from '@/app/lib/novel-types';
|
|
|
-import { isPathSafe } from '@/app/lib/novel-server-utils';
|
|
|
|
|
|
|
+import { isPathSafe, isFilePathSafe } from '@/app/lib/novel-server-utils';
|
|
|
import { spawn } from 'child_process';
|
|
import { spawn } from 'child_process';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -183,7 +183,7 @@ export async function POST(request: NextRequest) {
|
|
|
content: string;
|
|
content: string;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- if (!filePath || !isPathSafe(filePath)) {
|
|
|
|
|
|
|
+ if (!filePath || !isFilePathSafe(filePath)) {
|
|
|
return NextResponse.json(
|
|
return NextResponse.json(
|
|
|
{ success: false, error: '路径不合法' },
|
|
{ success: false, error: '路径不合法' },
|
|
|
{ status: 400 }
|
|
{ status: 400 }
|
|
@@ -213,7 +213,7 @@ export async function POST(request: NextRequest) {
|
|
|
case 'read': {
|
|
case 'read': {
|
|
|
const { filePath } = body as { filePath: string };
|
|
const { filePath } = body as { filePath: string };
|
|
|
|
|
|
|
|
- if (!filePath || !isPathSafe(filePath)) {
|
|
|
|
|
|
|
+ if (!filePath || !isFilePathSafe(filePath)) {
|
|
|
return NextResponse.json(
|
|
return NextResponse.json(
|
|
|
{ success: false, error: '路径不合法' },
|
|
{ success: false, error: '路径不合法' },
|
|
|
{ status: 400 }
|
|
{ status: 400 }
|
|
@@ -257,7 +257,7 @@ export async function POST(request: NextRequest) {
|
|
|
case 'delete': {
|
|
case 'delete': {
|
|
|
const { filePath } = body as { filePath: string };
|
|
const { filePath } = body as { filePath: string };
|
|
|
|
|
|
|
|
- if (!filePath || !isPathSafe(filePath)) {
|
|
|
|
|
|
|
+ if (!filePath || !isFilePathSafe(filePath)) {
|
|
|
return NextResponse.json(
|
|
return NextResponse.json(
|
|
|
{ success: false, error: '路径不合法' },
|
|
{ success: false, error: '路径不合法' },
|
|
|
{ status: 400 }
|
|
{ status: 400 }
|
|
@@ -280,7 +280,7 @@ export async function POST(request: NextRequest) {
|
|
|
case 'open': {
|
|
case 'open': {
|
|
|
const { filePath } = body as { filePath: string };
|
|
const { filePath } = body as { filePath: string };
|
|
|
|
|
|
|
|
- if (!filePath || !isPathSafe(filePath)) {
|
|
|
|
|
|
|
+ if (!filePath || !isFilePathSafe(filePath)) {
|
|
|
return NextResponse.json(
|
|
return NextResponse.json(
|
|
|
{ success: false, error: '路径不合法' },
|
|
{ success: false, error: '路径不合法' },
|
|
|
{ status: 400 }
|
|
{ status: 400 }
|