布局调整,直接使用vue3-ts-util

pull/1/head
zanllp 2023-03-11 21:33:39 +08:00
parent 63d8d99831
commit 0ca19e4e33
15 changed files with 200 additions and 214 deletions

View File

@ -6,8 +6,8 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<script type="module" crossorigin src="/baidu_netdisk/fe-static/assets/index-6bab16e5.js"></script>
<link rel="stylesheet" href="/baidu_netdisk/fe-static/assets/index-0f49a3a2.css">
<script type="module" crossorigin src="/baidu_netdisk/fe-static/assets/index-d3a213e0.js"></script>
<link rel="stylesheet" href="/baidu_netdisk/fe-static/assets/index-b702d084.css">
</head>
<body>
<div id="zanllp_dev_gradio_fe"></div>
@ -31,6 +31,7 @@
});
}
// eslint-disable-next-line no-undef
asyncCheck(() => gradioApp().querySelector("#baidu_netdisk_container_wrapper"), 500, Infinity).then((el) => {
/**
* @type {HTMLDivElement}

View File

@ -9,10 +9,17 @@ import uuid
import asyncio
import subprocess
from modules import script_callbacks, shared
from typing import List,Dict,Union
from typing import List, Dict, Union
from modules.shared import opts
from scripts.log_parser import parse_log_line
from scripts.bin import download_bin_file, get_matched_summary, check_bin_exists,cwd, bin_file_path, bin_file_name
from scripts.bin import (
download_bin_file,
get_matched_summary,
check_bin_exists,
cwd,
bin_file_path,
bin_file_name,
)
# 创建logger对象设置日志级别为DEBUG
@ -40,14 +47,14 @@ logger.addHandler(file_handler)
def get_global_conf():
default_conf = get_default_conf()
return {
"output_dirs": opts.data.get("baidu_netdisk_output_dirs") or default_conf.get("output_dirs"),
"upload_dir": opts.data.get("baidu_netdisk_upload_dir") or default_conf.get("upload_dir"),
"output_dirs": opts.data.get("baidu_netdisk_output_dirs")
or default_conf.get("output_dirs"),
"upload_dir": opts.data.get("baidu_netdisk_upload_dir")
or default_conf.get("upload_dir"),
}
def exec_ops(args: Union[List[str],str]):
def exec_ops(args: Union[List[str], str]):
args = [args] if isinstance(args, str) else args
res = ""
if check_bin_exists():
@ -121,7 +128,9 @@ def get_curr_user_name():
return res["username"] if res else "未登录"
not_exists_msg = f"找不到{bin_file_name},尝试手动从 {get_matched_summary()[1]} 下载,下载后放到 {cwd} 文件夹下,重启界面"
not_exists_msg = (
f"找不到{bin_file_name},尝试手动从 {get_matched_summary()[1]} 下载,下载后放到 {cwd} 文件夹下,重启界面"
)
def upload_file_to_baidu_net_disk(pre_log):
@ -150,11 +159,11 @@ def on_ui_tabs():
with gr.Row(visible=bool(exists and not user)) as login_form:
bduss_input = gr.Textbox(interactive=True, label="输入bduss,完成后回车登录")
with gr.Row(visible=bool(exists and user)) as operation_form:
with gr.Column(scale=2):
logout_btn = gr.Button("登出账户")
with gr.Column(scale=8):
log_text = gr.HTML("如果你看到这个那说明此项那说明出现了问题", elem_id="baidu_netdisk_container_wrapper"
with gr.Column():
html_container = gr.HTML(
"如果你看到这个那说明此项那说明出现了问题", elem_id="baidu_netdisk_container_wrapper"
)
logout_btn = gr.Button("登出账户")
def on_bduss_input_enter(bduss):
res = login_by_bduss(bduss=bduss)
@ -167,7 +176,7 @@ def on_ui_tabs():
bduss_input.submit(
on_bduss_input_enter,
inputs=[bduss_input],
outputs=[log_text, operation_form, login_form],
outputs=[html_container, operation_form, login_form],
)
def on_logout():
@ -177,6 +186,7 @@ def on_ui_tabs():
logout_btn.click(fn=on_logout, outputs=[login_form, operation_form])
return ((baidu_netdisk, "百度云上传", "baiduyun"),)
def get_default_conf():
conf_g = opts.data
outputs_dirs = ",".join(
@ -202,13 +212,16 @@ def get_default_conf():
"upload_dir": upload_dir,
}
def on_ui_settings():
bd_options = []
default_conf = get_default_conf()
bd_options.append(
("baidu_netdisk_output_dirs", default_conf["output_dirs"], "上传的本地文件夹列表,多个文件夹使用逗号分隔")
(
"baidu_netdisk_output_dirs",
default_conf["output_dirs"],
"上传的本地文件夹列表,多个文件夹使用逗号分隔",
)
)
bd_options.append(
("baidu_netdisk_upload_dir", default_conf["upload_dir"], "百度网盘用于接收上传文件的文件夹地址")
@ -232,7 +245,11 @@ subprocess_cache: Dict[str, asyncio.subprocess.Process] = {}
def baidu_netdisk_api(_: gr.Blocks, app: FastAPI):
pre = "/baidu_netdisk/"
app.mount(f"{pre}fe-static", StaticFiles(directory=f"{cwd}/vue/dist"), name="baidu_netdisk-fe-static")
app.mount(
f"{pre}fe-static",
StaticFiles(directory=f"{cwd}/vue/dist"),
name="baidu_netdisk-fe-static",
)
@app.get(f"{pre}hello")
async def greeting():
@ -243,7 +260,7 @@ def baidu_netdisk_api(_: gr.Blocks, app: FastAPI):
id = str(uuid.uuid4())
conf = get_global_conf()
dirs = str(conf["output_dirs"]).split(",")
process = await asyncio.create_subprocess_exec(
bin_file_path,
"upload",
@ -269,13 +286,13 @@ def baidu_netdisk_api(_: gr.Blocks, app: FastAPI):
line = line.decode()
# logger.info(line)
if not line:
#logger.error(line)
# logger.error(line)
break
if line.isspace():
continue
info = parse_log_line(line)
#if info is None:
#logger.error(line)
# if info is None:
# logger.error(line)
tasks.append({"info": info, "log": line})
except asyncio.TimeoutError:
break

View File

@ -1,5 +1,5 @@
import { execSync } from 'child_process'
import { readdir, readFile, rm, writeFile } from 'fs/promises'
import { readFile, rm, writeFile } from 'fs/promises'
const main = async () => {
console.log(execSync("yarn build").toString())
@ -9,7 +9,7 @@ const main = async () => {
} catch (error) {
}
const html = await readFile("dist/index.html")
const html = (await readFile("dist/index.html")).toString()
const js = (await readFile("index.tpl.js")).toString().replace("__built_html__", html)
await writeFile("../javascript/index.js", js)
}

2
vue/components.d.ts vendored
View File

@ -10,5 +10,7 @@ export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
AButton: typeof import('ant-design-vue/es')['Button']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

89
vue/dist/assets/index-d3a213e0.js vendored Normal file

File diff suppressed because one or more lines are too long

4
vue/dist/index.html vendored
View File

@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<script type="module" crossorigin src="/baidu_netdisk/fe-static/assets/index-6bab16e5.js"></script>
<link rel="stylesheet" href="/baidu_netdisk/fe-static/assets/index-0f49a3a2.css">
<script type="module" crossorigin src="/baidu_netdisk/fe-static/assets/index-d3a213e0.js"></script>
<link rel="stylesheet" href="/baidu_netdisk/fe-static/assets/index-b702d084.css">
</head>
<body>
<div id="zanllp_dev_gradio_fe"></div>

View File

@ -16,6 +16,7 @@
});
}
// eslint-disable-next-line no-undef
asyncCheck(() => gradioApp().querySelector("#baidu_netdisk_container_wrapper"), 500, Infinity).then((el) => {
/**
* @type {HTMLDivElement}

View File

@ -16,9 +16,11 @@
"ant-design-vue": "^3.2.15",
"axios": "^1.3.4",
"tsx": "^3.12.3",
"vue": "^3.2.47"
"vue": "^3.2.47",
"vue3-ts-util": "^0.8.2"
},
"devDependencies": {
"vue-router": "^4.1.6",
"@rushstack/eslint-patch": "^1.2.0",
"@types/node": "^18.14.2",
"@vitejs/plugin-vue": "^4.0.0",

View File

@ -2,7 +2,7 @@
<script setup lang="ts">
import { onMounted, ref, nextTick, reactive, computed } from 'vue'
import { getUploadTaskStatus, greeting, upload, type UploadTaskStatus } from './api'
import { Task } from './util/pollTask'
import { Task } from 'vue3-ts-util'
const pollTask = ref<ReturnType<typeof createUploadPollTask>>()
const allTaskRecord = ref([] as UploadTaskStatus[])
onMounted(async () => {

View File

@ -3,5 +3,3 @@ import App from './App.vue'
import "antd-vue-volar"
createApp(App).mount('#zanllp_dev_gradio_fe')
console.log("script running")

View File

@ -1,104 +0,0 @@
// from https://github.com/xiachufang/vue3-ts-util/blob/main/src/task.ts
interface BaseTask<T> {
/**
*
*/
action: () => T | Promise<T>
/**
*
*/
immediately?: boolean
id?: number
/**
* actiontrue
*/
validator?: (r: T) => boolean
errorHandleMethod?: 'stop' | 'ignore'
}
interface PollTask<T> extends BaseTask<T> {
/**
*
*/
pollInterval: number
}
export type TaskParams<T> = Omit<PollTask<T>, 'id'> // 去掉 PollTask 接口里面的id
export type TaskInst<T> = PollTask<T> & { isFinished: boolean; res?: T }
export class Task {
/** 为true时发生错误不打印 */
static silent = false
static run<T> (taskParams: TaskParams<T>) {
const task: TaskInst<T> = {
immediately: true, // 默认立即执行
id: -1,
isFinished: false,
errorHandleMethod: 'ignore', // 默认忽略action运行错误在下个时刻正常运行
...taskParams
}
let onReject: (t: T) => void
let onResolve: (t: T) => void
/**
* promise
* resolve
* */
const completedTask = new Promise<T>((resolve, reject) => {
onResolve = resolve // 把resolve提取出来可以减少一层嵌套
onReject = reject
})
/**
*
*
* @example
* const { clearTask } = Task.run({....})
* onMounted(clearTask)
* */
const clearTask = () => {
task.isFinished = true // 两个都要有刚好action在执行阻止运行下个action
clearTimeout(task.id) // action未执行取消任务
}
const runAction = async () => {
try {
// eslint-disable-next-line require-atomic-updates
task.res = await task.action()
// 没有验证器时认为会手动调用clearTask
if (task.validator && task.validator(task.res)) {
onResolve(task.res)
clearTask()
}
} catch (error: any) {
Task.silent || console.error(error)
if (task.errorHandleMethod === 'stop') {
clearTask()
onReject(error)
}
}
}
/**
* settimeout
*/
const asyncRunNextAction = () => {
if (task.isFinished) {
return
}
task.id = setTimeout(async () => {
await runAction()
asyncRunNextAction()
}, task.pollInterval) as any
}
/**
* runNextActionrunAction
*/
setTimeout(async () => {
task.immediately && await runAction()
asyncRunNextAction()
}, 0)
return {
task, // task 外部不可变
clearTask,
completedTask
}
}
}

View File

@ -3,10 +3,12 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import { env } from 'node:process'
const isProd = env.NODE_ENV === "production"
// https://vitejs.dev/config/
export default defineConfig({
base: 'baidu_netdisk/fe-static',
base: isProd ? '/baidu_netdisk/fe-static' : '/',
plugins: [vue(),
Components({
resolvers: [AntDesignVueResolver({ importStyle: 'css' })],

View File

@ -385,6 +385,18 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
"@types/lodash-es@^4.17.6":
version "4.17.6"
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.6.tgz#c2ed4c8320ffa6f11b43eb89e9eaeec65966a0a0"
integrity sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==
dependencies:
"@types/lodash" "*"
"@types/lodash@*", "@types/lodash@^4.14.191":
version "4.14.191"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.191.tgz#09511e7f7cba275acd8b419ddac8da9a6a79e2fa"
integrity sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==
"@types/node@^18.14.2":
version "18.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.14.6.tgz#ae1973dd2b1eeb1825695bb11ebfb746d27e3e93"
@ -570,6 +582,11 @@
"@vue/compiler-dom" "3.2.47"
"@vue/shared" "3.2.47"
"@vue/devtools-api@^6.4.5":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.5.0.tgz#98b99425edee70b4c992692628fa1ea2c1e57d07"
integrity sha512-o9KfBeaBmCKl10usN4crU53fYtC1r7jJwdGKjPT24t348rHxgfpZ0xL3Xm/gLUYnc0oTp8LAmrxOeLyu6tbk2Q==
"@vue/eslint-config-prettier@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@vue/eslint-config-prettier/-/eslint-config-prettier-7.1.0.tgz#97936379c7fb1d982b9d2c6b122306e3c2e464c8"
@ -917,7 +934,7 @@ csstype@^2.6.8:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.21.tgz#2efb85b7cc55c80017c66a5ad7cbd931fda3a90e"
integrity sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w==
dayjs@^1.10.5:
dayjs@^1.10.5, dayjs@^1.11.7:
version "1.11.7"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2"
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==
@ -1253,6 +1270,11 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
eventemitter3@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.0.tgz#084eb7f5b5388df1451e63f4c2aafd71b217ccb3"
integrity sha512-riuVbElZZNXLeLEoprfNYoDSwTBRR44X3mnhdI1YcnENpWTCsTTVZ2zFuqQcpoyqPQIUXdiPEU0ECAq0KQRaHg==
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
@ -1777,7 +1799,17 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"
lodash-es@^4.17.15:
lodash-commonjs-es@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/lodash-commonjs-es/-/lodash-commonjs-es-1.0.6.tgz#1c229271c0f8fada9f96f5751a2dcf2c35595dd4"
integrity sha512-CICituHwECZAK4hqf4mOEsw+B9OuO/4cp1aFSshtj5F9WdNOV3mkI1krAZ8+Z9OPXe3GmxJBY55M3AeQdL384A==
dependencies:
"@types/lodash" "^4.14.191"
"@types/lodash-es" "^4.17.6"
lodash "^4.17.21"
lodash-es "^4.17.21"
lodash-es@^4.17.15, lodash-es@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==
@ -2117,6 +2149,11 @@ queue-microtask@^1.2.2:
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==
ramda@^0.27.1:
version "0.27.2"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.27.2.tgz#84463226f7f36dc33592f6f4ed6374c48306c3f1"
integrity sha512-SbiLPU40JuJniHexQSAgad32hfwd+DRUdwF2PlVuI5RZD0/vahUco7R8vD86J/tcEKKF9vZrUVwgtmGCqlCKyA==
read-pkg@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
@ -2536,6 +2573,13 @@ vue-eslint-parser@^9.0.0, vue-eslint-parser@^9.0.1:
lodash "^4.17.21"
semver "^7.3.6"
vue-router@^4.1.6:
version "4.1.6"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.1.6.tgz#b70303737e12b4814578d21d68d21618469375a1"
integrity sha512-DYWYwsG6xNPmLq/FmZn8Ip+qrhFEzA14EI12MsMgVxvHFDYvlr4NXpVF5hrRH1wVcDP8fGi5F4rxuJSl8/r+EQ==
dependencies:
"@vue/devtools-api" "^6.4.5"
vue-template-compiler@^2.7.14:
version "2.7.14"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.7.14.tgz#4545b7dfb88090744c1577ae5ac3f964e61634b1"
@ -2559,6 +2603,16 @@ vue-types@^3.0.0:
dependencies:
is-plain-object "3.0.1"
vue3-ts-util@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/vue3-ts-util/-/vue3-ts-util-0.8.2.tgz#d0d9dfa6077c65bd124ba5fcf0e4ed32906be3ab"
integrity sha512-u3NCzJSt9eICW9KmODr9kJB8W9YQd2p/LCFPvBAfLS77MzNUTa6IwmgXY/YCKXWP+2y8eNLkPUzwBl+5Xze2LA==
dependencies:
dayjs "^1.11.7"
eventemitter3 "^5.0.0"
lodash-commonjs-es "^1.0.5"
ramda "^0.27.1"
vue@^3.2.47:
version "3.2.47"
resolved "https://registry.yarnpkg.com/vue/-/vue-3.2.47.tgz#3eb736cbc606fc87038dbba6a154707c8a34cff0"