|
|
@@ -190,6 +190,13 @@ export async function POST(request: NextRequest) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ if (path.isAbsolute(filePath)) {
|
|
|
+ return NextResponse.json(
|
|
|
+ { success: false, error: 'filePath 必须是相对路径' },
|
|
|
+ { status: 400 }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
const fullPath = path.join(projectPath, filePath);
|
|
|
const tmpPath = fullPath + '.tmp';
|
|
|
|
|
|
@@ -213,6 +220,13 @@ export async function POST(request: NextRequest) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ if (path.isAbsolute(filePath)) {
|
|
|
+ return NextResponse.json(
|
|
|
+ { success: false, error: 'filePath 必须是相对路径' },
|
|
|
+ { status: 400 }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
const fullPath = path.join(projectPath, filePath);
|
|
|
const stat = await fs.stat(fullPath);
|
|
|
const content = await fs.readFile(fullPath, 'utf-8');
|
|
|
@@ -250,6 +264,13 @@ export async function POST(request: NextRequest) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ if (path.isAbsolute(filePath)) {
|
|
|
+ return NextResponse.json(
|
|
|
+ { success: false, error: 'filePath 必须是相对路径' },
|
|
|
+ { status: 400 }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
const fullPath = path.join(projectPath, filePath);
|
|
|
await fs.unlink(fullPath);
|
|
|
|
|
|
@@ -266,6 +287,13 @@ export async function POST(request: NextRequest) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ if (path.isAbsolute(filePath)) {
|
|
|
+ return NextResponse.json(
|
|
|
+ { success: false, error: 'filePath 必须是相对路径' },
|
|
|
+ { status: 400 }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
const fullPath = path.join(projectPath, filePath);
|
|
|
|
|
|
// 检查文件是否存在
|