From 0c6c49a0413bf27a6951dd3547f759ecf2b15388 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Fri, 14 Jul 2023 14:46:10 +0000 Subject: [PATCH] Update --- client.ts | 2 +- components/NewTask.tsx | 8 ++++---- components/SettingsCheckbox.tsx | 2 +- components/SettingsContext.tsx | 2 +- components/SettingsSelect.tsx | 4 ++-- components/SettingsText.tsx | 2 +- components/Task.tsx | 2 +- eh_translation.ts | 2 +- islands/Settings.tsx | 3 ++- islands/TaskManager.tsx | 8 ++++++-- meilisearch.ts | 2 +- page/GalleryMetadata.ts | 2 +- page/GalleryPage.ts | 2 +- page/MPVPage.ts | 2 +- routes/_middleware.ts | 10 ++++++++-- routes/api/export/gallery/zip/[gid].ts | 2 +- routes/api/filemeta.ts | 2 +- routes/api/files/[token].ts | 2 +- routes/api/gallery/[gid].ts | 2 +- routes/api/status.ts | 2 +- routes/api/task.ts | 4 ++-- server/cfg.ts | 16 ++++++++-------- server/config.ts | 2 +- server/export_zip.ts | 4 ++-- server/gallery.ts | 2 +- server/i18ns.ts | 7 +++++-- server/task.ts | 10 +++++----- signal_handler.ts | 11 ----------- tasks/download.ts | 4 ++-- tasks/export_zip.ts | 2 +- thumbnail/base.ts | 2 +- thumbnail/ffmpeg_binary.ts | 2 +- 32 files changed, 66 insertions(+), 63 deletions(-) diff --git a/client.ts b/client.ts index cc353c2..a3a0281 100644 --- a/client.ts +++ b/client.ts @@ -1,4 +1,4 @@ -import { Config } from "./config.ts"; +import type { Config } from "./config.ts"; import { load_gallery_metadata } from "./page/GalleryMetadata.ts"; import { load_gallery_page } from "./page/GalleryPage.ts"; import { load_mpv_page } from "./page/MPVPage.ts"; diff --git a/components/NewTask.tsx b/components/NewTask.tsx index 4451718..2a18d52 100644 --- a/components/NewTask.tsx +++ b/components/NewTask.tsx @@ -19,11 +19,11 @@ import BContext from "./BContext.tsx"; import Button from "preact-material-components/Button"; import { sendTaskMessage } from "../islands/TaskManager.tsx"; import Snackbar from "preact-material-components/Snackbar"; -import { GalleryResult } from "../server/gallery.ts"; +import type { GalleryResult } from "../server/gallery.ts"; import { tw } from "twind"; -import { ExportZipConfig } from "../tasks/export_zip.ts"; -import { GMeta } from "../db.ts"; -import { GalleryListResult } from "../server/gallery.ts"; +import type { ExportZipConfig } from "../tasks/export_zip.ts"; +import type { GMeta } from "../db.ts"; +import type { GalleryListResult } from "../server/gallery.ts"; export type NewTaskProps = { show: boolean; diff --git a/components/SettingsCheckbox.tsx b/components/SettingsCheckbox.tsx index 8c3207d..77dd786 100644 --- a/components/SettingsCheckbox.tsx +++ b/components/SettingsCheckbox.tsx @@ -1,6 +1,6 @@ import { Component, ContextType } from "preact"; import { SettingsCtx } from "./SettingsContext.tsx"; -import { ConfigType } from "../config.ts"; +import type { ConfigType } from "../config.ts"; import Checkbox from "preact-material-components/Checkbox"; export type SettingsCheckboxProps = { diff --git a/components/SettingsContext.tsx b/components/SettingsContext.tsx index a9abab1..a6c80f0 100644 --- a/components/SettingsContext.tsx +++ b/components/SettingsContext.tsx @@ -1,6 +1,6 @@ import { Component, ComponentChild, createContext } from "preact"; import { StateUpdater } from "preact/hooks"; -import { ConfigType } from "../config.ts"; +import type { ConfigType } from "../config.ts"; export const SettingsCtx = createContext(null); diff --git a/components/SettingsSelect.tsx b/components/SettingsSelect.tsx index 4aeee11..f6284ca 100644 --- a/components/SettingsSelect.tsx +++ b/components/SettingsSelect.tsx @@ -1,8 +1,8 @@ import { Component, ContextType } from "preact"; import { SettingsCtx } from "./SettingsContext.tsx"; -import { ConfigType } from "../config.ts"; +import type { ConfigType } from "../config.ts"; import Md3Select from "./Md3Select.tsx"; -import { Ref, StateUpdater, useRef } from "preact/hooks"; +import { StateUpdater } from "preact/hooks"; interface obj { toString(): string; diff --git a/components/SettingsText.tsx b/components/SettingsText.tsx index c0308fa..96b7a26 100644 --- a/components/SettingsText.tsx +++ b/components/SettingsText.tsx @@ -1,6 +1,6 @@ import { Component, ComponentChildren, ContextType } from "preact"; import { SettingsCtx } from "./SettingsContext.tsx"; -import { ConfigType } from "../config.ts"; +import type { ConfigType } from "../config.ts"; import TextField from "preact-material-components/TextField"; import { Ref, StateUpdater, useRef } from "preact/hooks"; diff --git a/components/Task.tsx b/components/Task.tsx index 42166c2..339866b 100644 --- a/components/Task.tsx +++ b/components/Task.tsx @@ -1,6 +1,6 @@ import { Component } from "preact"; import Icon from "preact-material-components/Icon"; -import { TaskDetail, TaskStatus, TaskType } from "../task.ts"; +import type { TaskDetail } from "../task.ts"; import t from "../server/i18n.ts"; type Props = { diff --git a/eh_translation.ts b/eh_translation.ts index 8f8c3c5..9b6eda8 100644 --- a/eh_translation.ts +++ b/eh_translation.ts @@ -1,4 +1,4 @@ -import { EhDb } from "./db.ts"; +import type { EhDb } from "./db.ts"; import { asyncForEach } from "./utils.ts"; export type GHAuthor = { diff --git a/islands/Settings.tsx b/islands/Settings.tsx index c5a0a7d..0a8495e 100644 --- a/islands/Settings.tsx +++ b/islands/Settings.tsx @@ -4,7 +4,8 @@ import Button from "preact-material-components/Button"; import Snackbar from "preact-material-components/Snackbar"; import { tw } from "twind"; import { GlobalCtx } from "../components/GlobalContext.tsx"; -import { ConfigType, ThumbnailMethod } from "../config.ts"; +import type { ConfigType } from "../config.ts"; +import { ThumbnailMethod } from "../config.ts"; import SettingsCheckbox from "../components/SettingsCheckbox.tsx"; import SettingsContext from "../components/SettingsContext.tsx"; import SettingsText from "../components/SettingsText.tsx"; diff --git a/islands/TaskManager.tsx b/islands/TaskManager.tsx index 5dec7e5..c6f8055 100644 --- a/islands/TaskManager.tsx +++ b/islands/TaskManager.tsx @@ -2,9 +2,13 @@ import { Component, ContextType } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; import { signal } from "@preact/signals"; import { GlobalCtx } from "../components/GlobalContext.tsx"; -import { TaskDetail, TaskStatus } from "../task.ts"; +import type { TaskDetail } from "../task.ts"; +import { TaskStatus } from "../task.ts"; import { Sortable } from "sortable"; -import { TaskClientSocketData, TaskServerSocketData } from "../server/task.ts"; +import type { + TaskClientSocketData, + TaskServerSocketData, +} from "../server/task.ts"; import { get_ws_host } from "../server/utils.ts"; import Task from "../components/Task.tsx"; import Fab from "preact-material-components/Fab"; diff --git a/meilisearch.ts b/meilisearch.ts index 43b4d75..a9314f8 100644 --- a/meilisearch.ts +++ b/meilisearch.ts @@ -5,7 +5,7 @@ import { MeiliSearchApiError, } from "meilisearch"; import { sleep } from "./utils.ts"; -import { EhDb } from "./db.ts"; +import type { EhDb } from "./db.ts"; import isEqual from "lodash/isEqual"; const GMetaSettings: Record = { diff --git a/page/GalleryMetadata.ts b/page/GalleryMetadata.ts index 69d6e12..6c48bb6 100644 --- a/page/GalleryMetadata.ts +++ b/page/GalleryMetadata.ts @@ -1,5 +1,5 @@ import { unescape } from "std/html/mod.ts"; -import { GMeta } from "../db.ts"; +import type { GMeta } from "../db.ts"; export type GalleryMetadataTorrentInfo = { hash: string; diff --git a/page/GalleryPage.ts b/page/GalleryPage.ts index c32495c..818b3ba 100644 --- a/page/GalleryPage.ts +++ b/page/GalleryPage.ts @@ -1,7 +1,7 @@ import { DOMParser, Element } from "deno_dom/deno-dom-wasm-noinit.ts"; import { extname } from "std/path/mod.ts"; import { Client } from "../client.ts"; -import { EhFile, PMeta } from "../db.ts"; +import type { EhFile, PMeta } from "../db.ts"; import { initDOMParser, map, parse_bool } from "../utils.ts"; import { parseUrl, UrlType } from "../url.ts"; import { SinglePage } from "./SinglePage.ts"; diff --git a/page/MPVPage.ts b/page/MPVPage.ts index f32ea1a..cefa74a 100644 --- a/page/MPVPage.ts +++ b/page/MPVPage.ts @@ -2,7 +2,7 @@ import { DOMParser } from "deno_dom/deno-dom-wasm-noinit.ts"; import { extname } from "std/path/mod.ts"; import { Client } from "../client.ts"; import { initDOMParser } from "../utils.ts"; -import { EhFile, PMeta } from "../db.ts"; +import type { EhFile, PMeta } from "../db.ts"; export type MPVRawImage = { /**Image name*/ diff --git a/routes/_middleware.ts b/routes/_middleware.ts index ec4d7a0..700bac6 100644 --- a/routes/_middleware.ts +++ b/routes/_middleware.ts @@ -12,7 +12,10 @@ const STATIC_FILES = ["/common.css", "/scrollBar.css", "/sw.js", "/sw.js.map"]; export async function handler(req: Request, ctx: MiddlewareHandlerContext) { const url = new URL(req.url); if (url.pathname == "/sw.js") { - const base = import.meta.resolve("../static").slice(8); + let base = import.meta.resolve("../static").slice(7); + if (Deno.build.os === "windows") { + base = base.slice(1); + } const map_file = join(base, "sw.meta.json"); if (!(await checkMapFile(map_file))) { const data = await build({ @@ -57,7 +60,10 @@ export async function handler(req: Request, ctx: MiddlewareHandlerContext) { } } if (STATIC_FILES.includes(url.pathname)) { - const base = import.meta.resolve("../static").slice(8); + let base = import.meta.resolve("../static").slice(7); + if (Deno.build.os === "windows") { + base = base.slice(1); + } const file = join(base, url.pathname.slice(1)); const opts: GetFileResponseOptions = {}; opts.range = req.headers.get("Range"); diff --git a/routes/api/export/gallery/zip/[gid].ts b/routes/api/export/gallery/zip/[gid].ts index ca7addc..5e9b78b 100644 --- a/routes/api/export/gallery/zip/[gid].ts +++ b/routes/api/export/gallery/zip/[gid].ts @@ -2,7 +2,7 @@ import { Handlers } from "$fresh/server.ts"; import { get_task_manager } from "../../../../../server.ts"; import { get_export_zip_response } from "../../../../../server/export_zip.ts"; import { parse_bool, parse_int } from "../../../../../server/parse_form.ts"; -import { ExportZipConfig } from "../../../../../tasks/export_zip.ts"; +import type { ExportZipConfig } from "../../../../../tasks/export_zip.ts"; export const handler: Handlers = { async GET(req, ctx) { diff --git a/routes/api/filemeta.ts b/routes/api/filemeta.ts index 22b5080..62d2d0e 100644 --- a/routes/api/filemeta.ts +++ b/routes/api/filemeta.ts @@ -1,5 +1,5 @@ import { Handlers } from "$fresh/server.ts"; -import { EhFileMeta } from "../../db.ts"; +import type { EhFileMeta } from "../../db.ts"; import { get_task_manager } from "../../server.ts"; import { get_string, parse_bool, parse_int } from "../../server/parse_form.ts"; import { return_data, return_error } from "../../server/utils.ts"; diff --git a/routes/api/files/[token].ts b/routes/api/files/[token].ts index 29551cc..e3e6a44 100644 --- a/routes/api/files/[token].ts +++ b/routes/api/files/[token].ts @@ -1,6 +1,6 @@ import { Handlers } from "$fresh/server.ts"; import { get_task_manager } from "../../../server.ts"; -import { EhFiles } from "../../../server/files.ts"; +import type { EhFiles } from "../../../server/files.ts"; import { return_data } from "../../../server/utils.ts"; export const handler: Handlers = { diff --git a/routes/api/gallery/[gid].ts b/routes/api/gallery/[gid].ts index 2f1d722..fd29e56 100644 --- a/routes/api/gallery/[gid].ts +++ b/routes/api/gallery/[gid].ts @@ -1,6 +1,6 @@ import { Handlers } from "$fresh/server.ts"; import { get_task_manager } from "../../../server.ts"; -import { GalleryData } from "../../../server/gallery.ts"; +import type { GalleryData } from "../../../server/gallery.ts"; import { return_data, return_error } from "../../../server/utils.ts"; export const handler: Handlers = { diff --git a/routes/api/status.ts b/routes/api/status.ts index 9f90350..82da8cc 100644 --- a/routes/api/status.ts +++ b/routes/api/status.ts @@ -1,6 +1,6 @@ import { Handlers } from "$fresh/server.ts"; import { get_task_manager } from "../../server.ts"; -import { StatusData } from "../../server/status.ts"; +import type { StatusData } from "../../server/status.ts"; import { return_data } from "../../server/utils.ts"; import { check_ffmpeg_binary } from "../../thumbnail/ffmpeg_binary.ts"; diff --git a/routes/api/task.ts b/routes/api/task.ts index b4c3663..da927af 100644 --- a/routes/api/task.ts +++ b/routes/api/task.ts @@ -1,7 +1,7 @@ import { Handlers } from "$fresh/server.ts"; import { get_task_manager } from "../../server.ts"; -import { Task, TaskProgress } from "../../task.ts"; -import { +import type { Task, TaskProgress } from "../../task.ts"; +import type { TaskClientSocketData, TaskServerSocketData, } from "../../server/task.ts"; diff --git a/server/cfg.ts b/server/cfg.ts index 821be9d..8b11f60 100644 --- a/server/cfg.ts +++ b/server/cfg.ts @@ -1,12 +1,12 @@ import { signal } from "@preact/signals"; import { ConfigType } from "../config.ts"; import { get_ws_host } from "./utils.ts"; -import { ConfigClientSocketData, ConfigSeverSocketData } from "./config.ts"; -import { DEFAULT_DOWNLOAD_CONFIG, DownloadConfig } from "../tasks/download.ts"; -import { - DEFAULT_EXPORT_ZIP_CONFIG, - ExportZipConfig, -} from "../tasks/export_zip.ts"; +import type { + ConfigClientSocketData, + ConfigSeverSocketData, +} from "./config.ts"; +import type { DownloadConfig } from "../tasks/download.ts"; +import type { ExportZipConfig } from "../tasks/export_zip.ts"; export const cfg = signal(undefined); @@ -30,7 +30,7 @@ export function initCfg() { } export function generate_download_cfg(): DownloadConfig { - if (!cfg.value) return DEFAULT_DOWNLOAD_CONFIG; + if (!cfg.value) return {}; const c = cfg.value; return { download_original_img: c.download_original_img, @@ -42,7 +42,7 @@ export function generate_download_cfg(): DownloadConfig { } export function generate_export_zip_cfg(): ExportZipConfig { - if (!cfg.value) return DEFAULT_EXPORT_ZIP_CONFIG; + if (!cfg.value) return {}; const c = cfg.value; return { jpn_title: c.export_zip_jpn_title, diff --git a/server/config.ts b/server/config.ts index da7b16b..f87d792 100644 --- a/server/config.ts +++ b/server/config.ts @@ -1,4 +1,4 @@ -import { ConfigType } from "../config.ts"; +import type { ConfigType } from "../config.ts"; export type ConfigClientSocketData = { type: "close" }; export type ConfigSeverSocketData = { type: "close" } | { diff --git a/server/export_zip.ts b/server/export_zip.ts index 34eb8e0..7c48def 100644 --- a/server/export_zip.ts +++ b/server/export_zip.ts @@ -1,6 +1,6 @@ import { Uint8ArrayReader, ZipWriter } from "zipjs/index.js"; -import { EhDb, PMeta } from "../db.ts"; -import { ExportZipConfig } from "../tasks/export_zip.ts"; +import type { EhDb, PMeta } from "../db.ts"; +import type { ExportZipConfig } from "../tasks/export_zip.ts"; import { addZero, configureZipJs, limitFilename } from "../utils.ts"; export function get_export_zip_response( diff --git a/server/gallery.ts b/server/gallery.ts index 7cbc587..c2d9063 100644 --- a/server/gallery.ts +++ b/server/gallery.ts @@ -1,4 +1,4 @@ -import { ExtendedPMeta, GMeta, Tag } from "../db.ts"; +import type { ExtendedPMeta, GMeta, Tag } from "../db.ts"; import { JSONResult } from "./utils.ts"; export type GalleryData = { diff --git a/server/i18ns.ts b/server/i18ns.ts index db5073e..6b4065a 100644 --- a/server/i18ns.ts +++ b/server/i18ns.ts @@ -1,7 +1,7 @@ import { exists } from "std/fs/exists.ts"; import { parse } from "std/jsonc/mod.ts"; import { join } from "std/path/mod.ts"; -import { I18NMap } from "./i18n.ts"; +import type { I18NMap } from "./i18n.ts"; import { pick } from "accept-language-parser/"; import { get_host } from "./utils.ts"; @@ -11,7 +11,10 @@ type MODULE = "common" | "settings" | "task" | "user"; const MODULES: MODULE[] = ["common", "settings", "task", "user"]; export async function load_translation(signal?: AbortSignal) { - const base = import.meta.resolve("../translation").slice(8); + let base = import.meta.resolve("../translation").slice(7); + if (Deno.build.os === "windows") { + base = base.slice(1); + } const enmap: I18NMap = {}; for (const m of MODULES) { const t = await Deno.readTextFile(join(base, "en", m + ".jsonc"), { diff --git a/server/task.ts b/server/task.ts index 45895bc..3ce323d 100644 --- a/server/task.ts +++ b/server/task.ts @@ -1,8 +1,8 @@ -import { Task } from "../task.ts"; -import { TaskEventData } from "../task_manager.ts"; -import { DownloadConfig } from "../tasks/download.ts"; -import { ExportZipConfig } from "../tasks/export_zip.ts"; -import { DiscriminatedUnion } from "../utils.ts"; +import type { Task } from "../task.ts"; +import type { TaskEventData } from "../task_manager.ts"; +import type { DownloadConfig } from "../tasks/download.ts"; +import type { ExportZipConfig } from "../tasks/export_zip.ts"; +import type { DiscriminatedUnion } from "../utils.ts"; export type TaskServerSocketData = TaskEventData | { type: "close" } | { type: "tasks"; diff --git a/signal_handler.ts b/signal_handler.ts index a6b2545..931bf0f 100644 --- a/signal_handler.ts +++ b/signal_handler.ts @@ -23,14 +23,6 @@ export function add_exit_handler(m: TaskManager) { m.close(); }; Deno.addSignalListener("SIGINT", handler); - if (Deno.build.os !== "windows") { - Deno.addSignalListener("SIGKILL", () => { - m.abort(); - m.force_abort(); - ExitTarget.dispatchEvent(new Event("close")); - m.close(); - }); - } } export function get_abort_signal(callback?: () => void): AbortSignal { @@ -40,8 +32,5 @@ export function get_abort_signal(callback?: () => void): AbortSignal { if (callback) callback(); }; Deno.addSignalListener("SIGINT", handler); - if (Deno.build.os !== "windows") { - Deno.addSignalListener("SIGKILL", handler); - } return a.signal; } diff --git a/tasks/download.ts b/tasks/download.ts index 0ed71a7..86b6597 100644 --- a/tasks/download.ts +++ b/tasks/download.ts @@ -1,7 +1,7 @@ import { assert } from "std/testing/asserts.ts"; import { Client } from "../client.ts"; -import { Config } from "../config.ts"; -import { EhDb, EhFile, PMeta } from "../db.ts"; +import type { Config } from "../config.ts"; +import type { EhDb, EhFile, PMeta } from "../db.ts"; import { Task, TaskDownloadProgess, TaskType } from "../task.ts"; import { TaskManager } from "../task_manager.ts"; import { diff --git a/tasks/export_zip.ts b/tasks/export_zip.ts index 3f627d9..1d116ea 100644 --- a/tasks/export_zip.ts +++ b/tasks/export_zip.ts @@ -1,6 +1,6 @@ import { join } from "std/path/mod.ts"; import { Uint8ArrayReader, ZipWriter } from "zipjs/index.js"; -import { EhDb } from "../db.ts"; +import type { EhDb } from "../db.ts"; import { addZero, asyncForEach, diff --git a/thumbnail/base.ts b/thumbnail/base.ts index 9e1f502..ac34640 100644 --- a/thumbnail/base.ts +++ b/thumbnail/base.ts @@ -1,6 +1,6 @@ import { join } from "std/path/mod.ts"; import { filterFilename } from "../utils.ts"; -import { EhFile } from "../db.ts"; +import type { EhFile } from "../db.ts"; export type ThumbnailConfig = { width: number; diff --git a/thumbnail/ffmpeg_binary.ts b/thumbnail/ffmpeg_binary.ts index b5f3d82..2f0ea47 100644 --- a/thumbnail/ffmpeg_binary.ts +++ b/thumbnail/ffmpeg_binary.ts @@ -1,4 +1,4 @@ -import { ThumbnailConfig } from "./base.ts"; +import type { ThumbnailConfig } from "./base.ts"; export async function check_ffmpeg_binary(p: string) { const cmd = new Deno.Command(p, {