新增功能:添加zhaozuohong.vip镜像选项
This commit is contained in:
parent
501259b420
commit
de2c2af2bd
9 changed files with 123 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
||||||
from typing import List
|
from typing import List, Literal, get_args, get_origin
|
||||||
|
|
||||||
from pydantic import BaseModel, model_validator
|
from pydantic import BaseModel, model_validator
|
||||||
from pydantic_core import PydanticUndefined
|
from pydantic_core import PydanticUndefined
|
||||||
|
@ -15,6 +15,18 @@ class ConfModel(BaseModel):
|
||||||
data[name] = expected_type
|
data[name] = expected_type
|
||||||
else:
|
else:
|
||||||
data[name] = field.default
|
data[name] = field.default
|
||||||
|
value = data[name]
|
||||||
|
|
||||||
|
# 检查 Literal 类型并修正
|
||||||
|
if get_origin(expected_type) is Literal:
|
||||||
|
valid_literals = get_args(expected_type)
|
||||||
|
if value not in valid_literals:
|
||||||
|
# 修正为默认值
|
||||||
|
data[name] = (
|
||||||
|
field.default
|
||||||
|
if field.default is not PydanticUndefined
|
||||||
|
else None
|
||||||
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,9 +67,17 @@ class LaunchPart(ConfModel):
|
||||||
is_show_log: bool = False
|
is_show_log: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class OtherPart(ConfModel):
|
||||||
|
"""其他配置"""
|
||||||
|
|
||||||
|
# xx.zhaozuohong.vip镜像 (访问xx.zhaozuohong.vip url时,0=原路径 1=在.zhaozuohong.vip前添加-cf前缀)
|
||||||
|
base_mirror: Literal["0", "1"] = "0"
|
||||||
|
|
||||||
|
|
||||||
class Conf(
|
class Conf(
|
||||||
Total,
|
Total,
|
||||||
UpdatePart,
|
UpdatePart,
|
||||||
LaunchPart,
|
LaunchPart,
|
||||||
|
OtherPart,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -8,18 +8,21 @@ constants.py
|
||||||
update_tmp_folder = "download_tmp"
|
update_tmp_folder = "download_tmp"
|
||||||
# 更新脚本名
|
# 更新脚本名
|
||||||
upgrade_script_name = "upgrade.bat"
|
upgrade_script_name = "upgrade.bat"
|
||||||
|
# 下载新版本压缩包名
|
||||||
|
file_name = "launcher.7z"
|
||||||
|
|
||||||
# 获取最新版本发布信息
|
# 获取最新版本发布信息
|
||||||
get_new_version_url = (
|
get_new_version_url = (
|
||||||
"https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
|
"https://git.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
|
||||||
)
|
)
|
||||||
# 下载新版本压缩包名
|
|
||||||
file_name = "launcher.7z"
|
|
||||||
|
|
||||||
# 下载地址
|
# 下载地址
|
||||||
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
|
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
|
||||||
download_python_url = "https://list.zhaozuohong.vip/mower-ng/python.7z"
|
download_python_url = "https://list.zhaozuohong.vip/mower-ng/python.7z"
|
||||||
|
|
||||||
|
# mower-ng git链接
|
||||||
|
mower_ng_git_url = "https://git.zhaozuohong.vip/mower-ng/mower-ng.git"
|
||||||
|
|
||||||
# pip镜像地址
|
# pip镜像地址
|
||||||
mirror_list = {
|
mirror_list = {
|
||||||
"pypi": "https://pypi.org/simple",
|
"pypi": "https://pypi.org/simple",
|
||||||
|
|
12
launcher/utils.py
Normal file
12
launcher/utils.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from launcher import config
|
||||||
|
|
||||||
|
|
||||||
|
def build_base_url(url: str) -> str:
|
||||||
|
"""
|
||||||
|
构建xx.zhaozuohong.vip,如果配置base_mirror是1,在.zhaozuohong.vip前添加-cf前缀
|
||||||
|
:param url: 带有xx.zhaozuohong.vip的url字符串
|
||||||
|
:return: 构建完成的url
|
||||||
|
"""
|
||||||
|
if config.conf.base_mirror == "1":
|
||||||
|
url = url.replace(".zhaozuohong.vip", "-cf.zhaozuohong.vip")
|
||||||
|
return url
|
|
@ -3,6 +3,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
from _winapi import CREATE_NO_WINDOW
|
from _winapi import CREATE_NO_WINDOW
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
@ -20,6 +21,7 @@ from launcher.constants import (
|
||||||
mirror_list,
|
mirror_list,
|
||||||
file_name,
|
file_name,
|
||||||
instances_folder_name,
|
instances_folder_name,
|
||||||
|
mower_ng_git_url,
|
||||||
)
|
)
|
||||||
from launcher.file.download import init_download, download_file
|
from launcher.file.download import init_download, download_file
|
||||||
from launcher.file.extract import extract_7z_file
|
from launcher.file.extract import extract_7z_file
|
||||||
|
@ -27,17 +29,22 @@ from launcher.file.utils import ensure_directory_exists, check_command_path
|
||||||
from launcher.instances import manager
|
from launcher.instances import manager
|
||||||
from launcher.log import logger
|
from launcher.log import logger
|
||||||
from launcher.sys_config import sys_config
|
from launcher.sys_config import sys_config
|
||||||
|
from launcher.utils import build_base_url
|
||||||
from launcher.webview.events import custom_event, LogType
|
from launcher.webview.events import custom_event, LogType
|
||||||
|
|
||||||
command_list = {
|
command_list = {
|
||||||
"download_git": lambda: init_download("git", download_git_url, os.getcwd()),
|
"download_git": lambda: init_download(
|
||||||
|
"git", build_base_url(download_git_url), os.getcwd()
|
||||||
|
),
|
||||||
"download_python": lambda: init_download(
|
"download_python": lambda: init_download(
|
||||||
"python", download_python_url, os.getcwd()
|
"python", build_base_url(download_python_url), os.getcwd()
|
||||||
),
|
),
|
||||||
"lfs": "git\\bin\\git lfs install",
|
"lfs": "git\\bin\\git lfs install",
|
||||||
"ensurepip": "python\\python -m ensurepip --default-pip",
|
"ensurepip": "python\\python -m ensurepip --default-pip",
|
||||||
"clone": "git\\bin\\git -c lfs.concurrenttransfers=100 clone https://git.zhaozuohong.vip/mower-ng/mower-ng.git --branch slow",
|
"clone": lambda: f"git\\bin\\git -c lfs.concurrenttransfers=100 clone {build_base_url(mower_ng_git_url)} --branch slow",
|
||||||
"fetch": lambda: f"..\\git\\bin\\git fetch origin {config.conf.branch} --progress",
|
"set_remote": lambda: f"..\\git\\bin\\git remote set-url origin {build_base_url(mower_ng_git_url)}",
|
||||||
|
"set_lfs": lambda: f"..\\git\\bin\\git config lfs.url {build_base_url(mower_ng_git_url)}/info/lfs",
|
||||||
|
"fetch": lambda: f"..\\git\\bin\\git fetch {build_base_url(mower_ng_git_url)} {config.conf.branch} --progress",
|
||||||
"switch": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=100 switch -f {config.conf.branch} --progress",
|
"switch": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=100 switch -f {config.conf.branch} --progress",
|
||||||
"reset": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=200 reset --hard origin/{config.conf.branch}",
|
"reset": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=200 reset --hard origin/{config.conf.branch}",
|
||||||
"pip_tools_install": lambda: f"..\\python\\Scripts\\pip install --no-cache-dir -i {mirror_list[config.conf.mirror]} pip-tools --no-warn-script-location",
|
"pip_tools_install": lambda: f"..\\python\\Scripts\\pip install --no-cache-dir -i {mirror_list[config.conf.mirror]} pip-tools --no-warn-script-location",
|
||||||
|
@ -86,11 +93,12 @@ class Api:
|
||||||
|
|
||||||
def get_new_version(self):
|
def get_new_version(self):
|
||||||
logger.info("获取最新版本号")
|
logger.info("获取最新版本号")
|
||||||
response = requests.get(get_new_version_url)
|
response = requests.get(build_base_url(get_new_version_url))
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
# 更新启动器本身
|
# 更新启动器本身
|
||||||
def update_self(self, download_url):
|
def update_self(self, download_url):
|
||||||
|
download_url = build_base_url(download_url)
|
||||||
logger.info(f"开始更新启动器 {download_url}")
|
logger.info(f"开始更新启动器 {download_url}")
|
||||||
current_path = os.getcwd()
|
current_path = os.getcwd()
|
||||||
download_tmp_folder = os.path.join(current_path, "download_tmp")
|
download_tmp_folder = os.path.join(current_path, "download_tmp")
|
||||||
|
@ -258,3 +266,22 @@ class Api:
|
||||||
else:
|
else:
|
||||||
os.startfile(path)
|
os.startfile(path)
|
||||||
custom_event(LogType.info, f"成功打开文件夹:{path}")
|
custom_event(LogType.info, f"成功打开文件夹:{path}")
|
||||||
|
|
||||||
|
def test_base_url_connect(self):
|
||||||
|
url = build_base_url(get_new_version_url)
|
||||||
|
custom_event(LogType.info, f"开始测试URL连接:{url}")
|
||||||
|
try:
|
||||||
|
start_time = time.time()
|
||||||
|
response = requests.get(url)
|
||||||
|
end_time = time.time()
|
||||||
|
if response.status_code == 200:
|
||||||
|
elapsed_time_ms = (end_time - start_time) * 1000
|
||||||
|
custom_event(
|
||||||
|
LogType.info, f"测试成功,响应时间为 {elapsed_time_ms:.2f} 毫秒"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
custom_event(
|
||||||
|
LogType.error, f"测试失败: HTTP状态码 {response.status_code}"
|
||||||
|
)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
custom_event(LogType.error, f"发生错误: {e}")
|
||||||
|
|
30
ui/src/components/BaseMirrorOption.vue
Normal file
30
ui/src/components/BaseMirrorOption.vue
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<script setup>
|
||||||
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
import { useConfigStore } from '@/stores/config.js'
|
||||||
|
|
||||||
|
const conf = useConfigStore().config
|
||||||
|
|
||||||
|
const running = inject('running')
|
||||||
|
|
||||||
|
async function test_connect() {
|
||||||
|
running.value = true
|
||||||
|
await pywebview.api.test_base_url_connect()
|
||||||
|
running.value = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<n-form-item label="镜像模式" :label-style="form_item_label_style">
|
||||||
|
<n-radio-group v-model:value="conf.base_mirror" :disabled="running">
|
||||||
|
<n-flex>
|
||||||
|
<n-radio value="0">默认模式</n-radio>
|
||||||
|
<n-radio value="1">镜像模式(-cf后缀)</n-radio>
|
||||||
|
</n-flex>
|
||||||
|
</n-radio-group>
|
||||||
|
<n-button strong secondary type="primary" size="small" @click="test_connect" :disabled="running"
|
||||||
|
>测试连接</n-button
|
||||||
|
>
|
||||||
|
</n-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
|
@ -1,4 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
|
||||||
|
|
||||||
const steps = ref([
|
const steps = ref([
|
||||||
{
|
{
|
||||||
title: '下载 git、python',
|
title: '下载 git、python',
|
||||||
|
@ -22,6 +24,9 @@ provide('current_state', current_state)
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
|
<base-mirror-option />
|
||||||
|
</n-form>
|
||||||
<n-alert title="以下步骤仅需运行一次" type="warning" />
|
<n-alert title="以下步骤仅需运行一次" type="warning" />
|
||||||
<n-steps :current="current_step" :status="current_state" size="small">
|
<n-steps :current="current_step" :status="current_state" size="small">
|
||||||
<n-step v-for="step in steps" :title="step.title" />
|
<n-step v-for="step in steps" :title="step.title" />
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { SyncCircle } from '@vicons/ionicons5'
|
import { Sync } from '@vicons/ionicons5'
|
||||||
import { form_item_label_style } from '@/styles/styles.js'
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
|
||||||
|
|
||||||
const notification = useNotification()
|
const notification = useNotification()
|
||||||
|
|
||||||
|
@ -58,17 +59,20 @@ async function check_update() {
|
||||||
<template>
|
<template>
|
||||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
|
<base-mirror-option />
|
||||||
<n-form-item label="版本" :label-style="form_item_label_style">
|
<n-form-item label="版本" :label-style="form_item_label_style">
|
||||||
<n-space align="center">
|
<n-space align="center">
|
||||||
{{ version }}
|
{{ version }}
|
||||||
<n-button
|
<n-button
|
||||||
type="success"
|
type="success"
|
||||||
|
secondary
|
||||||
|
size="small"
|
||||||
:loading="check_running"
|
:loading="check_running"
|
||||||
:disabled="running"
|
:disabled="running"
|
||||||
@click="check_update"
|
@click="check_update"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon :component="SyncCircle"></n-icon>
|
<n-icon :component="Sync"></n-icon>
|
||||||
</template>
|
</template>
|
||||||
检查更新
|
检查更新
|
||||||
</n-button>
|
</n-button>
|
||||||
|
@ -77,11 +81,14 @@ async function check_update() {
|
||||||
<n-alert style="margin: 8px 0" type="success" v-if="update_able">
|
<n-alert style="margin: 8px 0" type="success" v-if="update_able">
|
||||||
<template #header>
|
<template #header>
|
||||||
最新版本:{{ `${new_version.tag_name} ${new_version.name}` }}
|
最新版本:{{ `${new_version.tag_name} ${new_version.name}` }}
|
||||||
<n-button style="float: right" @click="open_new_version_html">了解此版本</n-button>
|
<n-button type="success" secondary style="float: right" @click="open_new_version_html">
|
||||||
|
了解此版本
|
||||||
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
<n-space>
|
<n-space>
|
||||||
<n-button
|
<n-button
|
||||||
type="success"
|
type="success"
|
||||||
|
secondary
|
||||||
:loading="update_self_running"
|
:loading="update_self_running"
|
||||||
:disabled="running"
|
:disabled="running"
|
||||||
@click="update_self"
|
@click="update_self"
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useConfigStore } from '@/stores/config.js'
|
import { useConfigStore } from '@/stores/config.js'
|
||||||
import { form_item_label_style } from '@/styles/styles.js'
|
import { form_item_label_style } from '@/styles/styles.js'
|
||||||
|
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
|
||||||
|
|
||||||
const conf = useConfigStore().config
|
const conf = useConfigStore().config
|
||||||
const branch = ref(null)
|
const branch = ref(null)
|
||||||
const mirror = ref(null)
|
const mirror = ref(null)
|
||||||
|
const running = inject('running')
|
||||||
|
|
||||||
const steps = computed(() => [
|
const steps = computed(() => [
|
||||||
{
|
{
|
||||||
title: '更新源码',
|
title: '更新源码',
|
||||||
command: ['fetch', 'switch', 'reset'],
|
command: ['set_remote', 'set_lfs', 'fetch', 'switch', 'reset'],
|
||||||
cwd: 'mower-ng'
|
cwd: 'mower-ng'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -28,8 +30,9 @@ provide('current_state', current_state)
|
||||||
<template>
|
<template>
|
||||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||||
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||||
|
<base-mirror-option />
|
||||||
<n-form-item label="mower-ng 代码分支" :label-style="form_item_label_style">
|
<n-form-item label="mower-ng 代码分支" :label-style="form_item_label_style">
|
||||||
<n-radio-group v-model:value="conf.branch">
|
<n-radio-group v-model:value="conf.branch" :disabled="running">
|
||||||
<n-flex>
|
<n-flex>
|
||||||
<n-radio value="fast">测试版</n-radio>
|
<n-radio value="fast">测试版</n-radio>
|
||||||
<n-radio value="slow">稳定版</n-radio>
|
<n-radio value="slow">稳定版</n-radio>
|
||||||
|
@ -37,7 +40,7 @@ provide('current_state', current_state)
|
||||||
</n-radio-group>
|
</n-radio-group>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="PyPI 仓库镜像" :label-style="form_item_label_style">
|
<n-form-item label="PyPI 仓库镜像" :label-style="form_item_label_style">
|
||||||
<n-radio-group v-model:value="conf.mirror">
|
<n-radio-group v-model:value="conf.mirror" :disabled="running">
|
||||||
<n-flex>
|
<n-flex>
|
||||||
<n-radio value="pypi">PyPI</n-radio>
|
<n-radio value="pypi">PyPI</n-radio>
|
||||||
<n-radio value="aliyun">阿里云镜像站</n-radio>
|
<n-radio value="aliyun">阿里云镜像站</n-radio>
|
||||||
|
|
|
@ -20,6 +20,8 @@ export const useConfigStore = defineStore('config', () => {
|
||||||
// 启动程序 LaunchPart
|
// 启动程序 LaunchPart
|
||||||
this.instances = []
|
this.instances = []
|
||||||
this.is_show_log = conf.is_show_log
|
this.is_show_log = conf.is_show_log
|
||||||
|
// 其他部分 OtherPart
|
||||||
|
this.base_mirror = conf.base_mirror
|
||||||
Object.assign(this, conf)
|
Object.assign(this, conf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue