Update deps

This commit is contained in:
2024-05-31 10:06:51 +08:00
parent b7fd2ca133
commit 0fa8705d4a
17 changed files with 19 additions and 304 deletions

View File

@@ -1,24 +0,0 @@
import { parse_bool } from "./parse.ts";
import { set_state } from "./state.ts";
import type { StatusData } from "./status.ts";
import type { BUser } from "./user.ts";
import type { JSONResult } from "./utils.ts";
export async function check_auth_status() {
const re = await fetch("/api/user");
const u: JSONResult<BUser> = await re.json();
if (u.ok) return true;
if (u.status !== 404 && u.status !== 1 && u.status !== 401) {
throw Error(u.error);
}
const re2 = await fetch("/api/status");
const s: JSONResult<StatusData> = await re2.json();
if (!s.ok) {
throw Error(u.error);
}
if (s.data.no_user) {
if (!parse_bool(localStorage.getItem("skip_create_root_user"), false)) {
set_state("#/create_root_user");
}
} else set_state("#/login");
}

View File

@@ -1,3 +0,0 @@
import * as bs5 from "bootstrap/?target=es2022";
export default bs5;

View File

@@ -1,50 +0,0 @@
import { signal } from "@preact/signals";
import { ConfigType } from "../config.ts";
import { get_ws_host } from "./utils.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<ConfigType | undefined>(undefined);
export function initCfg() {
const ws = new WebSocket(`${get_ws_host()}/api/config?current=1&type=ws`);
console.log(ws);
function sendMessage(mes: ConfigClientSocketData) {
ws.send(JSON.stringify(mes));
}
ws.onmessage = (e) => {
const d: ConfigSeverSocketData = JSON.parse(e.data);
if (d.type === "close") {
ws.close();
} else if (d.type === "cfg") {
cfg.value = d.cfg;
}
};
self.addEventListener("beforeunload", () => {
sendMessage({ type: "close" });
});
}
export function generate_download_cfg(): DownloadConfig {
if (!cfg.value) return {};
const c = cfg.value;
return {
download_original_img: c.download_original_img,
max_download_img_count: c.max_download_img_count,
max_retry_count: c.max_retry_count,
mpv: c.mpv,
remove_previous_gallery: c.remove_previous_gallery,
};
}
export function generate_export_zip_cfg(): ExportZipConfig {
if (!cfg.value) return {};
const c = cfg.value;
return {
jpn_title: c.export_zip_jpn_title,
};
}

View File

@@ -1,12 +0,0 @@
export function detect_darkmode() {
return window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
}
export function addDarkModeListener(e: (e: MediaQueryListEvent) => void) {
return window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").addEventListener(
"change",
e,
);
}

View File

@@ -1,58 +0,0 @@
import { signal } from "@preact/signals";
import type {
MdDialog as _MdDialog,
MdMenu as _MdMenu,
MdMenuItem as _MdMenuItem,
MdOutlinedButton as _MdOutlinedButton,
MdOutlinedSelect as _MdOutlinedSelect,
MdOutlinedTextField as _MdOutlinedTextField,
MdSelectOption as _MdSelectOption,
MdTextButton as _MdTextButton,
MdTonalButton as _MdTonalButton,
} from "./md3.ts";
import type _bs5 from "./bs5.ts";
export const MdOutlinedTextField = signal<
typeof _MdOutlinedTextField | undefined
>(undefined);
export const MdOutlinedButton = signal<typeof _MdOutlinedButton | undefined>(
undefined,
);
export const MdTonalButton = signal<typeof _MdTonalButton | undefined>(
undefined,
);
export const MdSelectOption = signal<typeof _MdSelectOption | undefined>(
undefined,
);
export const MdOutlinedSelect = signal<typeof _MdOutlinedSelect | undefined>(
undefined,
);
export const MdDialog = signal<typeof _MdDialog | undefined>(undefined);
export const MdTextButton = signal<typeof _MdTextButton | undefined>(undefined);
export const MdMenu = signal<typeof _MdMenu | undefined>(undefined);
export const MdMenuItem = signal<typeof _MdMenuItem | undefined>(undefined);
export const bs5 = signal<typeof _bs5 | undefined>(undefined);
export async function load_dmodule() {
const md3 = await import("./md3.ts");
MdOutlinedTextField.value = md3.MdOutlinedTextField;
MdOutlinedButton.value = md3.MdOutlinedButton;
MdTonalButton.value = md3.MdTonalButton;
MdSelectOption.value = md3.MdSelectOption;
MdOutlinedSelect.value = md3.MdOutlinedSelect;
MdDialog.value = md3.MdDialog;
MdTextButton.value = md3.MdTextButton;
MdMenu.value = md3.MdMenu;
MdMenuItem.value = md3.MdMenuItem;
const b = await import("./bs5.ts");
bs5.value = b.default;
}

