Feature(custom): auto refresh after change custom url

ISSUES CLOSED: #191
This commit is contained in:
Kuingsmile 2024-04-20 11:41:56 +08:00
parent 2087d9a355
commit 939c907d23
2 changed files with 17 additions and 22 deletions

View File

@ -21,7 +21,7 @@
style="width: 200px;" style="width: 200px;"
:persistent="false" :persistent="false"
teleported teleported
@change="handleChangeCustomUrl" @change="handleChangeCustomUrlInput"
> >
<el-option <el-option
v-for="item in customDomainList" v-for="item in customDomainList"
@ -35,7 +35,7 @@
v-model="currentCustomDomain" v-model="currentCustomDomain"
:placeholder="$T('MANAGE_BUCKET_PAGE_CUSTOM_URL_INPUT_PLACEHOLDER')" :placeholder="$T('MANAGE_BUCKET_PAGE_CUSTOM_URL_INPUT_PLACEHOLDER')"
style="width: 200px;" style="width: 200px;"
@blur="handleChangeCustomUrl" @blur="handleChangeCustomUrlInput"
/> />
<el-link <el-link
v-else v-else
@ -2063,23 +2063,14 @@ async function handleClickFile (item: any) {
} }
} }
async function handleChangeCustomUrlInput () {
await handleChangeCustomUrl()
await forceRefreshFileList()
}
// //
async function handleChangeCustomUrl () { async function handleChangeCustomUrl () {
if (currentPicBedName.value === 'github') { if (['aliyun', 'tcyun', 'qiniu', 's3plist', 'webdavplist', 'local', 'sftp'].includes(currentPicBedName.value)) {
isShowLoadingPage.value = true
if (isLoadingData.value) {
ElNotification({
title: $T('MANAGE_BUCKET_CHANGE_CUSTOM_URL_TITLE'),
message: $T('MANAGE_BUCKET_CHANGE_CUSTOM_URL_MSG'),
type: 'error',
duration: 2000
})
}
isShowLoadingPage.value = true
await resetParam(true)
isShowLoadingPage.value = false
} else if (['aliyun', 'tcyun', 'qiniu', 's3plist', 'webdavplist', 'local', 'sftp'].includes(currentPicBedName.value)) {
const currentConfigs = await getConfig<any>('picBed') const currentConfigs = await getConfig<any>('picBed')
const currentConfig = currentConfigs[configMap.alias] const currentConfig = currentConfigs[configMap.alias]
const currentTransformedConfig = JSON.parse(currentConfig.transformedConfig ?? '{}') const currentTransformedConfig = JSON.parse(currentConfig.transformedConfig ?? '{}')
@ -2174,7 +2165,7 @@ async function initCustomDomainList () {
currentCustomDomain.value = `https://${configMap.bucketName}.s3.amazonaws.com` currentCustomDomain.value = `https://${configMap.bucketName}.s3.amazonaws.com`
} }
} }
handleChangeCustomUrl() await handleChangeCustomUrl()
} else if (currentPicBedName.value === 'webdavplist') { } else if (currentPicBedName.value === 'webdavplist') {
const currentConfigs = await getConfig<any>('picBed') const currentConfigs = await getConfig<any>('picBed')
const currentConfig = currentConfigs[configMap.alias] const currentConfig = currentConfigs[configMap.alias]
@ -2188,17 +2179,20 @@ async function initCustomDomainList () {
} }
currentCustomDomain.value = endpoint currentCustomDomain.value = endpoint
} }
handleChangeCustomUrl() await handleChangeCustomUrl()
} else if (currentPicBedName.value === 'local' || currentPicBedName.value === 'sftp') { } else if (currentPicBedName.value === 'local' || currentPicBedName.value === 'sftp') {
const currentConfigs = await getConfig<any>('picBed') const currentConfigs = await getConfig<any>('picBed')
const currentConfig = currentConfigs[configMap.alias] const currentConfig = currentConfigs[configMap.alias]
const currentTransformedConfig = JSON.parse(currentConfig.transformedConfig ?? '{}') const currentTransformedConfig = JSON.parse(currentConfig.transformedConfig ?? '{}')
if (currentTransformedConfig[configMap.bucketName] && currentTransformedConfig[configMap.bucketName]?.customUrl) { if (currentTransformedConfig[configMap.bucketName] && currentTransformedConfig[configMap.bucketName]?.customUrl) {
currentCustomDomain.value = currentTransformedConfig[configMap.bucketName].customUrl ?? '' currentCustomDomain.value = currentTransformedConfig[configMap.bucketName].customUrl ?? ''
if (manageStore.config.settings.isForceCustomUrlHttps && currentCustomDomain.value.startsWith('http://')) {
currentCustomDomain.value = currentCustomDomain.value.replace('http://', 'https://')
}
} else { } else {
currentCustomDomain.value = '' currentCustomDomain.value = ''
} }
handleChangeCustomUrl() await handleChangeCustomUrl()
} }
} }
@ -2232,6 +2226,7 @@ async function resetParam (force: boolean = false) {
fileSortSizeReverse.value = false fileSortSizeReverse.value = false
fileSortTimeReverse.value = false fileSortTimeReverse.value = false
if (!isAutoRefresh.value && !force && !paging.value) { if (!isAutoRefresh.value && !force && !paging.value) {
console.log('use cache')
const cachedData = await searchExistFileList() const cachedData = await searchExistFileList()
if (cachedData.length > 0) { if (cachedData.length > 0) {
currentPageFilesInfo.push(...cachedData[0].value.fullList) currentPageFilesInfo.push(...cachedData[0].value.fullList)
@ -2283,7 +2278,7 @@ watch(route, async (newRoute) => {
const parsedConfigMap = JSON.parse(queryConfigMap) const parsedConfigMap = JSON.parse(queryConfigMap)
Object.assign(configMap, parsedConfigMap) Object.assign(configMap, parsedConfigMap)
await initCustomDomainList() await initCustomDomainList()
await resetParam(false) await resetParam(true)
isShowLoadingPage.value = false isShowLoadingPage.value = false
} }
}) })
@ -3683,7 +3678,7 @@ onBeforeMount(async () => {
await manageStore.refreshConfig() await manageStore.refreshConfig()
isShowLoadingPage.value = true isShowLoadingPage.value = true
await initCustomDomainList() await initCustomDomainList()
await resetParam(false) await resetParam(true)
isShowLoadingPage.value = false isShowLoadingPage.value = false
document.addEventListener('keydown', handleDetectShiftKey) document.addEventListener('keydown', handleDetectShiftKey)
document.addEventListener('keyup', handleDetectShiftKey) document.addEventListener('keyup', handleDetectShiftKey)

View File

@ -618,7 +618,7 @@ async function initData () {
form.isShowThumbnail = config.settings.isShowThumbnail ?? false form.isShowThumbnail = config.settings.isShowThumbnail ?? false
form.isShowList = config.settings.isShowList ?? false form.isShowList = config.settings.isShowList ?? false
form.isIgnoreCase = config.settings.isIgnoreCase ?? false form.isIgnoreCase = config.settings.isIgnoreCase ?? false
form.isForceCustomUrlHttps = config.settings.isForceCustomUrlHttps ?? true form.isForceCustomUrlHttps = config.settings.isForceCustomUrlHttps ?? false
form.isEncodeUrl = config.settings.isEncodeUrl ?? false form.isEncodeUrl = config.settings.isEncodeUrl ?? false
form.isUploadKeepDirStructure = config.settings.isUploadKeepDirStructure ?? true form.isUploadKeepDirStructure = config.settings.isUploadKeepDirStructure ?? true
form.isDownloadFileKeepDirStructure = config.settings.isDownloadKeepDirStructure ?? false form.isDownloadFileKeepDirStructure = config.settings.isDownloadKeepDirStructure ?? false