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: {
|
||||
fullFrameReferenceOnly?: boolean;
|
||||
regions: NormalizedLocalEditRegion[];
|
||||
scalePercent?: ScaleAdjustPercent | null;
|
||||
sourceBuffer: Buffer;
|
||||
@ -3116,6 +3117,24 @@ async function createScaleAdjustPatchReference(params: {
|
||||
userId,
|
||||
});
|
||||
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([
|
||||
sharp(sourceBuffer, { failOn: "none" })
|
||||
.extract(workspacePixelRect)
|
||||
@ -3126,7 +3145,6 @@ async function createScaleAdjustPatchReference(params: {
|
||||
.png({ compressionLevel: 6 })
|
||||
.toBuffer(),
|
||||
]);
|
||||
const suffix = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
const [
|
||||
sourceCropUpload,
|
||||
targetDraftUpload,
|
||||
@ -4354,10 +4372,41 @@ export async function POST(request: NextRequest) {
|
||||
isScaleAdjustOperation &&
|
||||
!useScaleAdjustPatchWorkflow &&
|
||||
!useProviderTextOnlyCoordinatePrompt;
|
||||
const annotatedBuffer = isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinatePrompt
|
||||
? useScaleAdjustVisualLayoutGuide
|
||||
? (
|
||||
const shouldUploadAnnotatedReference =
|
||||
!isScaleAdjustOperation || sendScaleAdjustAnnotatedReferenceToModel;
|
||||
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({
|
||||
regions,
|
||||
scalePercent,
|
||||
@ -4366,54 +4415,26 @@ export async function POST(request: NextRequest) {
|
||||
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({
|
||||
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();
|
||||
: await sharp(sourceBuffer, { failOn: "none" })
|
||||
.composite([
|
||||
{
|
||||
input: buildAnnotationSvg({
|
||||
height: sourceHeight,
|
||||
hidePromptText: false,
|
||||
regions,
|
||||
width: sourceWidth,
|
||||
}),
|
||||
left: 0,
|
||||
top: 0,
|
||||
},
|
||||
])
|
||||
.png({ compressionLevel: 6 })
|
||||
.toBuffer()
|
||||
: null;
|
||||
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(
|
||||
annotatedFilename,
|
||||
toArrayBuffer(annotatedBuffer)
|
||||
);
|
||||
const annotatedUpload = annotatedBuffer
|
||||
? await uploadFile(annotatedFilename, toArrayBuffer(annotatedBuffer))
|
||||
: null;
|
||||
const scaleAdjustEditMaskUpload = useScaleAdjustEditMask
|
||||
? await uploadFile(
|
||||
`canvas-scale-adjust-edit-mask-${Date.now()}-${Math.random()
|
||||
@ -4437,6 +4458,11 @@ export async function POST(request: NextRequest) {
|
||||
sourceHeight,
|
||||
sourceImageUrl,
|
||||
sourceWidth,
|
||||
fullFrameReferenceOnly:
|
||||
useScaleAdjustStructureLockedPatchWorkflow &&
|
||||
regions.some((region) =>
|
||||
isScaleAdjustFurnitureProductLikePrompt(region.prompt)
|
||||
),
|
||||
userId: session.user.id,
|
||||
})
|
||||
: null;
|
||||
@ -4561,7 +4587,7 @@ export async function POST(request: NextRequest) {
|
||||
]
|
||||
: [
|
||||
sourceImageUrl,
|
||||
...(sendScaleAdjustAnnotatedReferenceToModel
|
||||
...(sendScaleAdjustAnnotatedReferenceToModel && annotatedUpload?.url
|
||||
? [annotatedUpload.url]
|
||||
: []),
|
||||
...scaleAdjustCropReferenceImageUrls,
|
||||
@ -4630,7 +4656,7 @@ export async function POST(request: NextRequest) {
|
||||
debugLabel:
|
||||
operation === SCALE_ADJUST_OPERATION ? "canvas-scale-adjust" : "canvas-local-edit",
|
||||
debugMeta: {
|
||||
annotatedReferenceUrl: annotatedUpload.url,
|
||||
annotatedReferenceUrl: annotatedUpload?.url || null,
|
||||
annotatedReferenceSentToModel: sendScaleAdjustAnnotatedReferenceToModel,
|
||||
annotatedReferenceType: isScaleAdjustOperation
|
||||
? useScaleAdjustFullFrameStructurePatch
|
||||
@ -4862,7 +4888,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
annotatedReferenceUrl: annotatedUpload.url,
|
||||
annotatedReferenceUrl: annotatedUpload?.url || null,
|
||||
aspectRatio: resolvedAspectRatio,
|
||||
displayPrompt,
|
||||
prompt: displayPrompt,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user