View File

@@ -1,94 +0,0 @@
import { MdOutlinedTextField as _MdOutlinedTextField } from "@material/web/textfield/outlined-text-field.js?module";
import { MdOutlinedButton as _MdOutlinedButton } from "@material/web/button/outlined-button.js?module";
import { MdTonalButton as _MdTonalButton } from "@material/web/button/tonal-button.js?module";
import { MdSelectOption as _MdSelectOption } from "@material/web/select/select-option.js?module";
import { MdOutlinedSelect as _MdOutlinedSelect } from "@material/web/select/outlined-select.js?module";
import { MdDialog as _MdDialog } from "@material/web/dialog/dialog.js?module";
import { MdTextButton as _MdTextButton } from "@material/web/button/text-button.js?module";
import { MdMenu as _MdMenu } from "@material/web/menu/menu.js?module";
import { MdMenuItem as _MdMenuItem } from "@material/web/menu/menu-item.js?module";
import { createComponent } from "@lit-labs/react/?target=es2022";
import * as Preact from "preact/compat";
export const MdOutlinedTextField = createComponent({
tagName: "md-outlined-text-field",
elementClass: _MdOutlinedTextField,
// @ts-ignore Checked
react: Preact,
});
export const MdOutlinedButton = createComponent({
tagName: "md-outlined-button",
elementClass: _MdOutlinedButton,
// @ts-ignore Checked
react: Preact,
});
export const MdTonalButton = createComponent({
tagName: "md-tonal-button",
elementClass: _MdTonalButton,
// @ts-ignore Checked
react: Preact,
});
export const MdSelectOption = createComponent({
tagName: "md-select-option",
elementClass: _MdSelectOption,
// @ts-ignore Checked
react: Preact,
});
export const MdOutlinedSelect = createComponent({
tagName: "md-outlined-select",
elementClass: _MdOutlinedSelect,
// @ts-ignore Checked
react: Preact,
});
export type DialogAction = {
action: string;
};
export const MdDialog = createComponent({
tagName: "md-dialog",
elementClass: _MdDialog,
// @ts-ignore Checked
react: Preact,
events: {
"onopening": "opening",
"onopened": "opened",
"onclosing": "closing",
"onclosed": "closed",
},
});
export const MdTextButton = createComponent({
tagName: "md-text-button",
elementClass: _MdTextButton,
// @ts-ignore Checked
react: Preact,
});
export const MdMenu = createComponent({
tagName: "md-menu",
elementClass: _MdMenu,
// @ts-ignore Checked
react: Preact,
});
export const MdMenuItem = createComponent({
tagName: "md-menu-item",
elementClass: _MdMenuItem,
// @ts-ignore Checked
react: Preact,
});
export { _MdOutlinedTextField };
export { _MdOutlinedButton };
export { _MdTonalButton };
export { _MdSelectOption };
export { _MdOutlinedSelect };
export { _MdDialog };
export { _MdTextButton };
export { _MdMenu };
export { _MdMenuItem };

View File

@@ -1,38 +0,0 @@
import { signal } from "@preact/signals";
import { StateUpdater } from "preact/hooks";
export const state = signal("#/");
let listener: StateUpdater<string> | undefined = undefined;
export function initState(l: StateUpdater<string>) {
const hash = document.location.hash;
listener = l;
if (!hash || hash == "#") {
set_state("#/");
} else {
set_state(hash);
}
self.addEventListener("popstate", (e) => {
const s = e.state;
if (typeof s === "string") {
l(s);
} else {
l("#/");
}
});
self.addEventListener("hashchange", (_) => {
const hash = document.location.hash;
if (!hash || hash == "#") {
l("#/");
} else {
l(hash);
}
});
}
export const set_state: StateUpdater<string> = (updater) => {
const v = typeof updater === "function" ? updater(state.value) : updater;
state.value = v;
history.pushState(v, "", v);
if (listener) listener(v);
};