fix: add web project folder picker and isolated HTML file previews
This commit is contained in:
+18
-1
@@ -18,6 +18,7 @@ import { companionGateway } from './companion-gateway.mjs';
|
||||
import { inspectOperations } from './operations.mjs';
|
||||
import { validateModelWaitSettings } from '../core/models/request-deadline.mjs';
|
||||
import { nativeParameterSettings } from '../shared/contracts/native-parameters.mjs';
|
||||
import { localDirectories } from './local-directories.mjs';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -80,7 +81,7 @@ return async (request, response) => {
|
||||
response.setHeader('X-Frame-Options', 'DENY');
|
||||
// Scripts and API requests belong to this workbench origin. Inline styles
|
||||
// are limited to the existing React layout; model text never becomes HTML.
|
||||
response.setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'");
|
||||
response.setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self'; frame-src http://127.0.0.1:*; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'");
|
||||
const actualPort = getPort();
|
||||
if (server && (!server.listening || server.address().port !== actualPort)) throw new Error('本地执行宿主已经变化,请重新连接工作台。');
|
||||
const url = new URL(request.url, 'http://127.0.0.1:' + actualPort);
|
||||
@@ -285,6 +286,22 @@ return async (request, response) => {
|
||||
}
|
||||
return json(response, runtime.projectIndexer().status(project));
|
||||
}
|
||||
if (method === 'GET' && route === '/api/local-directories') return json(response, await localDirectories(url.searchParams.get('path') || ''));
|
||||
if (method === 'GET' && route === '/api/local-file-preview-access') return json(response, runtime.filePreviews?.access(url.searchParams.get('url') || '') || { allowed: false });
|
||||
const filePreview = route.match(/^\/api\/projects\/([a-f0-9-]+)\/file-previews(?:\/([a-f0-9-]+))?$/);
|
||||
if (filePreview) {
|
||||
const project = store.project(filePreview[1]);
|
||||
if (method === 'POST' && !filePreview[2]) {
|
||||
const input = await body(request);
|
||||
if (Object.keys(input).some(key => key !== 'path')) throw new Error('文件预览只接受项目相对路径。');
|
||||
return json(response, await runtime.localFilePreviews().start(project, input.path), 201);
|
||||
}
|
||||
if (method === 'DELETE' && filePreview[2]) {
|
||||
const input = await body(request);
|
||||
if (Object.keys(input).length) throw new Error('关闭预览不接受额外字段。');
|
||||
return json(response, runtime.filePreviews ? await runtime.filePreviews.close(project.id, filePreview[2]) : { closed: true });
|
||||
}
|
||||
}
|
||||
const projectMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/(files|file|inspection|code-index|code-query)$/);
|
||||
if (method === 'GET' && projectMatch) {
|
||||
const project = store.project(projectMatch[1]);
|
||||
|
||||
Reference in New Issue
Block a user