Skip to content

Commit

Permalink
fix: downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghomist committed Feb 22, 2025
1 parent 972061e commit ee04371
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "rockoon",
"version": "1.5.1",
"version": "1.5.2",
"identifier": "com.ghomist.rockoon",
"build": {
"beforeDevCommand": "pnpm dev",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const init = async () => {

await initStores();

await checkUpdate();
await checkUpdate(true);
};

init();
6 changes: 4 additions & 2 deletions src/stores/pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export const usePrefStore = defineStore(PREF_STORE_KEY, {
backgroundBlur: 8,
maskOpacity: 0.25,
backgroundImage: undefined,
customThemeColor: "#888"
customThemeColor: "#888",
indexExpireTime: 120
}),
getters: {
hasRecent: state =>
useFileStore().instances.some(x => x.path === state.recent),
recentInstance: state =>
useFileStore().instances.find(x => x.path === state.recent)
useFileStore().instances.find(x => x.path === state.recent),
expireMs: state => state.indexExpireTime * 60 * 1000
},
actions: {
save() {
Expand Down
3 changes: 3 additions & 0 deletions src/types/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type PreferenceStore = {

/** 自定义主题色 */
customThemeColor?: string;

/** 下载站索引过期时间(分钟) */
indexExpireTime: number;
};

type FileStore = {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { usePrefStore } from "@/stores/pref";
import storage from "./storage";

const expireTime = 1000 * 60 * 90; // 90 min
const STORAGE_KEY = "ys-storage";
const username = "ballancemaps";
const indexLink = `http://c6.ysepan.com/f_ht/ajcx/ml.aspx?cz=ml_dq&_dlmc=${username}&_dlmm=`;
const fileListLink = `http://c6.ysepan.com/f_ht/ajcx/wj.aspx?cz=dq&jsq=0&mlbh={index}&wjpx=1&_dlmc=${username}&_dlmm=`;
const indexLink = `/ballance-download/f_ht/ajcx/ml.aspx?cz=ml_dq&_dlmc=${username}&_dlmm=`;
const fileListLink = `/ballance-download/f_ht/ajcx/wj.aspx?cz=dq&jsq=0&mlbh={index}&wjpx=1&_dlmc=${username}&_dlmm=`;

const getYsHtml = async (url: string) => {
let responseString = await fetch(url, {
Expand Down Expand Up @@ -57,7 +57,7 @@ export const fetchFiles = async (refresh = false) => {
if (
!refresh &&
cache.lastUpdate &&
cache.lastUpdate.getTime() + expireTime > Date.now()
cache.lastUpdate.getTime() + usePrefStore().expireMs > Date.now()
) {
return cache;
}
Expand Down
18 changes: 14 additions & 4 deletions src/utils/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { openDialog, sendMessage } from "./message";
import { h, ref } from "vue";
import { toPercentage } from "./format";

export const checkUpdate = async () => {
const update = await check();
export const checkUpdate = async (quiet = false) => {
let update;
try {
update = await check({
timeout: 10000
});
} catch {
if (!quiet) sendMessage("检查更新失败");
return;
}
if (update) {
let date = "未知";
let date = "未知更新时间";
if (update.date) {
date = update.date
.replace(/\s+([+-]\d{2}:\d{2}):\d{2}$/, "$1")
Expand Down Expand Up @@ -46,8 +54,10 @@ export const checkUpdate = async () => {
}
});
close();
sendMessage("更新完成!请重启 Rockoon");
if (!quiet) sendMessage("更新完成!请重启 Rockoon");
}
});
} else {
if (!quiet) sendMessage("已是最新版本!");
}
};
11 changes: 11 additions & 0 deletions src/views/settings/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ onMounted(() => {
ascii-only
/>
</BasicConfig>
<BasicConfig
title="下载站自动刷新时间"
tooltip="超过此时间将会自动刷新下载列表,建议设置为 120 分钟"
>
<BasicSlider
v-model="pref.indexExpireTime"
:min="30"
:max="360"
:formatter="(v: number) => v.toFixed(0) + 'min'"
/>
</BasicConfig>
<BasicConfig title="重置启动器设置">
<BasicButton @click="onRestorePref">重置</BasicButton>
</BasicConfig>
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineConfig(async () => ({
},
proxy: {
"/ballance-download": {
target: "http://ballancemaps.ysepan.com/",
target: "http://c6.ysepan.com",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/ballance-download/, "")
}
Expand Down

0 comments on commit ee04371

Please sign in to comment.