adds dall-e full history page and metadata downloader
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
const IMAGE_HISTORY_SIZE = 30;
|
||||
const IMAGE_HISTORY_SIZE = 10000;
|
||||
const imageHistory = new Array<ImageHistory>(IMAGE_HISTORY_SIZE);
|
||||
let index = 0;
|
||||
|
||||
type ImageHistory = { url: string; prompt: string };
|
||||
type ImageHistory = { url: string; prompt: string, token?: string };
|
||||
|
||||
export function addToImageHistory(image: ImageHistory) {
|
||||
if (image.token?.length) {
|
||||
image.token = `...${image.token.slice(-5)}`;
|
||||
}
|
||||
imageHistory[index] = image;
|
||||
index = (index + 1) % IMAGE_HISTORY_SIZE;
|
||||
}
|
||||
|
||||
export function getLastNImages(n: number) {
|
||||
export function getLastNImages(n: number = IMAGE_HISTORY_SIZE): ImageHistory[] {
|
||||
const result: ImageHistory[] = [];
|
||||
let currentIndex = (index - 1 + IMAGE_HISTORY_SIZE) % IMAGE_HISTORY_SIZE;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import axios from "axios";
|
||||
import express from "express";
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import { v4 } from "uuid";
|
||||
@@ -53,10 +54,11 @@ async function createThumbnail(filepath: string) {
|
||||
* Mutates the result object.
|
||||
*/
|
||||
export async function mirrorGeneratedImage(
|
||||
host: string,
|
||||
req: express.Request,
|
||||
prompt: string,
|
||||
result: OpenAIImageGenerationResult
|
||||
): Promise<OpenAIImageGenerationResult> {
|
||||
const host = req.protocol + "://" + req.get("host");
|
||||
for (const item of result.data) {
|
||||
let mirror: string;
|
||||
if (item.b64_json) {
|
||||
@@ -66,7 +68,7 @@ export async function mirrorGeneratedImage(
|
||||
}
|
||||
item.url = `${host}/user_content/${path.basename(mirror)}`;
|
||||
await createThumbnail(mirror);
|
||||
addToImageHistory({ url: item.url, prompt });
|
||||
addToImageHistory({ url: item.url, prompt, token: req.user?.token ?? "" });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user