From 9dbeb37fd72c661d41ae1c7ef7ad2f57e9703a68 Mon Sep 17 00:00:00 2001 From: pinks Date: Sat, 23 Sep 2023 20:49:05 +0200 Subject: [PATCH] move files --- {db => app}/config.ts | 2 +- {db => app}/db.ts | 0 {tasks => app}/generationQueue.ts | 21 ++++++++++----------- db/jobStore.ts => app/generationStore.ts | 2 +- {tasks => app}/mod.ts | 0 bot/cancelCommand.ts | 2 +- bot/img2imgCommand.ts | 8 ++++---- bot/mod.ts | 4 ++-- bot/pnginfoCommand.ts | 2 +- bot/queueCommand.ts | 6 +++--- bot/txt2imgCommand.ts | 8 ++++---- common/deadline.ts | 5 ----- main.ts | 2 +- {common => sd}/SdError.ts | 0 {common => sd}/parsePngInfo.test.ts | 0 {common => sd}/parsePngInfo.ts | 0 {common => sd}/sdApi.ts | 0 {common => utils}/formatOrdinal.ts | 0 {common => utils}/formatUserChat.ts | 0 {common => utils}/getFlagEmoji.ts | 0 20 files changed, 28 insertions(+), 34 deletions(-) rename {db => app}/config.ts (96%) rename {db => app}/db.ts (100%) rename {tasks => app}/generationQueue.ts (95%) rename db/jobStore.ts => app/generationStore.ts (96%) rename {tasks => app}/mod.ts (100%) delete mode 100644 common/deadline.ts rename {common => sd}/SdError.ts (100%) rename {common => sd}/parsePngInfo.test.ts (100%) rename {common => sd}/parsePngInfo.ts (100%) rename {common => sd}/sdApi.ts (100%) rename {common => utils}/formatOrdinal.ts (100%) rename {common => utils}/formatUserChat.ts (100%) rename {common => utils}/getFlagEmoji.ts (100%) diff --git a/db/config.ts b/app/config.ts similarity index 96% rename from db/config.ts rename to app/config.ts index 8793d83..d3be5b8 100644 --- a/db/config.ts +++ b/app/config.ts @@ -1,4 +1,4 @@ -import * as SdApi from "../common/sdApi.ts"; +import * as SdApi from "../sd/sdApi.ts"; import { db } from "./db.ts"; export interface ConfigData { diff --git a/db/db.ts b/app/db.ts similarity index 100% rename from db/db.ts rename to app/db.ts diff --git a/tasks/generationQueue.ts b/app/generationQueue.ts similarity index 95% rename from tasks/generationQueue.ts rename to app/generationQueue.ts index d359518..9390699 100644 --- a/tasks/generationQueue.ts +++ b/app/generationQueue.ts @@ -1,10 +1,10 @@ import { bot } from "../bot/mod.ts"; -import { PngInfo } from "../common/parsePngInfo.ts"; -import * as SdApi from "../common/sdApi.ts"; -import { formatUserChat } from "../common/formatUserChat.ts"; -import { getConfig, SdInstanceData } from "../db/config.ts"; -import { db } from "../db/db.ts"; -import { generationStore, SdGenerationInfo } from "../db/jobStore.ts"; +import { PngInfo } from "../sd/parsePngInfo.ts"; +import * as SdApi from "../sd/sdApi.ts"; +import { formatUserChat } from "../utils/formatUserChat.ts"; +import { getConfig, SdInstanceData } from "./config.ts"; +import { db } from "./db.ts"; +import { generationStore, SdGenerationInfo } from "./generationStore.ts"; import { Async, AsyncX, @@ -18,9 +18,8 @@ import { KVMQ, Log, } from "../deps.ts"; -import { formatOrdinal } from "../common/formatOrdinal.ts"; -import { deadline } from "../common/deadline.ts"; -import { SdError } from "../common/SdError.ts"; +import { formatOrdinal } from "../utils/formatOrdinal.ts"; +import { SdError } from "../sd/SdError.ts"; const logger = () => Log.getLogger(); @@ -66,7 +65,7 @@ export async function restartGenerationWorkers() { // check if worker is up const activeWorkerStatus = await activeWorkerSdClient.GET("/sdapi/v1/memory", { - signal: deadline(10_000), + signal: AbortSignal.timeout(10_000), }) .then((response) => { if (!response.data) { @@ -233,7 +232,7 @@ async function processGenerationJob( await Async.delay(3000); const progressResponse = await workerSdClient.GET("/sdapi/v1/progress", { params: {}, - signal: deadline(15_000), + signal: AbortSignal.timeout(15_000), }); if (!progressResponse.data) { throw new SdError( diff --git a/db/jobStore.ts b/app/generationStore.ts similarity index 96% rename from db/jobStore.ts rename to app/generationStore.ts index bc988d2..d61eabc 100644 --- a/db/jobStore.ts +++ b/app/generationStore.ts @@ -1,5 +1,5 @@ import { GrammyTypes, IKV } from "../deps.ts"; -import { PngInfo } from "../common/parsePngInfo.ts"; +import { PngInfo } from "../sd/parsePngInfo.ts"; import { db } from "./db.ts"; export interface GenerationSchema { diff --git a/tasks/mod.ts b/app/mod.ts similarity index 100% rename from tasks/mod.ts rename to app/mod.ts diff --git a/bot/cancelCommand.ts b/bot/cancelCommand.ts index 8b88454..b63633e 100644 --- a/bot/cancelCommand.ts +++ b/bot/cancelCommand.ts @@ -1,4 +1,4 @@ -import { generationQueue } from "../tasks/generationQueue.ts"; +import { generationQueue } from "../app/generationQueue.ts"; import { Context } from "./mod.ts"; export async function cancelCommand(ctx: Context) { diff --git a/bot/img2imgCommand.ts b/bot/img2imgCommand.ts index 0eb014c..bea0b4b 100644 --- a/bot/img2imgCommand.ts +++ b/bot/img2imgCommand.ts @@ -1,9 +1,9 @@ import { Collections, Grammy, GrammyStatelessQ } from "../deps.ts"; -import { formatUserChat } from "../common/formatUserChat.ts"; -import { parsePngInfo, PngInfo } from "../common/parsePngInfo.ts"; +import { formatUserChat } from "../utils/formatUserChat.ts"; +import { parsePngInfo, PngInfo } from "../sd/parsePngInfo.ts"; import { Context, logger } from "./mod.ts"; -import { generationQueue } from "../tasks/generationQueue.ts"; -import { getConfig } from "../db/config.ts"; +import { generationQueue } from "../app/generationQueue.ts"; +import { getConfig } from "../app/config.ts"; export const img2imgQuestion = new GrammyStatelessQ.StatelessQuestion( "img2img", diff --git a/bot/mod.ts b/bot/mod.ts index 67ab9b0..eb02ea4 100644 --- a/bot/mod.ts +++ b/bot/mod.ts @@ -1,11 +1,11 @@ import { Grammy, GrammyAutoQuote, GrammyFiles, GrammyParseMode, Log } from "../deps.ts"; -import { formatUserChat } from "../common/formatUserChat.ts"; +import { formatUserChat } from "../utils/formatUserChat.ts"; import { queueCommand } from "./queueCommand.ts"; import { txt2imgCommand, txt2imgQuestion } from "./txt2imgCommand.ts"; import { pnginfoCommand, pnginfoQuestion } from "./pnginfoCommand.ts"; import { img2imgCommand, img2imgQuestion } from "./img2imgCommand.ts"; import { cancelCommand } from "./cancelCommand.ts"; -import { getConfig, setConfig } from "../db/config.ts"; +import { getConfig, setConfig } from "../app/config.ts"; export const logger = () => Log.getLogger(); diff --git a/bot/pnginfoCommand.ts b/bot/pnginfoCommand.ts index d340462..ca0f108 100644 --- a/bot/pnginfoCommand.ts +++ b/bot/pnginfoCommand.ts @@ -1,5 +1,5 @@ import { Grammy, GrammyParseMode, GrammyStatelessQ } from "../deps.ts"; -import { getPngInfo, parsePngInfo } from "../common/parsePngInfo.ts"; +import { getPngInfo, parsePngInfo } from "../sd/parsePngInfo.ts"; import { Context } from "./mod.ts"; export const pnginfoQuestion = new GrammyStatelessQ.StatelessQuestion( diff --git a/bot/queueCommand.ts b/bot/queueCommand.ts index ea4eef7..52c6e3a 100644 --- a/bot/queueCommand.ts +++ b/bot/queueCommand.ts @@ -1,8 +1,8 @@ import { Grammy, GrammyParseMode } from "../deps.ts"; import { Context, logger } from "./mod.ts"; -import { getFlagEmoji } from "../common/getFlagEmoji.ts"; -import { activeGenerationWorkers, generationQueue } from "../tasks/generationQueue.ts"; -import { getConfig } from "../db/config.ts"; +import { getFlagEmoji } from "../utils/getFlagEmoji.ts"; +import { activeGenerationWorkers, generationQueue } from "../app/generationQueue.ts"; +import { getConfig } from "../app/config.ts"; export async function queueCommand(ctx: Grammy.CommandContext) { let formattedMessage = await getMessageText(); diff --git a/bot/txt2imgCommand.ts b/bot/txt2imgCommand.ts index ce6cdf3..0564011 100644 --- a/bot/txt2imgCommand.ts +++ b/bot/txt2imgCommand.ts @@ -1,9 +1,9 @@ import { Grammy, GrammyStatelessQ } from "../deps.ts"; -import { formatUserChat } from "../common/formatUserChat.ts"; -import { getPngInfo, parsePngInfo, PngInfo } from "../common/parsePngInfo.ts"; +import { formatUserChat } from "../utils/formatUserChat.ts"; +import { getPngInfo, parsePngInfo, PngInfo } from "../sd/parsePngInfo.ts"; import { Context, logger } from "./mod.ts"; -import { generationQueue } from "../tasks/generationQueue.ts"; -import { getConfig } from "../db/config.ts"; +import { generationQueue } from "../app/generationQueue.ts"; +import { getConfig } from "../app/config.ts"; export const txt2imgQuestion = new GrammyStatelessQ.StatelessQuestion( "txt2img", diff --git a/common/deadline.ts b/common/deadline.ts deleted file mode 100644 index c897f16..0000000 --- a/common/deadline.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function deadline(timeout: number): AbortSignal { - const controller = new AbortController(); - setTimeout(() => controller.abort(), timeout); - return controller.signal; -} diff --git a/main.ts b/main.ts index 1853539..86f1ed1 100644 --- a/main.ts +++ b/main.ts @@ -14,7 +14,7 @@ Log.setup({ // Main program logic import { bot } from "./bot/mod.ts"; -import { runAllTasks } from "./tasks/mod.ts"; +import { runAllTasks } from "./app/mod.ts"; await Promise.all([ bot.start(), runAllTasks(), diff --git a/common/SdError.ts b/sd/SdError.ts similarity index 100% rename from common/SdError.ts rename to sd/SdError.ts diff --git a/common/parsePngInfo.test.ts b/sd/parsePngInfo.test.ts similarity index 100% rename from common/parsePngInfo.test.ts rename to sd/parsePngInfo.test.ts diff --git a/common/parsePngInfo.ts b/sd/parsePngInfo.ts similarity index 100% rename from common/parsePngInfo.ts rename to sd/parsePngInfo.ts diff --git a/common/sdApi.ts b/sd/sdApi.ts similarity index 100% rename from common/sdApi.ts rename to sd/sdApi.ts diff --git a/common/formatOrdinal.ts b/utils/formatOrdinal.ts similarity index 100% rename from common/formatOrdinal.ts rename to utils/formatOrdinal.ts diff --git a/common/formatUserChat.ts b/utils/formatUserChat.ts similarity index 100% rename from common/formatUserChat.ts rename to utils/formatUserChat.ts diff --git a/common/getFlagEmoji.ts b/utils/getFlagEmoji.ts similarity index 100% rename from common/getFlagEmoji.ts rename to utils/getFlagEmoji.ts