diff --git a/app/userDailyStatsStore.ts b/app/userDailyStatsStore.ts index 485fdeb..64d7446 100644 --- a/app/userDailyStatsStore.ts +++ b/app/userDailyStatsStore.ts @@ -26,8 +26,8 @@ export const getUserDailyStats = kvMemoize( for await ( const generation of generationStore.listBy("fromId", { - before: new Date(new Date(year, month - 1, day).getTime() + 24 * 60 * 60 * 1000), - after: new Date(year, month - 1, day), + after: new Date(Date.UTC(year, month - 1, day)), + before: new Date(Date.UTC(year, month - 1, day + 1)), value: userId, }) ) { diff --git a/bot/mod.ts b/bot/mod.ts index 7052f5d..6f7fdda 100644 --- a/bot/mod.ts +++ b/bot/mod.ts @@ -115,7 +115,7 @@ bot.api.setMyDescription( bot.api.setMyCommands([ { command: "txt2img", description: "Generate image from text" }, { command: "img2img", description: "Generate image from image" }, - { command: "getprompt", description: "Try to extract prompt from raw file" }, + { command: "pnginfo", description: "Try to extract prompt from raw file" }, { command: "queue", description: "Show the current queue" }, { command: "cancel", description: "Cancel all your requests" }, ]); @@ -160,7 +160,7 @@ bot.use(txt2imgQuestion.middleware()); bot.command("img2img", img2imgCommand); bot.use(img2imgQuestion.middleware()); -bot.command("getprompt", pnginfoCommand); +bot.command("pnginfo", pnginfoCommand); bot.use(pnginfoQuestion.middleware()); bot.command("queue", queueCommand); diff --git a/bot/parsePngInfo.ts b/bot/parsePngInfo.ts index b751fb3..ad3174f 100644 --- a/bot/parsePngInfo.ts +++ b/bot/parsePngInfo.ts @@ -1,22 +1,24 @@ import * as ExifReader from "exifreader"; export function getPngInfo(pngData: ArrayBuffer): string | undefined { - const image = ExifReader.load(pngData); + const info = ExifReader.load(pngData); - if (image.UserComment && image.UserComment.value) { + if (info.UserComment?.value && Array.isArray(info.UserComment.value)) { // JPEG image - return String.fromCharCode.apply( - 0, - (image.UserComment.value as number[]).filter((char: number) => char != 0), - ) - .replace("UNICODE", ""); - } else if (image.parameters && image.parameters.description) { - // PNG image - return image.parameters.description; - } else { - // Unknown image type - return undefined; + return String.fromCharCode( + ...info.UserComment.value + .filter((char): char is number => typeof char == "number") + .filter((char) => char !== 0), + ).replace("UNICODE", ""); } + + if (info.parameters?.description) { + // PNG image + return info.parameters.description; + } + + // Unknown image type + return undefined; } export interface PngInfo { diff --git a/bot/pnginfoCommand.ts b/bot/pnginfoCommand.ts index 20c2be9..ed41fcf 100644 --- a/bot/pnginfoCommand.ts +++ b/bot/pnginfoCommand.ts @@ -22,7 +22,7 @@ async function pnginfo(ctx: ErisContext, includeRepliedTo: boolean): Promise resp.arrayBuffer()); - const params = parsePngInfo(getPngInfo(buffer) ?? "Nothing found.", undefined, true); + const info = getPngInfo(buffer); + if (!info) { + return await ctx.reply( + "No info found in file.", + omitUndef({ reply_to_message_id: ctx.message?.message_id }), + ); + } + const params = parsePngInfo(info, undefined, true); const paramsText = fmt([ `${params.prompt}\n`, diff --git a/ui/AdminsPage.tsx b/ui/AdminsPage.tsx index c9d39f5..4e76406 100644 --- a/ui/AdminsPage.tsx +++ b/ui/AdminsPage.tsx @@ -56,9 +56,11 @@ export function AdminsPage(props: { sessionId: string | null }) { ) : getAdmins.data?.length === 0 ? ( -
  • -

    No admins.

    -
  • + ) : getAdmins.error ?

    Loading admins failed

    diff --git a/ui/WorkersPage.tsx b/ui/WorkersPage.tsx index 2428a37..33cfd0a 100644 --- a/ui/WorkersPage.tsx +++ b/ui/WorkersPage.tsx @@ -39,9 +39,11 @@ export function WorkersPage(props: { sessionId: string | null }) { ) : getWorkers.data?.length === 0 ? ( -
  • -

    No workers.

    -
  • + ) : getWorkers.error ?

    Loading workers failed