PR #24
|
@ -26,8 +26,8 @@ export const getUserDailyStats = kvMemoize(
|
||||||
|
|
||||||
for await (
|
for await (
|
||||||
const generation of generationStore.listBy("fromId", {
|
const generation of generationStore.listBy("fromId", {
|
||||||
before: new Date(new Date(year, month - 1, day).getTime() + 24 * 60 * 60 * 1000),
|
after: new Date(Date.UTC(year, month - 1, day)),
|
||||||
nameless marked this conversation as resolved
Outdated
|
|||||||
after: new Date(year, month - 1, day),
|
before: new Date(Date.UTC(year, month - 1, day + 1)),
|
||||||
value: userId,
|
value: userId,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ bot.api.setMyDescription(
|
||||||
bot.api.setMyCommands([
|
bot.api.setMyCommands([
|
||||||
{ command: "txt2img", description: "Generate image from text" },
|
{ command: "txt2img", description: "Generate image from text" },
|
||||||
{ command: "img2img", description: "Generate image from image" },
|
{ 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: "queue", description: "Show the current queue" },
|
||||||
{ command: "cancel", description: "Cancel all your requests" },
|
{ command: "cancel", description: "Cancel all your requests" },
|
||||||
]);
|
]);
|
||||||
|
@ -160,7 +160,7 @@ bot.use(txt2imgQuestion.middleware());
|
||||||
bot.command("img2img", img2imgCommand);
|
bot.command("img2img", img2imgCommand);
|
||||||
bot.use(img2imgQuestion.middleware());
|
bot.use(img2imgQuestion.middleware());
|
||||||
|
|
||||||
bot.command("getprompt", pnginfoCommand);
|
bot.command("pnginfo", pnginfoCommand);
|
||||||
pinks
commented
Can we change it to Can we change it to `imginfo`? Also change all the function names if we do. Or leave the name as is
nameless
commented
leaving it as it is, will rename everything in future PR leaving it as it is, will rename everything in future PR
|
|||||||
bot.use(pnginfoQuestion.middleware());
|
bot.use(pnginfoQuestion.middleware());
|
||||||
|
|
||||||
bot.command("queue", queueCommand);
|
bot.command("queue", queueCommand);
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
import * as ExifReader from "exifreader";
|
import * as ExifReader from "exifreader";
|
||||||
|
|
||||||
export function getPngInfo(pngData: ArrayBuffer): string | undefined {
|
export function getPngInfo(pngData: ArrayBuffer): string | undefined {
|
||||||
nameless marked this conversation as resolved
pinks
commented
I don't like
I don't like `as` here. How about:
```ts
export function getImageInfo(imageData: ArrayBuffer): string | undefined {
const info = ExifReader.load(imageData);
if (info.UserComment?.value && Array.isArray(info.UserComment.value)) {
// JPEG image
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;
}
```
|
|||||||
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
|
// JPEG image
|
||||||
return String.fromCharCode.apply(
|
return String.fromCharCode(
|
||||||
0,
|
...info.UserComment.value
|
||||||
(image.UserComment.value as number[]).filter((char: number) => char != 0),
|
.filter((char): char is number => typeof char == "number")
|
||||||
)
|
.filter((char) => char !== 0),
|
||||||
.replace("UNICODE", "");
|
).replace("UNICODE", "");
|
||||||
} else if (image.parameters && image.parameters.description) {
|
}
|
||||||
|
|
||||||
|
if (info.parameters?.description) {
|
||||||
// PNG image
|
// PNG image
|
||||||
return image.parameters.description;
|
return info.parameters.description;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Unknown image type
|
// Unknown image type
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export interface PngInfo {
|
export interface PngInfo {
|
||||||
prompt: string;
|
prompt: string;
|
||||||
|
|
|
@ -22,7 +22,7 @@ async function pnginfo(ctx: ErisContext, includeRepliedTo: boolean): Promise<voi
|
||||||
|
|
||||||
if (document?.mime_type !== "image/png" && document?.mime_type !== "image/jpeg") {
|
if (document?.mime_type !== "image/png" && document?.mime_type !== "image/jpeg") {
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
"Please send me a PNG file." +
|
"Please send me a PNG or JPEG file." +
|
||||||
nameless marked this conversation as resolved
Outdated
pinks
commented
"Please send me a PNG or JPEG file." "Please send me a PNG or JPEG file."
|
|||||||
pnginfoQuestion.messageSuffixMarkdown(),
|
pnginfoQuestion.messageSuffixMarkdown(),
|
||||||
omitUndef(
|
omitUndef(
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,14 @@ async function pnginfo(ctx: ErisContext, includeRepliedTo: boolean): Promise<voi
|
||||||
|
|
||||||
const file = await ctx.api.getFile(document.file_id);
|
const file = await ctx.api.getFile(document.file_id);
|
||||||
const buffer = await fetch(file.getUrl()).then((resp) => resp.arrayBuffer());
|
const buffer = await fetch(file.getUrl()).then((resp) => resp.arrayBuffer());
|
||||||
const params = parsePngInfo(getPngInfo(buffer) ?? "Nothing found.", undefined, true);
|
const info = getPngInfo(buffer);
|
||||||
nameless marked this conversation as resolved
Outdated
pinks
commented
Maybe split it in 3 lines:
Maybe split it in 3 lines:
```js
const info = getPngInfo(buffer);
if (!info) return await ctx.reply("No info found in file.", {...});
const params = parsePngInfo(info, undefined, true);
```
|
|||||||
|
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([
|
const paramsText = fmt([
|
||||||
`${params.prompt}\n`,
|
`${params.prompt}\n`,
|
||||||
|
|
|
@ -56,9 +56,11 @@ export function AdminsPage(props: { sessionId: string | null }) {
|
||||||
)
|
)
|
||||||
: getAdmins.data?.length === 0
|
: getAdmins.data?.length === 0
|
||||||
? (
|
? (
|
||||||
|
<ul className="flex flex-col gap-2">
|
||||||
nameless marked this conversation as resolved
Outdated
pinks
commented
`li` outside of `ul`?
|
|||||||
<li className="flex flex-col gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2">
|
<li className="flex flex-col gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2">
|
||||||
<p key="no-admins" className="text-center text-gray-500">No admins.</p>
|
<p key="no-admins" className="text-center text-gray-500">No admins.</p>
|
||||||
</li>
|
</li>
|
||||||
|
</ul>
|
||||||
)
|
)
|
||||||
: getAdmins.error
|
: getAdmins.error
|
||||||
? <p className="alert">Loading admins failed</p>
|
? <p className="alert">Loading admins failed</p>
|
||||||
|
|
|
@ -39,9 +39,11 @@ export function WorkersPage(props: { sessionId: string | null }) {
|
||||||
)
|
)
|
||||||
: getWorkers.data?.length === 0
|
: getWorkers.data?.length === 0
|
||||||
? (
|
? (
|
||||||
|
<ul className="flex flex-col gap-2">
|
||||||
nameless marked this conversation as resolved
Outdated
pinks
commented
`li` without `ul`
|
|||||||
<li className="flex flex-col gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2">
|
<li className="flex flex-col gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2">
|
||||||
<p key="no-workers" className="text-center text-gray-500">No workers.</p>
|
<p key="no-workers" className="text-center text-gray-500">No workers.</p>
|
||||||
</li>
|
</li>
|
||||||
|
</ul>
|
||||||
)
|
)
|
||||||
: getWorkers.error
|
: getWorkers.error
|
||||||
? <p className="alert">Loading workers failed</p>
|
? <p className="alert">Loading workers failed</p>
|
||||||
|
|
Loading…
Reference in New Issue
You need to use
Date.UTC
orUTCDateMini
here. Otherwise it will return midnight but in local timezone.For example: