From e79744f6b6dc0cdba71d45e8828b028b0cd51b9f Mon Sep 17 00:00:00 2001 From: lifegpc Date: Fri, 24 May 2024 18:13:54 +0800 Subject: [PATCH] Remove fresh dashboard --- Dockerfile | 2 +- components/BCheckbox.tsx | 47 ---- components/BContext.tsx | 29 --- components/BMd3TextField.tsx | 141 ----------- components/BSelect.tsx | 85 ------- components/BTextField.tsx | 217 ---------------- components/CreateRootUser.tsx | 105 -------- components/Login.tsx | 100 -------- components/Md3Select.tsx | 102 -------- components/NewTask.tsx | 421 ------------------------------- components/Progress.tsx | 109 -------- components/SettingsCheckbox.tsx | 46 ---- components/SettingsContext.tsx | 33 --- components/SettingsSelect.tsx | 91 ------- components/SettingsText.tsx | 130 ---------- components/StringRecordsBox.tsx | 183 -------------- components/StyleSheet.tsx | 21 -- components/Task.tsx | 138 ---------- components/TaskFilterBar.tsx | 97 ------- deno.json | 1 - fetch_static_files.ts | 50 ---- fresh.gen.ts | 10 - islands/Container.tsx | 190 -------------- islands/Settings.tsx | 333 ------------------------ islands/TaskManager.tsx | 212 ---------------- routes/index.tsx | 61 ----- routes/manifest.json.ts | 47 ---- static/.gitignore | 2 - static/common.css | 435 -------------------------------- static/scrollBar.css | 19 -- 30 files changed, 1 insertion(+), 3456 deletions(-) delete mode 100644 components/BCheckbox.tsx delete mode 100644 components/BContext.tsx delete mode 100644 components/BMd3TextField.tsx delete mode 100644 components/BSelect.tsx delete mode 100644 components/BTextField.tsx delete mode 100644 components/CreateRootUser.tsx delete mode 100644 components/Login.tsx delete mode 100644 components/Md3Select.tsx delete mode 100644 components/NewTask.tsx delete mode 100644 components/Progress.tsx delete mode 100644 components/SettingsCheckbox.tsx delete mode 100644 components/SettingsContext.tsx delete mode 100644 components/SettingsSelect.tsx delete mode 100644 components/SettingsText.tsx delete mode 100644 components/StringRecordsBox.tsx delete mode 100644 components/StyleSheet.tsx delete mode 100644 components/Task.tsx delete mode 100644 components/TaskFilterBar.tsx delete mode 100644 fetch_static_files.ts delete mode 100644 islands/Container.tsx delete mode 100644 islands/Settings.tsx delete mode 100644 islands/TaskManager.tsx delete mode 100644 routes/index.tsx delete mode 100644 routes/manifest.json.ts delete mode 100644 static/common.css delete mode 100644 static/scrollBar.css diff --git a/Dockerfile b/Dockerfile index b97fe63..48fdd15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -97,7 +97,7 @@ COPY ./LICENSE ./ ENV LD_LIBRARY_PATH=/app/lib ENV PATH=/app/bin:$PATH -RUN deno task fetch && deno task server-build && deno task prebuild && \ +RUN deno task server-build && deno task prebuild && \ deno task cache && rm -rf ~/.cache && \ mkdir -p ./thumbnails && chmod 777 ./thumbnails && \ mkdir -p ./downloads && chmod 777 ./downloads && \ diff --git a/components/BCheckbox.tsx b/components/BCheckbox.tsx deleted file mode 100644 index 170ba7c..0000000 --- a/components/BCheckbox.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import { Component, ContextType } from "preact"; -import Checkbox from "preact-material-components/Checkbox.js"; -import { BCtx } from "./BContext.tsx"; - -type Props = { - id?: string; - checked: boolean; - name?: string; - description?: string; - set_value?: (v: boolean) => void; -}; - -export default class BCheckbox extends Component { - static contextType = BCtx; - declare context: ContextType; - set_value(value: boolean) { - if (this.props.set_value) { - this.props.set_value(value); - } else if (this.context) { - this.context.set_value((v) => { - v[this.props.name || ""] = value; - return v; - }); - } - } - render() { - let label = null; - if (this.props.description) { - label = ; - } - return ( -
- { - if (ev.target) { - const e = ev.target as HTMLInputElement; - this.set_value(e.checked); - } - }} - /> - {label} -
- ); - } -} diff --git a/components/BContext.tsx b/components/BContext.tsx deleted file mode 100644 index e8a656f..0000000 --- a/components/BContext.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { Component, ComponentChild, createContext } from "preact"; -import { StateUpdater } from "preact/hooks"; - -type State = { - set_value: StateUpdater>; -}; - -type Props = { - children: ComponentChild; - set_value: StateUpdater>; -}; - -export const BCtx = createContext(null); - -export default class BContext extends Component { - constructor(props: Props) { - super(props); - this.state = { - set_value: props.set_value, - }; - } - render() { - return ( - - {this.props.children} - - ); - } -} diff --git a/components/BMd3TextField.tsx b/components/BMd3TextField.tsx deleted file mode 100644 index 7c89b04..0000000 --- a/components/BMd3TextField.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import { Component, ComponentChildren, ContextType } from "preact"; -import { BCtx } from "./BContext.tsx"; -import { useState } from "preact/hooks"; -import type { _MdOutlinedTextField as _TextField } from "../server/md3.ts"; -import { MdOutlinedTextField } from "../server/dmodule.ts"; -import List from "preact-material-components/List.js"; - -interface TextType { - text: string; - password: string; - number: number; -} - -interface DataType { - text: never; - password: never; - number: number; -} - -type Props = { - /**@default {true} */ - clear_cache?: boolean; - label?: string; - description?: string; - value?: TextType[T]; - name?: string; - type: T; - disabled?: boolean; - children?: ComponentChildren; - set_value?: (v?: TextType[T]) => void; - min?: DataType[T]; - max?: DataType[T]; - id?: string; - list?: string; - datalist?: { value: TextType[T]; label?: string }[]; -}; - -export default class BMd3TextField - extends Component, unknown> { - static contextType = BCtx; - declare context: ContextType; - get clear_cache() { - return this.props.clear_cache !== undefined - ? this.props.clear_cache - : true; - } - get_value(e: _TextField): TextType[T] | undefined { - const type = this.props.type; - if (!e.value.length) return undefined; - // @ts-ignore Checked - if (type === "text" || type === "password") return e.value; - // @ts-ignore Checked - return e.valueAsNumber; - } - render() { - if (!MdOutlinedTextField.value) return null; - let datalist_div = null; - const [display_datalist, set_display_datalist] = useState(false); - let cn = "b-text-field md3 text"; - if (this.props.label) cn += " label"; - if (this.props.datalist && this.props.datalist.length) { - cn += " datalist"; - let cn2 = "datalist"; - if (display_datalist) cn2 += " open"; - const v = this.props.value?.toString(); - datalist_div = ( - - {this.props.datalist.map((d) => { - if (v !== undefined) { - if (!d.value.toString().startsWith(v)) return null; - } - let label_div = null; - if (d.label) { - label_div =
{d.label}
; - } - return ( - { - this.set_value(d.value); - }} - > -
{d.value}
- {label_div} -
- ); - })} -
- ); - } - const TextField = MdOutlinedTextField.value; - let desc = null; - if (this.props.description) { - desc = ; - } - let value: string | undefined; - if (this.props.value !== undefined) { - if (typeof this.props.value === "string") { - value = this.props.value; - } else { - value = this.props.value.toString(); - } - } else if (this.clear_cache) { - value = ""; - } - return ( -
- {desc} - { - if (ev.target) { - const e = ev.target as _TextField; - this.set_value(this.get_value(e)); - } - }} - onFocus={() => set_display_datalist(true)} - onBlur={() => set_display_datalist(false)} - /> - {datalist_div} - {this.props.children} -
- ); - } - set_value(value?: TextType[T]) { - if (this.props.set_value) { - this.props.set_value(value); - } else if (this.context) { - this.context.set_value((v) => { - v[this.props.name || ""] = value; - return v; - }); - } - } -} diff --git a/components/BSelect.tsx b/components/BSelect.tsx deleted file mode 100644 index a0ce16d..0000000 --- a/components/BSelect.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { Component, ContextType } from "preact"; -import Md3Select from "./Md3Select.tsx"; -import { StateUpdater } from "preact/hooks"; -import { BCtx } from "./BContext.tsx"; - -interface obj { - toString(): string; -} - -type Props = { - id?: string; - list: { value: T; text?: string; disabled?: boolean }[]; - /**@default {0}*/ - selectedIndex?: number; - selectedValue?: T; - /**@default {false}*/ - disabled?: boolean; - hintText?: string; - set_value?: StateUpdater; - name?: string; -}; - -type State = { - selectedIndex: number; -}; - -export default class BSelect extends Component, State> { - static contextType = BCtx; - declare context: ContextType; - constructor(props: Props) { - super(props); - if (!props.list.length) throw Error("No list."); - let index = props.selectedValue - ? props.list.findIndex((v) => v.value === props.selectedValue) - : props.selectedIndex; - if (index === -1) index = 0; - this.state = { selectedIndex: index || 0 }; - } - componentWillReceiveProps( - nextProps: Readonly>, - _nextContext: unknown, - ): void { - const index = nextProps.selectedValue - ? nextProps.list.findIndex((v) => - v.value === nextProps.selectedValue - ) - : nextProps.selectedIndex; - if (index === -1) return; - const selectedIndex = index || 0; - this.setState({ selectedIndex }); - } - render() { - return ( - { - this.setState({ selectedIndex }); - this.set_value(selectedIndex); - }} - selectedIndex={this.state.selectedIndex} - > - {this.props.list.map((v) => { - const t = v.text ? v.text : v.value.toString(); - return ; - })} - - ); - } - get selectedIndex() { - return this.state.selectedIndex; - } - set_value(index: number) { - const value = this.props.list[index].value; - if (this.props.set_value) { - this.props.set_value(value); - } else if (this.context) { - this.context.set_value((v) => { - v[this.props.name || ""] = value; - return v; - }); - } - } -} diff --git a/components/BTextField.tsx b/components/BTextField.tsx deleted file mode 100644 index b612b82..0000000 --- a/components/BTextField.tsx +++ /dev/null @@ -1,217 +0,0 @@ -import { Component, ComponentChildren, ContextType } from "preact"; -import TextField from "preact-material-components/TextField.js"; -import { Ref, useRef, useState } from "preact/hooks"; -import { BCtx } from "./BContext.tsx"; -import List from "preact-material-components/List.js"; - -interface TextType { - text: string; - password: string; - number: number; -} - -interface DataType { - text: never; - password: never; - number: number; -} - -type Props = { - /**@default {true} */ - clear_cache?: boolean; - value?: TextType[T]; - name?: string; - description?: string; - type: T; - label?: string; - helpertext?: string; - textarea?: boolean; - fullwidth?: boolean; - disabled?: boolean; - children?: ComponentChildren; - set_value?: (v?: TextType[T]) => void; - min?: DataType[T]; - max?: DataType[T]; - outlined?: boolean; - id?: string; - list?: string; - datalist?: { value: TextType[T]; label?: string }[]; - onPaste?: ( - clipboard: string, - ) => { text: string; overwrite?: boolean } | undefined; -}; - -export default class BTextField - extends Component, unknown> { - static contextType = BCtx; - ref: Ref | undefined; - declare context: ContextType; - clear() { - const e = this.ref?.current; - if (e) { - const b = e.base; - if (b) { - const t = b as HTMLElement; - const d = t.querySelector("input"); - if (d) { - d.value = ""; - } - } - } - } - get clear_cache() { - return this.props.clear_cache !== undefined - ? this.props.clear_cache - : true; - } - update(value: TextType[T]) { - const e = this.ref?.current; - if (e) { - const b = e.base; - if (b) { - const t = b as HTMLElement; - const d = t.querySelector("input"); - if (d) { - const type = this.props.type; - // @ts-ignore Checked - if (type === "text" || type === "password") d.value = value; - // @ts-ignore Checked - else d.valueAsNumber = value; - } - } - } - } - set_value(value?: TextType[T]) { - if (this.props.set_value) { - this.props.set_value(value); - } else if (this.context) { - this.context.set_value((v) => { - v[this.props.name || ""] = value; - return v; - }); - } - } - componentDidMount() { - if (this.props.value !== undefined) this.update(this.props.value); - else if (this.clear_cache) this.clear(); - } - componentDidUpdate( - previousProps: Readonly>, - previousState: Readonly, - snapshot: unknown, - ): void { - if (this.props.value !== undefined) this.update(this.props.value); - else if (this.clear_cache) this.clear(); - } - get value(): TextType[T] | undefined { - const e = this.ref?.current; - if (e) { - const b = e.base; - if (b) { - const t = b as HTMLElement; - const d = t.querySelector("input"); - if (d) { - return this.get_value(d); - } - } - } - return undefined; - } - get_value(e: HTMLInputElement): TextType[T] | undefined { - const type = this.props.type; - if (!e.value.length) return undefined; - // @ts-ignore Checked - if (type === "text" || type === "password") return e.value; - // @ts-ignore Checked - return e.valueAsNumber; - } - render() { - this.ref = useRef(); - let cn = "b-text-field text"; - let datalist_div = null; - const [display_datalist, set_display_datalist] = useState(false); - if (this.props.helpertext) cn += " helper"; - if (this.props.outlined) cn += " outlined"; - if (this.props.label) cn += " label"; - if (this.props.datalist && this.props.datalist.length) { - cn += " datalist"; - let cn2 = "datalist"; - if (display_datalist) cn2 += " open"; - const v = this.value?.toString(); - datalist_div = ( - - {this.props.datalist.map((d) => { - if (v !== undefined) { - if (!d.value.toString().startsWith(v)) return null; - } - let label_div = null; - if (d.label) { - label_div =
{d.label}
; - } - return ( - { - this.set_value(d.value); - }} - > -
{d.value}
- {label_div} -
- ); - })} -
- ); - } - let desc = null; - if (this.props.description) { - desc = ; - } - return ( -
- {desc} - { - if (ev.target) { - const e = ev.target as HTMLInputElement; - this.set_value(this.get_value(e)); - } - }} - min={this.props.min} - max={this.props.max} - outlined={this.props.outlined} - list={this.props.list} - onFocus={() => set_display_datalist(true)} - onBlur={() => set_display_datalist(false)} - onPaste={this.props.onPaste - ? ((e: ClipboardEvent) => { - if (!this.props.onPaste) return; - const clipboard = - e.clipboardData?.getData("text") || ""; - const v = this.props.onPaste(clipboard); - if (!v) return; - e.preventDefault(); - if (e.target) { - const i = e.target as HTMLInputElement; - if (v.overwrite) { - i.value = v.text; - } else { - i.setRangeText(v.text); - } - this.set_value(this.get_value(i)); - } - }) - : undefined} - /> - {datalist_div} - {this.props.children} -
- ); - } -} diff --git a/components/CreateRootUser.tsx b/components/CreateRootUser.tsx deleted file mode 100644 index fd6dc11..0000000 --- a/components/CreateRootUser.tsx +++ /dev/null @@ -1,105 +0,0 @@ -import { Component, ContextType } from "preact"; -import { GlobalCtx } from "./GlobalContext.tsx"; -import BMd3TextField from "./BMd3TextField.tsx"; -import t from "../server/i18n.ts"; -import { useState } from "preact/hooks"; -import { MdTextButton, MdTonalButton } from "../server/dmodule.ts"; -import { set_state } from "../server/state.ts"; -import pbkdf2Hmac from "pbkdf2-hmac/?target=es2022"; -import { encodeBase64 as encode } from "std/encoding/base64.ts"; - -type Props = { - show: boolean; -}; - -export default class CreateRootUser extends Component { - static contextType = GlobalCtx; - declare context: ContextType; - render() { - if (!this.props.show) return null; - if (!MdTonalButton.value) return null; - if (!MdTextButton.value) return null; - const [username, set_username] = useState(); - const [password, set_password] = useState(); - const [disabled, set_disabled] = useState(false); - const create_user = async (username: string, password: string) => { - set_disabled(true); - const body = new URLSearchParams(); - body.append("name", username); - body.append("password", password); - const re = await fetch("/api/user", { method: "PUT", body }); - if (re.status !== 201) { - throw Error(re.statusText); - } - const b = new URLSearchParams(); - b.append("username", username); - const p = new Uint8Array( - await pbkdf2Hmac( - password, - "eh-downloader-salt", - 210000, - 64, - "SHA-512", - ), - ); - const t = (new Date()).getTime(); - const p2 = encode( - new Uint8Array( - await pbkdf2Hmac(p, t.toString(), 1000, 64, "SHA-512"), - ), - ); - b.append("password", p2); - b.append("t", t.toString()); - b.append("set_cookie", "1"); - if (document.location.protocol === "https:") { - b.append("secure", "1"); - } - const re2 = await fetch("/api/token", { method: "PUT", body: b }); - const token = await re2.json(); - if (!token.ok) { - throw Error(token.error); - } - }; - const Button = MdTonalButton.value; - const TextButton = MdTextButton.value; - return ( -
- - - { - localStorage.setItem("skip_create_root_user", "1"); - set_state("#/"); - }} - > - {t("user.skip")} - - -
- ); - } -} diff --git a/components/Login.tsx b/components/Login.tsx deleted file mode 100644 index 40c61eb..0000000 --- a/components/Login.tsx +++ /dev/null @@ -1,100 +0,0 @@ -import { Component, ContextType } from "preact"; -import { GlobalCtx } from "./GlobalContext.tsx"; -import BMd3TextField from "./BMd3TextField.tsx"; -import t from "../server/i18n.ts"; -import { useState } from "preact/hooks"; -import { MdTonalButton } from "../server/dmodule.ts"; -import { set_state } from "../server/state.ts"; -import pbkdf2Hmac from "pbkdf2-hmac/?target=es2022"; -import { encodeBase64 as encode } from "std/encoding/base64.ts"; -import { UserAgent } from "std/http/user_agent.ts"; - -type Props = { - show: boolean; -}; - -export default class Login extends Component { - static contextType = GlobalCtx; - declare context: ContextType; - render() { - if (!this.props.show) return null; - if (!MdTonalButton.value) return null; - const [username, set_username] = useState(); - const [password, set_password] = useState(); - const [disabled, set_disabled] = useState(false); - const login = async (username: string, password: string) => { - set_disabled(true); - const b = new URLSearchParams(); - b.append("username", username); - const p = new Uint8Array( - await pbkdf2Hmac( - password, - "eh-downloader-salt", - 210000, - 64, - "SHA-512", - ), - ); - const t = (new Date()).getTime(); - const p2 = encode( - new Uint8Array( - await pbkdf2Hmac(p, t.toString(), 1000, 64, "SHA-512"), - ), - ); - b.append("password", p2); - b.append("t", t.toString()); - b.append("set_cookie", "1"); - if (document.location.protocol === "https:") { - b.append("secure", "1"); - } - b.append("client", "fresh"); - b.append("client_version", "0.0.1"); - b.append("client_platform", "web"); - const ua = new UserAgent(navigator.userAgent); - let name = ua.browser.name; - if (name && ua.browser.version) { - name += " " + ua.browser.version; - } - if (name) { - b.append("device", name); - } - const re2 = await fetch("/api/token", { method: "PUT", body: b }); - const token = await re2.json(); - if (!token.ok) { - throw Error(token.error); - } - }; - const Button = MdTonalButton.value; - return ( -
- - - -
- ); - } -} diff --git a/components/Md3Select.tsx b/components/Md3Select.tsx deleted file mode 100644 index 08782a9..0000000 --- a/components/Md3Select.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { Component, VNode } from "preact"; -import { MdOutlinedSelect, MdSelectOption } from "../server/dmodule.ts"; -import type { _MdOutlinedSelect } from "../server/md3.ts"; - -type OProps = { - value: string; - headline?: string; - selected?: boolean; - disabled?: boolean; -}; - -class Md3Option extends Component { - render() { - if (!MdSelectOption.value) return null; - const Option = MdSelectOption.value; - return ( -