fix: reduce scale adjust reference uploads
This commit is contained in:
parent
a3a69fed43
commit
c9b6df55b0
@ -3080,6 +3080,7 @@ async function buildScaleAdjustVisualLayoutGuideBuffer(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createScaleAdjustPatchReference(params: {
|
async function createScaleAdjustPatchReference(params: {
|
||||||
|
fullFrameReferenceOnly?: boolean;
|
||||||
regions: NormalizedLocalEditRegion[];
|
regions: NormalizedLocalEditRegion[];
|
||||||
scalePercent?: ScaleAdjustPercent | null;
|
scalePercent?: ScaleAdjustPercent | null;
|
||||||
sourceBuffer: Buffer;
|
sourceBuffer: Buffer;
|
||||||
@ -3116,6 +3117,24 @@ async function createScaleAdjustPatchReference(params: {
|
|||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
const targetDraftBuffer = targetDraftReference.buffer;
|
const targetDraftBuffer = targetDraftReference.buffer;
|
||||||
|
const suffix = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||||
|
if (params.fullFrameReferenceOnly && structureLockAppliedRef.value) {
|
||||||
|
const targetDraftFullUpload = await uploadFile(
|
||||||
|
`canvas-scale-adjust-full-target-draft-${suffix}.png`,
|
||||||
|
toArrayBuffer(targetDraftBuffer)
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
compositeClipMaskUrl: null,
|
||||||
|
sourceCropUrl: sourceImageUrl || targetDraftFullUpload.url,
|
||||||
|
structureLockedDraft: structureLockAppliedRef.value,
|
||||||
|
targetDraftFullUrl: targetDraftFullUpload.url,
|
||||||
|
targetDraftUrl: targetDraftFullUpload.url,
|
||||||
|
workspacePixelRect,
|
||||||
|
workspaceRect,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const [sourceCropBuffer, targetDraftCropBuffer] = await Promise.all([
|
const [sourceCropBuffer, targetDraftCropBuffer] = await Promise.all([
|
||||||
sharp(sourceBuffer, { failOn: "none" })
|
sharp(sourceBuffer, { failOn: "none" })
|
||||||
.extract(workspacePixelRect)
|
.extract(workspacePixelRect)
|
||||||
@ -3126,7 +3145,6 @@ async function createScaleAdjustPatchReference(params: {
|
|||||||
.png({ compressionLevel: 6 })
|
.png({ compressionLevel: 6 })
|
||||||
.toBuffer(),
|
.toBuffer(),
|
||||||
]);
|
]);
|
||||||
const suffix = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
||||||
const [
|
const [
|
||||||
sourceCropUpload,
|
sourceCropUpload,
|
||||||
targetDraftUpload,
|
targetDraftUpload,
|
||||||
@ -4354,10 +4372,41 @@ export async function POST(request: NextRequest) {
|
|||||||
isScaleAdjustOperation &&
|
isScaleAdjustOperation &&
|
||||||
!useScaleAdjustPatchWorkflow &&
|
!useScaleAdjustPatchWorkflow &&
|
||||||
!useProviderTextOnlyCoordinatePrompt;
|
!useProviderTextOnlyCoordinatePrompt;
|
||||||
const annotatedBuffer = isScaleAdjustOperation
|
const shouldUploadAnnotatedReference =
|
||||||
? useScaleAdjustCoordinatePrompt
|
!isScaleAdjustOperation || sendScaleAdjustAnnotatedReferenceToModel;
|
||||||
? useScaleAdjustVisualLayoutGuide
|
const annotatedBuffer = shouldUploadAnnotatedReference
|
||||||
? (
|
? isScaleAdjustOperation
|
||||||
|
? useScaleAdjustCoordinatePrompt
|
||||||
|
? useScaleAdjustVisualLayoutGuide
|
||||||
|
? (
|
||||||
|
await buildScaleAdjustVisualLayoutGuideBuffer({
|
||||||
|
regions,
|
||||||
|
scalePercent,
|
||||||
|
sourceBuffer,
|
||||||
|
sourceHeight,
|
||||||
|
sourceWidth,
|
||||||
|
})
|
||||||
|
).buffer
|
||||||
|
: useScaleAdjustMarkedPhotoGuide
|
||||||
|
? await buildScaleAdjustMarkedPhotoGuideBuffer({
|
||||||
|
height: sourceHeight,
|
||||||
|
regions,
|
||||||
|
scalePercent,
|
||||||
|
sourceBuffer,
|
||||||
|
width: sourceWidth,
|
||||||
|
})
|
||||||
|
: await sharp(
|
||||||
|
buildScaleAdjustZoomedCoordinateSvg({
|
||||||
|
height: sourceHeight,
|
||||||
|
regions,
|
||||||
|
scalePercent,
|
||||||
|
width: sourceWidth,
|
||||||
|
}),
|
||||||
|
{ failOn: "none" }
|
||||||
|
)
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
|
.toBuffer()
|
||||||
|
: (
|
||||||
await buildScaleAdjustVisualLayoutGuideBuffer({
|
await buildScaleAdjustVisualLayoutGuideBuffer({
|
||||||
regions,
|
regions,
|
||||||
scalePercent,
|
scalePercent,
|
||||||
@ -4366,54 +4415,26 @@ export async function POST(request: NextRequest) {
|
|||||||
sourceWidth,
|
sourceWidth,
|
||||||
})
|
})
|
||||||
).buffer
|
).buffer
|
||||||
: useScaleAdjustMarkedPhotoGuide
|
: await sharp(sourceBuffer, { failOn: "none" })
|
||||||
? await buildScaleAdjustMarkedPhotoGuideBuffer({
|
.composite([
|
||||||
height: sourceHeight,
|
{
|
||||||
regions,
|
input: buildAnnotationSvg({
|
||||||
scalePercent,
|
height: sourceHeight,
|
||||||
sourceBuffer,
|
hidePromptText: false,
|
||||||
width: sourceWidth,
|
regions,
|
||||||
})
|
width: sourceWidth,
|
||||||
: await sharp(
|
}),
|
||||||
buildScaleAdjustZoomedCoordinateSvg({
|
left: 0,
|
||||||
height: sourceHeight,
|
top: 0,
|
||||||
regions,
|
},
|
||||||
scalePercent,
|
])
|
||||||
width: sourceWidth,
|
.png({ compressionLevel: 6 })
|
||||||
}),
|
.toBuffer()
|
||||||
{ failOn: "none" }
|
: null;
|
||||||
)
|
|
||||||
.png({ compressionLevel: 6 })
|
|
||||||
.toBuffer()
|
|
||||||
: (
|
|
||||||
await buildScaleAdjustVisualLayoutGuideBuffer({
|
|
||||||
regions,
|
|
||||||
scalePercent,
|
|
||||||
sourceBuffer,
|
|
||||||
sourceHeight,
|
|
||||||
sourceWidth,
|
|
||||||
})
|
|
||||||
).buffer
|
|
||||||
: await sharp(sourceBuffer, { failOn: "none" })
|
|
||||||
.composite([
|
|
||||||
{
|
|
||||||
input: buildAnnotationSvg({
|
|
||||||
height: sourceHeight,
|
|
||||||
hidePromptText: false,
|
|
||||||
regions,
|
|
||||||
width: sourceWidth,
|
|
||||||
}),
|
|
||||||
left: 0,
|
|
||||||
top: 0,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.png({ compressionLevel: 6 })
|
|
||||||
.toBuffer();
|
|
||||||
const annotatedFilename = `${isScaleAdjustOperation ? "canvas-scale-adjust-layout-guide" : "canvas-local-edit"}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.png`;
|
const annotatedFilename = `${isScaleAdjustOperation ? "canvas-scale-adjust-layout-guide" : "canvas-local-edit"}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.png`;
|
||||||
const annotatedUpload = await uploadFile(
|
const annotatedUpload = annotatedBuffer
|
||||||
annotatedFilename,
|
? await uploadFile(annotatedFilename, toArrayBuffer(annotatedBuffer))
|
||||||
toArrayBuffer(annotatedBuffer)
|
: null;
|
||||||
);
|
|
||||||
const scaleAdjustEditMaskUpload = useScaleAdjustEditMask
|
const scaleAdjustEditMaskUpload = useScaleAdjustEditMask
|
||||||
? await uploadFile(
|
? await uploadFile(
|
||||||
`canvas-scale-adjust-edit-mask-${Date.now()}-${Math.random()
|
`canvas-scale-adjust-edit-mask-${Date.now()}-${Math.random()
|
||||||
@ -4437,6 +4458,11 @@ export async function POST(request: NextRequest) {
|
|||||||
sourceHeight,
|
sourceHeight,
|
||||||
sourceImageUrl,
|
sourceImageUrl,
|
||||||
sourceWidth,
|
sourceWidth,
|
||||||
|
fullFrameReferenceOnly:
|
||||||
|
useScaleAdjustStructureLockedPatchWorkflow &&
|
||||||
|
regions.some((region) =>
|
||||||
|
isScaleAdjustFurnitureProductLikePrompt(region.prompt)
|
||||||
|
),
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
@ -4561,7 +4587,7 @@ export async function POST(request: NextRequest) {
|
|||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
sourceImageUrl,
|
sourceImageUrl,
|
||||||
...(sendScaleAdjustAnnotatedReferenceToModel
|
...(sendScaleAdjustAnnotatedReferenceToModel && annotatedUpload?.url
|
||||||
? [annotatedUpload.url]
|
? [annotatedUpload.url]
|
||||||
: []),
|
: []),
|
||||||
...scaleAdjustCropReferenceImageUrls,
|
...scaleAdjustCropReferenceImageUrls,
|
||||||
@ -4630,7 +4656,7 @@ export async function POST(request: NextRequest) {
|
|||||||
debugLabel:
|
debugLabel:
|
||||||
operation === SCALE_ADJUST_OPERATION ? "canvas-scale-adjust" : "canvas-local-edit",
|
operation === SCALE_ADJUST_OPERATION ? "canvas-scale-adjust" : "canvas-local-edit",
|
||||||
debugMeta: {
|
debugMeta: {
|
||||||
annotatedReferenceUrl: annotatedUpload.url,
|
annotatedReferenceUrl: annotatedUpload?.url || null,
|
||||||
annotatedReferenceSentToModel: sendScaleAdjustAnnotatedReferenceToModel,
|
annotatedReferenceSentToModel: sendScaleAdjustAnnotatedReferenceToModel,
|
||||||
annotatedReferenceType: isScaleAdjustOperation
|
annotatedReferenceType: isScaleAdjustOperation
|
||||||
? useScaleAdjustFullFrameStructurePatch
|
? useScaleAdjustFullFrameStructurePatch
|
||||||
@ -4862,7 +4888,7 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
annotatedReferenceUrl: annotatedUpload.url,
|
annotatedReferenceUrl: annotatedUpload?.url || null,
|
||||||
aspectRatio: resolvedAspectRatio,
|
aspectRatio: resolvedAspectRatio,
|
||||||
displayPrompt,
|
displayPrompt,
|
||||||
prompt: displayPrompt,
|
prompt: displayPrompt,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user