From 1641d39ca71403bbeb3fd4816e667c820685f633 Mon Sep 17 00:00:00 2001 From: jmal Date: Fri, 23 May 2025 17:59:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E5=AD=98=E5=82=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 6c91aa5..2cb056d 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -7,6 +7,10 @@ import router from '@/router' import Layout from '@/layout' import ParentView from '@/components/ParentView' +const setState = (state) => { + localStorage.setItem('store', JSON.stringify(state)) +} + const getDefaultState = () => { const storeData = localStorage.getItem('store') let store = null @@ -127,6 +131,7 @@ const actions = { const { data } = response commit('SET_SHARE_TOKEN', data) commit('SET_SHARE_ID', shareId) + setState(state) resolve() }).catch(error => { reject(error) @@ -139,7 +144,7 @@ const actions = { commit('SET_NETDISK_NAME', netdiskName) commit('SET_NETDISK_LOGO', netdiskLogo) setLogo(netdiskName, netdiskLogo) - localStorage.setItem('store', JSON.stringify(state)) + setState(state) }, // get user info @@ -171,7 +176,7 @@ const actions = { commit('SET_NEW_VERSION', '') } setLogo(netdiskName, netdiskLogo) - localStorage.setItem('store', JSON.stringify(state)) + setState(state) resolve(data) }).catch(error => { reject(error) From 10c52d4164d604467a9a25a575b42f06bbd7292a Mon Sep 17 00:00:00 2001 From: jmal Date: Fri, 23 May 2025 18:00:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Doss=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E6=96=87=E4=BB=B6=E9=93=BE=E6=8E=A5=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/file-config.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils/file-config.js b/src/utils/file-config.js index 3916038..1c49b31 100644 --- a/src/utils/file-config.js +++ b/src/utils/file-config.js @@ -1,6 +1,12 @@ import fileApi from '@/api/file-api' import store from '@/store' +function isFilePath(str) { + // 匹配 test/r2/file.txt + const filePathRegex = /^[\w\-\/]+[\u4e00-\u9fa5\w\-]+\.\w+$/; + return filePathRegex.test(str); +} + export default { baseUrl: '/api', // 网盘logo @@ -42,8 +48,14 @@ export default { return `${fileUrl}?jmal-token=${token}&name=${username}` } if (shareToken) { + if (isFilePath(file.id)) { + return `${fileUrl}?share-token=${shareToken}` + } return `${baseUrl}/share-file/${file.id}/${shareToken}/${encodeURI(file.name)}` } + if (isFilePath(file.id)) { + return fileUrl + } return `${baseUrl}/share-file/${file.id}/${encodeURI(file.name)}` }, // 预览历史文件