feat: 前端支持以列表展示正式版和开发版的列表

This commit is contained in:
Soulter
2025-02-23 19:53:55 +08:00
parent 7d856756f4
commit 8e2c633cd4
4 changed files with 144 additions and 55 deletions

View File

@@ -32,9 +32,6 @@ class AstrBotUpdator(RepoZipUpdator):
pass
def _reboot(self, delay: int = 3):
if os.environ.get('TEST_MODE', 'off') == 'on':
logger.info("测试模式下不会重启。")
return
py = sys.executable
time.sleep(delay)
self.terminate_child_processes()
@@ -47,6 +44,9 @@ class AstrBotUpdator(RepoZipUpdator):
async def check_update(self, url: str, current_version: str) -> ReleaseInfo:
return await super().check_update(self.ASTRBOT_RELEASE_API, VERSION)
async def get_releases(self) -> list:
return await self.fetch_release_info(self.ASTRBOT_RELEASE_API)
async def update(self, reboot = False, latest = True, version = None, proxy = ""):
update_data = await self.fetch_release_info(self.ASTRBOT_RELEASE_API, latest)

View File

@@ -34,10 +34,19 @@ class RepoZipUpdator():
result = await response.json()
if not result:
return []
if latest:
ret = self.github_api_release_parser([result[0]])
else:
ret = self.github_api_release_parser(result)
# if latest:
# ret = self.github_api_release_parser([result[0]])
# else:
# ret = self.github_api_release_parser(result)
ret = []
for release in result:
ret.append({
"version": release['name'],
"published_at": release['published_at'],
"body": release['body'],
"tag_name": release['tag_name'],
"zipball_url": release['zipball_url']
})
except BaseException:
raise Exception("解析版本信息失败")
return ret
@@ -49,17 +58,10 @@ class RepoZipUpdator():
'''
ret = []
for release in releases:
version = release['name']
commit_hash = ''
# 规范是: v3.0.7.xxxxxx其中xxxxxx为 commit hash
_t = version.split(".")
if len(_t) == 4:
commit_hash = _t[3]
ret.append({
"version": release['name'],
"published_at": release['published_at'],
"body": release['body'],
"commit_hash": commit_hash,
"tag_name": release['tag_name'],
"zipball_url": release['zipball_url']
})
@@ -114,15 +116,6 @@ class RepoZipUpdator():
release_url = f"https://github.com/{author}/{repo}/archive/refs/heads/master.zip"
else:
release_url = releases[0]['zipball_url']
# 镜像站点
# match self.repo_mirror:
# case 'https://github-mirror.us.kg/':
# release_url = self.repo_mirror + release_url
# case "https://ghp.ci/":
# release_url = self.repo_mirror + release_url
# case _:
# pass
if proxy:
release_url = f"{proxy}/{release_url}"

View File

@@ -13,6 +13,7 @@ class UpdateRoute(Route):
super().__init__(context)
self.routes = {
'/update/check': ('GET', self.check_update),
'/update/releases': ('GET', self.get_releases),
'/update/do': ('POST', self.update_project),
'/update/dashboard': ('POST', self.update_dashboard),
'/update/pip-install': ('POST', self.install_pip_package)
@@ -46,6 +47,14 @@ class UpdateRoute(Route):
except Exception as e:
logger.warning(f"检查更新失败: {str(e)} (不影响除项目更新外的正常使用)")
return Response().error(e.__str__()).__dict__
async def get_releases(self):
try:
ret = await self.astrbot_updator.get_releases()
return Response().ok(ret).__dict__
except Exception as e:
logger.error(f"/api/update/releases: {traceback.format_exc()}")
return Response().error(e.__str__()).__dict__
async def update_project(self):
data = await request.json

View File

@@ -19,6 +19,18 @@ let botCurrVersion = ref('');
let dashboardHasNewVersion = ref(false);
let dashboardCurrentVersion = ref('');
let version = ref('');
let releases = ref([]);
let devCommits = ref([]); // 新增的 ref
let tab = ref(0);
let releasesHeader = [
{ title: '标签', key: 'tag_name' },
{ title: '发布时间', key: 'published_at' },
{ title: '内容', key: 'body' },
{ title: '源码地址', key: 'zipball_url' },
{ title: '操作', key: 'switch' }
];
const open = (link: string) => {
window.open(link, '_blank');
@@ -83,6 +95,41 @@ function checkUpdate() {
});
}
function getReleases() {
axios.get('/api/update/releases')
.then((res) => {
// releases.value = res.data.data;
// 更新 published_at 的时间为本地时间
releases.value = res.data.data.map((item: any) => {
item.published_at = new Date(item.published_at).toLocaleString();
return item;
})
})
.catch((err) => {
console.log(err);
});
}
function getDevCommits() {
fetch('https://api.github.com/repos/Soulter/AstrBot/commits', {
headers: {
'Host': 'api.github.com',
'Referer': 'https://api.github.com'
}
})
.then(response => response.json())
.then(data => {
devCommits.value = data.map((commit: any) => ({
sha: commit.sha,
date: new Date(commit.commit.author.date).toLocaleString(),
message: commit.commit.message
}));
})
.catch(err => {
console.log(err);
});
}
function switchVersion(version: string) {
updateStatus.value = '正在切换版本...';
axios.post('/api/update/do', {
@@ -151,10 +198,10 @@ commonStore.getStartTime();
</div>
<v-dialog v-model="updateStatusDialog" width="700">
<v-dialog v-model="updateStatusDialog" width="1000">
<template v-slot:activator="{ props }">
<v-btn @click="checkUpdate" class="text-primary mr-4" color="lightprimary" variant="flat" rounded="sm"
v-bind="props">
<v-btn @click="checkUpdate(); getReleases(); getDevCommits();" class="text-primary mr-4" color="lightprimary"
variant="flat" rounded="sm" v-bind="props">
更新 🔄
</v-btn>
</template>
@@ -164,40 +211,80 @@ commonStore.getStartTime();
</v-card-title>
<v-card-text>
<v-container>
<h3 class="mb-4">升级到项目最新版本</h3>
<small>当前版本 {{ botCurrVersion }}</small>
<div class="mb-4">
<small>会同时尝试更新机器人主程序和管理面板如果您正在使用 Docker 部署也可以重新拉取镜像或者使用 <a
href="https://containrrr.dev/watchtower/usage-overview/">watchtower</a> 来自动监控拉取</small>
<small>跳到旧版本或者切换到某个版本不会重新下载管理面板文件这可能会造成部分数据显示错误您可在 <a href="https://github.com/Soulter/AstrBot/releases">此处</a>
找到对应的面板文件 dist.zip解压后替换 data/dist 文件夹即可当然前端源代码在 dashboard 目录下你也可以自己使用 npm install npm build 构建</small>
</div>
<p>{{ updateStatus }}</p>
<v-btn class="mt-4 mb-4" @click="switchVersion('latest')" color="primary" style="border-radius: 10px;"
:disabled="!hasNewVersion">
更新到最新版本
<v-tabs v-model="tab">
<v-tab value="0">正式版</v-tab>
<v-tab value="1">开发版(master 分支)</v-tab>
</v-tabs>
<v-tabs-window v-model="tab">
<!-- 发行版 -->
<v-tabs-window-item key="0" v-show="tab == 0">
<small>当前版本 {{ botCurrVersion }}</small>
<p>{{ updateStatus }}</p>
<v-btn class="mt-4 mb-4" @click="switchVersion('latest')" color="primary" style="border-radius: 10px;"
:disabled="!hasNewVersion">
更新到最新版本
</v-btn>
<div class="mb-4">
<small>`更新到最新版本` 按钮会同时尝试更新机器人主程序和管理面板如果您正在使用 Docker 部署也可以重新拉取镜像或者使用 <a
href="https://containrrr.dev/watchtower/usage-overview/">watchtower</a> 来自动监控拉取</small>
</div>
<v-data-table :headers="releasesHeader" :items="releases" item-key="name">
<template v-slot:item.body="{ item }">
<v-tooltip :text="item.body">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" rounded="xl" variant="tonal" color="primary" size="small">查看</v-btn>
</template>
</v-tooltip>
</template>
<template v-slot:item.switch="{ item }">
<v-btn @click="switchVersion(item.tag_name)" rounded="xl" variant="plain" color="primary">
切换
</v-btn>
</template>
</v-data-table>
</v-tabs-window-item>
<!-- 开发版 -->
<v-tabs-window-item key="1" v-show="tab == 1">
<div style="margin-top: 16px;">
<v-data-table
:headers="[{ title: 'SHA', key: 'sha' }, { title: '日期', key: 'date' }, { title: '信息', key: 'message' }, { title: '操作', key: 'switch' }]"
:items="devCommits" item-key="sha">
<template v-slot:item.switch="{ item }">
<v-btn @click="switchVersion(item.sha)" rounded="xl" variant="plain" color="primary">
切换
</v-btn>
</template>
</v-data-table>
</div>
</v-tabs-window-item>
</v-tabs-window>
<h3 class="mb-4">手动输入版本号或 Commit SHA</h3>
<v-text-field label="输入版本号或 master 分支下的 commit hash。" v-model="version" required
variant="outlined"></v-text-field>
<div class="mb-4">
<small> v3.3.16 (不带 SHA) 42e5ec5d80b93b6bfe8b566754d45ffac4c3fe0b</small>
<br>
<a href="https://github.com/Soulter/AstrBot/commits/master"><small>查看 master 分支提交记录点击右边的 copy
即可复制</small></a>
</div>
<v-btn color="error" style="border-radius: 10px;" @click="switchVersion(version)">
确定切换
</v-btn>
<v-divider></v-divider>
<div style="margin-top: 16px;">
<h3 class="mb-4">切换到项目指定版本或指定提交</h3>
<div class="mb-4">
<small>跳到旧版本不会重新下载管理面板文件这可能会造成部分数据显示错误您可在 <a href="https://github.com/Soulter/AstrBot/releases">此处</a>
找到对应的面板文件 dist.zip解压后替换 data/dist 文件夹即可</small>
</div>
<v-text-field label="输入版本号或 master 分支下的 commit hash。" v-model="version" required
variant="outlined"></v-text-field>
<div class="mb-4">
<small> v3.3.16 (不带 SHA) 42e5ec5d80b93b6bfe8b566754d45ffac4c3fe0b</small>
<br>
<a href="https://github.com/Soulter/AstrBot/commits/master"><small>查看 master 分支提交记录点击右边的 copy
即可复制</small></a>
</div>
<v-btn color="error" style="border-radius: 10px;" @click="switchVersion(version)">
确定切换
</v-btn>
</div>
<v-divider></v-divider>
<div style="margin-top: 16px;">
<h3 class="mb-4">更新管理面板到最新版本</h3>
<h3 class="mb-4">单独更新管理面板到最新版本</h3>
<div class="mb-4">
<small>当前版本 {{ dashboardCurrentVersion }}</small>
<br>
@@ -268,4 +355,4 @@ commonStore.getStartTime();
</v-card>
</v-dialog>
</v-app-bar>
</template>
</template>