forked from pinks/eris
1
0
Fork 0

feat: send generation as file

This commit is contained in:
nameless 2023-11-10 10:13:07 +00:00
parent f678324889
commit 8b5d242865
3 changed files with 27 additions and 7 deletions

View File

@ -37,6 +37,7 @@ interface GenerationJob {
replyMessage: Message; replyMessage: Message;
workerInstanceKey?: string; workerInstanceKey?: string;
progress?: number; progress?: number;
asFile?: boolean;
} }
export const generationQueue = new Queue<GenerationJob>(db, "jobQueue"); export const generationQueue = new Queue<GenerationJob>(db, "jobQueue");
@ -284,6 +285,7 @@ async function processGenerationJob(
replyMessage: state.replyMessage, replyMessage: state.replyMessage,
workerInstanceKey: workerInstance.value.key, workerInstanceKey: workerInstance.value.key,
startDate, startDate,
sendOriginal: state.task.params.file,
endDate: new Date(), endDate: new Date(),
imageKeys, imageKeys,
info, info,

View File

@ -18,6 +18,7 @@ interface UploadJob {
replyMessage: Message; replyMessage: Message;
workerInstanceKey?: string; workerInstanceKey?: string;
startDate: Date; startDate: Date;
sendOriginal: boolean;
endDate: Date; endDate: Date;
imageKeys: Deno.KvKey[]; imageKeys: Deno.KvKey[];
info: SdGenerationInfo; info: SdGenerationInfo;
@ -71,13 +72,23 @@ export async function processUploadQueue() {
if (!imageType) throw new Error("Image has unknown type"); if (!imageType) throw new Error("Image has unknown type");
size += imageBuffer.byteLength; size += imageBuffer.byteLength;
types.add(imageType.ext); types.add(imageType.ext);
return InputMediaBuilder.photo( if (state.sendOriginal) {
new InputFile(imageBuffer, `image${idx}.${imageType.ext}`), return InputMediaBuilder.document(
// if it can fit, add caption for first photo new InputFile(imageBuffer, `image${idx}.${imageType.ext}`),
idx === 0 && caption.text.length <= 1024 // if it can fit, add caption for first photo
? { caption: caption.text, caption_entities: caption.entities } idx === 0 && caption.text.length <= 1024
: undefined, ? { 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,
);
}
}), }),
); );

View File

@ -23,6 +23,7 @@ export interface PngInfo {
interface PngInfoExtra extends PngInfo { interface PngInfoExtra extends PngInfo {
upscale?: number; upscale?: number;
file?: boolean;
} }
export function parsePngInfo( export function parsePngInfo(
@ -113,6 +114,12 @@ export function parsePngInfo(
} }
break; break;
} }
case "file": {
part = "params";
const file = value === "true" || value === "1" || value === "yes";
params.file = file;
break;
}
case "model": case "model":
case "modelhash": case "modelhash":
case "modelname": case "modelname":