From 8b5d242865b328a10335ebcbeabdba017887e367 Mon Sep 17 00:00:00 2001 From: nameless Date: Fri, 10 Nov 2023 10:13:07 +0000 Subject: [PATCH] feat: send generation as file --- app/generationQueue.ts | 2 ++ app/uploadQueue.ts | 25 ++++++++++++++++++------- bot/parsePngInfo.ts | 7 +++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/generationQueue.ts b/app/generationQueue.ts index 49700d0..0a6ed89 100644 --- a/app/generationQueue.ts +++ b/app/generationQueue.ts @@ -37,6 +37,7 @@ interface GenerationJob { replyMessage: Message; workerInstanceKey?: string; progress?: number; + asFile?: boolean; } export const generationQueue = new Queue(db, "jobQueue"); @@ -284,6 +285,7 @@ async function processGenerationJob( replyMessage: state.replyMessage, workerInstanceKey: workerInstance.value.key, startDate, + sendOriginal: state.task.params.file, endDate: new Date(), imageKeys, info, diff --git a/app/uploadQueue.ts b/app/uploadQueue.ts index ae22609..49fd7a2 100644 --- a/app/uploadQueue.ts +++ b/app/uploadQueue.ts @@ -18,6 +18,7 @@ interface UploadJob { replyMessage: Message; workerInstanceKey?: string; startDate: Date; + sendOriginal: boolean; endDate: Date; imageKeys: Deno.KvKey[]; info: SdGenerationInfo; @@ -71,13 +72,23 @@ export async function processUploadQueue() { if (!imageType) throw new Error("Image has unknown type"); size += imageBuffer.byteLength; types.add(imageType.ext); - return InputMediaBuilder.photo( - new InputFile(imageBuffer, `image${idx}.${imageType.ext}`), - // if it can fit, add caption for first photo - idx === 0 && caption.text.length <= 1024 - ? { caption: caption.text, caption_entities: caption.entities } - : undefined, - ); + if (state.sendOriginal) { + return InputMediaBuilder.document( + new InputFile(imageBuffer, `image${idx}.${imageType.ext}`), + // if it can fit, add caption for first photo + idx === 0 && caption.text.length <= 1024 + ? { caption: caption.text, caption_entities: caption.entities } + : undefined, + ); + } else { + return InputMediaBuilder.photo( + new InputFile(imageBuffer, `image${idx}.${imageType.ext}`), + // if it can fit, add caption for first photo + idx === 0 && caption.text.length <= 1024 + ? { caption: caption.text, caption_entities: caption.entities } + : undefined, + ); + } }), ); diff --git a/bot/parsePngInfo.ts b/bot/parsePngInfo.ts index 9bf2d40..23e63e1 100644 --- a/bot/parsePngInfo.ts +++ b/bot/parsePngInfo.ts @@ -23,6 +23,7 @@ export interface PngInfo { interface PngInfoExtra extends PngInfo { upscale?: number; + file?: boolean; } export function parsePngInfo( @@ -113,6 +114,12 @@ export function parsePngInfo( } break; } + case "file": { + part = "params"; + const file = value === "true" || value === "1" || value === "yes"; + params.file = file; + break; + } case "model": case "modelhash": case "modelname":