feat: 完善图像工作区与创作工具体验
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
type DesignCreateConversationInput,
|
||||
type DesignConfirmGenerationInput,
|
||||
type DesignCreateWorkspaceInput,
|
||||
type DesignGenerationParameters,
|
||||
type DesignRenameWorkspaceInput,
|
||||
type DesignSubmitMessageInput,
|
||||
} from '../../../shared/image-workspace';
|
||||
@@ -50,6 +51,25 @@ function asStringArray(value: unknown): string[] {
|
||||
: [];
|
||||
}
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === 'object' && !Array.isArray(value)
|
||||
? value as Record<string, unknown>
|
||||
: {};
|
||||
}
|
||||
|
||||
function generationParametersFromBody(body: Record<string, unknown>): DesignGenerationParameters {
|
||||
return {
|
||||
model: asString(body.model),
|
||||
resolution: asString(body.resolution),
|
||||
aspectRatio: asString(body.aspectRatio),
|
||||
durationSeconds: body.durationSeconds === null
|
||||
? null
|
||||
: typeof body.durationSeconds === 'number' && Number.isFinite(body.durationSeconds)
|
||||
? body.durationSeconds
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
const DESIGN_IMAGE_UPLOAD_MIME_TYPES = new Set([
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
@@ -390,6 +410,11 @@ export async function handleImageWorkspaceRoutes(
|
||||
return true;
|
||||
}
|
||||
|
||||
if (segments.length === 2 && segments[0] === 'workspaces' && req.method === 'DELETE') {
|
||||
sendData(res, await ctx.imageWorkspace.deleteWorkspace(segments[1]));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (segments.length === 2 && segments[0] === 'workspaces' && req.method === 'PATCH') {
|
||||
const body = await parseJsonBody<Record<string, unknown>>(req);
|
||||
const input: DesignRenameWorkspaceInput = {
|
||||
@@ -448,6 +473,20 @@ export async function handleImageWorkspaceRoutes(
|
||||
return true;
|
||||
}
|
||||
|
||||
if (segments.length === 4
|
||||
&& segments[0] === 'workspaces'
|
||||
&& segments[2] === 'generation-quotes'
|
||||
&& req.method === 'PATCH') {
|
||||
const body = await parseJsonBody<Record<string, unknown>>(req);
|
||||
sendData(res, await ctx.imageWorkspace.updateGenerationQuote({
|
||||
workspaceId: segments[1],
|
||||
quoteId: segments[3],
|
||||
finalPrompt: typeof body.finalPrompt === 'string' ? body.finalPrompt : '',
|
||||
generationParameters: generationParametersFromBody(body),
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (segments.length === 3
|
||||
&& segments[0] === 'workspaces'
|
||||
&& segments[2] === 'assets'
|
||||
@@ -489,6 +528,8 @@ export async function handleImageWorkspaceRoutes(
|
||||
quoteId: segments[5],
|
||||
clientTurnId: asString(body.clientTurnId),
|
||||
expectedTurnRevision: asInteger(body.expectedTurnRevision),
|
||||
finalPrompt: typeof body.finalPrompt === 'string' ? body.finalPrompt : '',
|
||||
generationParameters: generationParametersFromBody(asRecord(body.generationParameters)),
|
||||
};
|
||||
sendData(res, await ctx.imageWorkspace.confirmGeneration(input));
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user