🚧 WIP: add local path picbed for manage page

This commit is contained in:
萌萌哒赫萝
2023-08-12 01:00:40 -07:00
parent f585bb4d7d
commit e56bd78096
14 changed files with 457 additions and 102 deletions

View File

@@ -33,7 +33,7 @@ export default class AliyunApi {
try {
const client = AliyunApi.createClient(config)
const key = AliyunApi.getKey(fileName, config.path)
const result = await client.delete(key) as any
const result = await client.delete(key)
return result.res.status === 204
} catch (error) {
console.error(error)

View File

@@ -1570,6 +1570,7 @@ const urlToUpload = ref('')
// 图片预览相关
const previewedImage = ref('')
const ImagePreviewList = computed(() => currentPageFilesInfo.filter(item => item.isImage).map(item => item.url))
const getCurrentPreviewIndex = computed(() => ImagePreviewList.value.indexOf(previewedImage.value))
// 快捷键相关
const isShiftKeyPress = ref<boolean>(false)
const lastChoosed = ref<number>(-1)
@@ -1577,7 +1578,7 @@ const lastChoosed = ref<number>(-1)
const customDomainList = ref([] as any[])
const currentCustomDomain = ref('')
const isShowCustomDomainSelectList = computed(() => ['tcyun', 'aliyun', 'qiniu', 'github'].includes(currentPicBedName.value))
const isShowCustomDomainInput = computed(() => ['aliyun', 'qiniu', 'tcyun', 's3plist', 'webdavplist'].includes(currentPicBedName.value))
const isShowCustomDomainInput = computed(() => ['aliyun', 'qiniu', 'tcyun', 's3plist', 'webdavplist', 'local'].includes(currentPicBedName.value))
const isAutoCustomDomain = computed(() => manageStore.config.picBed[configMap.alias].isAutoCustomUrl === undefined ? true : manageStore.config.picBed[configMap.alias].isAutoCustomUrl)
// 文件预览相关
const isShowMarkDownDialog = ref(false)
@@ -1588,17 +1589,27 @@ const isShowVideoFileDialog = ref(false)
const videoFileUrl = ref('')
const videoPlayerHeaders = ref({})
// 重命名相关
const isShowRenameFileIcon = computed(() => ['tcyun', 'aliyun', 'qiniu', 'upyun', 's3plist', 'webdavplist'].includes(currentPicBedName.value))
const isShowRenameFileIcon = computed(() => ['tcyun', 'aliyun', 'qiniu', 'upyun', 's3plist', 'webdavplist', 'local'].includes(currentPicBedName.value))
const isShowBatchRenameDialog = ref(false)
const batchRenameMatch = ref('')
const batchRenameReplace = ref('')
const isRenameIncludeExt = ref(false)
const isSingleRename = ref(false)
const itemToBeRenamed = ref({} as any)
// 新建文件夹相关
const isShowCreateNewFolder = computed(() => ['tcyun', 'aliyun', 'qiniu', 'upyun', 'github', 's3plist', 'webdavplist'].includes(currentPicBedName.value))
const isShowPresignedUrl = computed(() => ['tcyun', 'aliyun', 'qiniu', 'github', 's3plist', 'webdavplist'].includes(currentPicBedName.value))
// 当前页面信息相关
const currentPicBedName = computed<string>(() => manageStore.config.picBed[configMap.alias].picBedName)
const paging = computed(() => manageStore.config.picBed[configMap.alias].paging)
const itemsPerPage = computed(() => manageStore.config.picBed[configMap.alias].itemsPerPage)
const calculateAllFileSize = computed(() => formatFileSize(currentPageFilesInfo.reduce((total: any, item: { fileSize: any }) => total + item.fileSize, 0)) || '0')
const isShowThumbnail = computed(() => manageStore.config.settings.isShowThumbnail ?? false)
const isAutoRefresh = computed(() => manageStore.config.settings.isAutoRefresh ?? false)
const isIgnoreCase = computed(() => manageStore.config.settings.isIgnoreCase ?? false)
// 新建文件夹相关
const isShowCreateNewFolder = computed(() => ['aliyun', 'github', 'local', 'qiniu', 'tcyun', 's3plist', 'upyun', 'webdavplist'].includes(currentPicBedName.value))
const isShowPresignedUrl = computed(() => ['aliyun', 'github', 'qiniu', 's3plist', 'tcyun', 'webdavplist'].includes(currentPicBedName.value))
// 上传相关函数
@@ -1655,7 +1666,7 @@ function getBase64ofWebdav () {
return headers
}
const getCurrentPreviewIndex = computed(() => ImagePreviewList.value.indexOf(previewedImage.value))
// 上传文件选择相关
function openFileSelectDialog () {
ipcRenderer.invoke('openFileSelectDialog').then((res: any) => {
@@ -1866,11 +1877,6 @@ function handleCopyUploadingTaskInfo () {
ElMessage.success($T('MANAGE_BUCKET_COPY_SUCCESS'))
}
function handleCopyDownloadingTaskInfo () {
clipboard.writeText(JSON.stringify(downloadTaskList.value, null, 2))
ElMessage.success($T('MANAGE_BUCKET_COPY_SUCCESS'))
}
function handleDeleteUploadedTask () {
ipcRenderer.send('deleteUploadedTask')
ElMessage.success($T('MANAGE_BUCKET_DELETE_SUCCESS'))
@@ -1881,6 +1887,13 @@ function handleDeleteAllUploadedTask () {
ElMessage.success($T('MANAGE_BUCKET_DELETE_SUCCESS'))
}
// 下载任务相关
function handleCopyDownloadingTaskInfo () {
clipboard.writeText(JSON.stringify(downloadTaskList.value, null, 2))
ElMessage.success($T('MANAGE_BUCKET_COPY_SUCCESS'))
}
function handleDeleteDownloadedTask () {
ipcRenderer.send('deleteDownloadedTask')
ElMessage.success($T('MANAGE_BUCKET_DELETE_SUCCESS'))
@@ -1891,7 +1904,11 @@ function handleDeleteAllDownloadedTask () {
ElMessage.success($T('MANAGE_BUCKET_DELETE_SUCCESS'))
}
const handleOpenDownloadedFolder = () => ipcRenderer.send('OpenDownloadedFolder', manageStore.config.settings.downloadDir)
function handleOpenDownloadedFolder () {
ipcRenderer.send('OpenDownloadedFolder', manageStore.config.settings.downloadDir)
}
// 文件列表相关
function handleShowFileInfo (item: any) {
isShowFileInfo.value = true
@@ -1967,17 +1984,7 @@ async function handleClickFile (item: any) {
}
}
const currentPicBedName = computed<string>(() => manageStore.config.picBed[configMap.alias].picBedName)
const paging = computed(() => manageStore.config.picBed[configMap.alias].paging)
const itemsPerPage = computed(() => manageStore.config.picBed[configMap.alias].itemsPerPage)
const calculateAllFileSize = computed(() => formatFileSize(currentPageFilesInfo.reduce((total: any, item: { fileSize: any }) => total + item.fileSize, 0)) || '0')
const isShowThumbnail = computed(() => manageStore.config.settings.isShowThumbnail ?? false)
const isAutoRefresh = computed(() => manageStore.config.settings.isAutoRefresh ?? false)
const isIgnoreCase = computed(() => manageStore.config.settings.isIgnoreCase ?? false)
// 自定义域名相关
async function handleChangeCustomUrl () {
if (currentPicBedName.value === 'github') {
@@ -2101,6 +2108,8 @@ async function initCustomDomainList () {
}
}
// 重置
async function resetParam (force: boolean = false) {
if (isLoadingData.value) {
isLoadingData.value = false
@@ -2596,7 +2605,7 @@ function handleCreateFolder () {
ElMessageBox.prompt($T('MANAGE_BUCKET_CREATE_FOLDER_BOX_TITLE'), $T('MANAGE_BUCKET_CREATE_FOLDER_BOX_TIP'), {
confirmButtonText: $T('MANAGE_BUCKET_CREATE_FOLDER_BOX_CONFIRM'),
cancelButtonText: $T('MANAGE_BUCKET_CREATE_FOLDER_BOX_CANCEL'),
inputPattern: /^[\u4e00-\u9fa5_a-zA-Z0-9/]+$/,
inputPattern: /^[\u4e00-\u9fff_a-zA-Z0-9/]+$/,
inputErrorMessage: $T('MANAGE_BUCKET_CREATE_FOLDER_ERROR_MSG')
}).then(async ({ value }) => {
let formatedPath = value
@@ -2617,7 +2626,7 @@ function handleCreateFolder () {
}).catch(() => {})
}
const showUrlDialog = () => {
function showUrlDialog () {
dialogVisible.value = true
}
@@ -2857,10 +2866,12 @@ async function getBucketFileListBackStage () {
isLoadingData.value = true
const fileTransferStore = useFileTransferStore()
fileTransferStore.resetFileTransferList()
if (currentPicBedName.value === 'webdavplist') {
if (currentPicBedName.value === 'webdavplist' ||
currentPicBedName.value === 'local') {
param.baseDir = configMap.baseDir
param.webPath = configMap.webPath
}
console.log(param)
ipcRenderer.send('getBucketListBackstage', configMap.alias, param)
ipcRenderer.on('refreshFileTransferList', (evt: IpcRendererEvent, data) => {
fileTransferStore.refreshFileTransferList(data)
@@ -3433,7 +3444,9 @@ const upLoadTaskColumns: Column<any>[] = [
}
]
const rowClass = ({ rowData }: Parameters<RowClassNameGetter<any>>[0]) => rowData.checked ? 'file-list-row-checked' : ''
function rowClass ({ rowData }: Parameters<RowClassNameGetter<any>>[0]) {
return rowData.checked ? 'file-list-row-checked' : ''
}
const columns: Column<any>[] = [
{

View File

@@ -555,7 +555,7 @@ function handleConfigImport (alias: string) {
const selectedConfig = existingConfiguration[alias]
if (!selectedConfig) return
supportedPicBedList[selectedConfig.picBedName].forEach((option: any) => {
supportedPicBedList[selectedConfig.picBedName].options.forEach((option: any) => {
if (selectedConfig[option] !== undefined) {
configResult[selectedConfig.picBedName + '.' + option] = selectedConfig[option]
}

View File

@@ -302,6 +302,7 @@ import { useManageStore } from '../store/manageStore'
// 国际化函数
import { T as $T } from '@/i18n'
import path from 'path'
const manageStore = useManageStore() as any
const route = useRoute()
@@ -443,13 +444,22 @@ async function getBucketList () {
}
}
function transPathToUnix (filePath: string | undefined) {
if (!filePath) return ''
return process.platform === 'win32' ? filePath.split(path.sep).join(path.posix.sep).replace(/^\/+|\/+$/g, '') : filePath.replace(/^\/+|\/+$/g, '')
}
function handleSelectMenu (bucketName: string) {
const currentPicBedConfig = manageStore.config.picBed[currentAlias.value]
const transformedConfig = JSON.parse(currentPicBedConfig.transformedConfig ?? '{}')
let prefix = transformedConfig[bucketName]?.baseDir || '/'
prefix = prefix.startsWith('/') ? prefix : `/${prefix}`
prefix = prefix.endsWith('/') ? prefix : `${prefix}/`
if (currentPicBedConfig.picBedName ?? currentPicBedName.value === 'local') {
prefix = `/${transPathToUnix(prefix)}/`
} else {
prefix = prefix.startsWith('/') ? prefix : `/${prefix}`
prefix = prefix.endsWith('/') ? prefix : `${prefix}/`
}
const configMap = {
prefix,
@@ -463,7 +473,7 @@ function handleSelectMenu (bucketName: string) {
webPath: currentPicBedConfig.webPath || ''
}
currentSelectedBucket.value = bucketName
console.log(configMap)
router.push({
path: '/main-page/manage-main-page/manage-bucket-page',
query: {
@@ -477,6 +487,7 @@ function switchPicBed (picBedAlias:string) {
router.push({
path: '/main-page/manage-login-page'
})
return
}
if (route.fullPath.startsWith('/main-page/manage-main-page/manage-bucket-page') || route.fullPath.startsWith('/main-page/manage-main-page/manage-setting-page')
) {

View File

@@ -41,7 +41,7 @@ const aliasRule = [
},
{
validator: (rule: any, value: any, callback: any) => {
const reg = /^[\u4e00-\u9fa5_a-zA-Z0-9-]+$/
const reg = /^[\u4e00-\u9fff_a-zA-Z0-9-]+$/
if (!reg.test(value)) {
callback(new Error($T('MANAGE_CONSTANT_ALIAS_RULE_MESSAGE_B')))
} else {
@@ -838,7 +838,7 @@ export const supportedPicBedList: IStringKeyMap = {
}
},
explain: $T('MANAGE_CONSTANT_LOCAL_EXPLAIN'),
options: ['alias', 'baseDir', 'customUrl', 'webPath'],
options: ['alias', 'baseDir', 'customUrl', 'bucketName', 'webPath'],
refLink: 'https://piclist.cn',
referenceText: $T('MANAGE_CONSTANT_LOCAL_REFER_TEXT')
}

View File

@@ -1,11 +1,18 @@
class LS {
get (name: string) {
const item = localStorage.getItem(name) as string
return item ? JSON.parse(item) : {}
const item = localStorage.getItem(name)
if (item) {
try {
return JSON.parse(item)
} catch (e) {
console.error('Failed to parse JSON:', e)
}
}
return {}
}
set (name: string, value: any) {
return localStorage.setItem(name, JSON.stringify(value))
set (name: string, value: any): void {
localStorage.setItem(name, JSON.stringify(value))
}
}