mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 02:58:13 -05:00
✨ Feature(custom): optimize aws s3 and buildin rename
This commit is contained in:
parent
8cc07dc758
commit
9ca0e4b469
@ -68,7 +68,7 @@
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"node-ssh-no-cpu-features": "^1.0.1",
|
||||
"nodejs-file-downloader": "^4.12.1",
|
||||
"piclist": "^1.8.7",
|
||||
"piclist": "^1.8.8",
|
||||
"pinia": "^2.1.7",
|
||||
"pinia-plugin-persistedstate": "^3.2.0",
|
||||
"proxy-agent": "^5.0.0",
|
||||
|
@ -46,21 +46,29 @@ export function renameFileNameWithCustomString (oldName: string, customFormat: s
|
||||
'{y}': () => year.slice(2),
|
||||
'{m}': () => renameFormatHelper(date.getMonth() + 1),
|
||||
'{d}': () => renameFormatHelper(date.getDate()),
|
||||
'{h}': () => renameFormatHelper(date.getHours()),
|
||||
'{i}': () => renameFormatHelper(date.getMinutes()),
|
||||
'{s}': () => renameFormatHelper(date.getSeconds()),
|
||||
'{ms}': () => date.getMilliseconds().toString().padStart(3, '0'),
|
||||
'{md5}': () => getMd5(fileBaseName),
|
||||
'{md5-16}': () => getMd5(fileBaseName).slice(0, 16),
|
||||
'{str-10}': () => randomStringGenerator(10),
|
||||
'{str-20}': () => randomStringGenerator(20),
|
||||
'{filename}': () => affixFileName ? path.basename(affixFileName, path.extname(affixFileName)) : path.basename(oldName, path.extname(oldName)),
|
||||
'{uuid}': () => uuidv4().replace(/-/g, ''),
|
||||
'{timestamp}': () => Math.floor(Date.now() / 1000).toString()
|
||||
'{timestamp}': () => date.getTime().toString()
|
||||
}
|
||||
if (customFormat === undefined || !Object.keys(conversionMap).some(item => customFormat.includes(item))) {
|
||||
if (customFormat === undefined || (!Object.keys(conversionMap).some(item => customFormat.includes(item)) && !customFormat.includes('{str-'))) {
|
||||
return oldName
|
||||
}
|
||||
const ext = path.extname(oldName)
|
||||
return Object.keys(conversionMap).reduce((acc, cur) => {
|
||||
let newName = Object.keys(conversionMap).reduce((acc, cur) => {
|
||||
return acc.replace(new RegExp(cur, 'g'), conversionMap[cur]())
|
||||
}, customFormat) + ext
|
||||
const strRegex = /{str-(\d+)}/gi
|
||||
newName = newName.replace(strRegex, (_, group1) => {
|
||||
const length = parseInt(group1, 10)
|
||||
return randomStringGenerator(length)
|
||||
})
|
||||
return newName
|
||||
}
|
||||
|
||||
export function renameFile ({ timestampRename, randomStringRename, customRename, customRenameFormat }: IStringKeyMap, oldName = ''): string {
|
||||
@ -205,43 +213,6 @@ export function customStrReplace (str: string, pattern: string, replacement: str
|
||||
}
|
||||
|
||||
export const customRenameFormatTable = [
|
||||
{
|
||||
placeholder: '{Y}',
|
||||
description: '年份,4位数',
|
||||
placeholderB: '{y}',
|
||||
descriptionB: '年份,2位数'
|
||||
},
|
||||
{
|
||||
placeholder: '{m}',
|
||||
description: '月份(01-12)',
|
||||
placeholderB: '{d}',
|
||||
descriptionB: '日期(01-31)'
|
||||
},
|
||||
{
|
||||
placeholder: '{timestamp}',
|
||||
description: '时间戳(秒)',
|
||||
placeholderB: '{uuid}',
|
||||
descriptionB: 'uuid字符串'
|
||||
},
|
||||
{
|
||||
placeholder: '{md5}',
|
||||
description: 'md5',
|
||||
placeholderB: '{md5-16}',
|
||||
descriptionB: 'md5前16位'
|
||||
},
|
||||
{
|
||||
placeholder: '{str-10}',
|
||||
description: '10位随机字符串',
|
||||
placeholderB: '{str-20}',
|
||||
descriptionB: '20位随机字符串'
|
||||
},
|
||||
{
|
||||
placeholder: '{filename}',
|
||||
description: '原文件名'
|
||||
}
|
||||
]
|
||||
|
||||
export const buildInRenameFormatTable = [
|
||||
{
|
||||
placeholder: '{Y}',
|
||||
description: '年份,4位数',
|
||||
@ -263,12 +234,12 @@ export const buildInRenameFormatTable = [
|
||||
{
|
||||
placeholder: '{s}',
|
||||
description: '秒(00-59)',
|
||||
placeholderB: '{localFolder:<number>}',
|
||||
descriptionB: '本地文件夹层级'
|
||||
placeholderB: '{ms}',
|
||||
descriptionB: '毫秒(000-999)'
|
||||
},
|
||||
{
|
||||
placeholder: '{timestamp}',
|
||||
description: '时间戳(秒)',
|
||||
description: '时间戳(毫秒)',
|
||||
placeholderB: '{uuid}',
|
||||
descriptionB: 'uuid字符串'
|
||||
},
|
||||
@ -279,13 +250,58 @@ export const buildInRenameFormatTable = [
|
||||
descriptionB: 'md5前16位'
|
||||
},
|
||||
{
|
||||
placeholder: '{str-10}',
|
||||
placeholder: '{str-number}',
|
||||
description: '10位随机字符串',
|
||||
placeholderB: '{str-20}',
|
||||
descriptionB: '20位随机字符串'
|
||||
},
|
||||
{
|
||||
placeholder: '{filename}',
|
||||
description: '原文件名'
|
||||
placeholderB: '{filename}',
|
||||
descriptionB: '原文件名'
|
||||
}
|
||||
]
|
||||
|
||||
export const buildInRenameFormatTable = [
|
||||
{
|
||||
placeholder: '{Y}',
|
||||
description: '年份,4位数',
|
||||
placeholderB: '{timestamp}',
|
||||
descriptionB: '时间戳(毫秒)'
|
||||
},
|
||||
{
|
||||
placeholder: '{y}',
|
||||
description: '年份,2位数',
|
||||
placeholderB: '{md5}',
|
||||
descriptionB: 'md5'
|
||||
},
|
||||
{
|
||||
placeholder: '{m}',
|
||||
description: '月份(01-12)',
|
||||
placeholderB: '{md5-16}',
|
||||
descriptionB: 'md5前16位'
|
||||
},
|
||||
{
|
||||
placeholder: '{d}',
|
||||
description: '日期(01-31)',
|
||||
placeholderB: '{localFolder:<number>}',
|
||||
descriptionB: '本地文件夹层级'
|
||||
},
|
||||
{
|
||||
placeholder: '{h}',
|
||||
description: '小时(00-23)',
|
||||
placeholderB: '{uuid}',
|
||||
descriptionB: 'uuid字符串'
|
||||
},
|
||||
{
|
||||
placeholder: '{i}',
|
||||
description: '分钟(00-59)',
|
||||
placeholderB: '{filename}',
|
||||
descriptionB: '原文件名'
|
||||
},
|
||||
{
|
||||
placeholder: '{s}',
|
||||
description: '秒(00-59)',
|
||||
placeholderB: '{str-number}',
|
||||
descriptionB: 'number位随机字符串'
|
||||
},
|
||||
{
|
||||
placeholder: '{ms}',
|
||||
description: '毫秒(000-999)'
|
||||
}
|
||||
]
|
||||
|
@ -12397,10 +12397,10 @@ performance-now@^2.1.0:
|
||||
resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
||||
integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==
|
||||
|
||||
piclist@^1.8.7:
|
||||
version "1.8.7"
|
||||
resolved "https://registry.yarnpkg.com/piclist/-/piclist-1.8.7.tgz#aa40af42762b857ac0c45a097421278a301320cf"
|
||||
integrity sha512-asSc588Fh1aMpIq/guqqHGhZb0wsLn+wZllKbtznDasbh4zNZvQECNDxRGVtmvsSYJlR+V+yyA2Z85AW/aQqyA==
|
||||
piclist@^1.8.8:
|
||||
version "1.8.8"
|
||||
resolved "https://registry.yarnpkg.com/piclist/-/piclist-1.8.8.tgz#a4b3b4bcdd88f48de5469497e140187ea6e46ab7"
|
||||
integrity sha512-2sucOVbqVNukb0FZ4ne+DG6bzAJIxZJgm1HlOHKk/NOKYvbcXLsHq0whtEsbfwnsFmkF5T9uJtXHwZPE86JoQA==
|
||||
dependencies:
|
||||
"@aws-sdk/client-s3" "3.421.0"
|
||||
"@aws-sdk/lib-storage" "3.421.0"
|
||||
|
Loading…
Reference in New Issue
Block a user