mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-06 20:42:57 +08:00
✨ Feature(custom): support sha256 placeholder for rename
ISSUES CLOSED: #393
This commit is contained in:
@@ -257,7 +257,9 @@
|
|||||||
"localFolder": "Local Folder Structure",
|
"localFolder": "Local Folder Structure",
|
||||||
"filename": "Original File Name",
|
"filename": "Original File Name",
|
||||||
"randomString": "Random String (number of digits)",
|
"randomString": "Random String (number of digits)",
|
||||||
"uuid": "Random UUID"
|
"uuid": "Random UUID",
|
||||||
|
"sha256": "SHA256 Hash",
|
||||||
|
"sha256-n": "SHA256 Hash (First n Digits)"
|
||||||
},
|
},
|
||||||
"imageProcessing": "Image Processing Settings",
|
"imageProcessing": "Image Processing Settings",
|
||||||
"deleteLocalFileAfterUpload": "Delete Local File After Upload",
|
"deleteLocalFileAfterUpload": "Delete Local File After Upload",
|
||||||
|
|||||||
@@ -252,7 +252,9 @@
|
|||||||
"localFolder": "本地文件夹层级",
|
"localFolder": "本地文件夹层级",
|
||||||
"filename": "文件原名",
|
"filename": "文件原名",
|
||||||
"randomString": "number位随机字符串",
|
"randomString": "number位随机字符串",
|
||||||
"uuid": "随机 UUID"
|
"uuid": "随机 UUID",
|
||||||
|
"sha256": "SHA256 哈希",
|
||||||
|
"sha256-n": "SHA256 哈希(前n位)"
|
||||||
},
|
},
|
||||||
"imageProcessing": "图片预处理设置",
|
"imageProcessing": "图片预处理设置",
|
||||||
"deleteLocalFileAfterUpload": "上传后删除本地文件",
|
"deleteLocalFileAfterUpload": "上传后删除本地文件",
|
||||||
|
|||||||
@@ -252,7 +252,9 @@
|
|||||||
"localFolder": "本地文件夾層級",
|
"localFolder": "本地文件夾層級",
|
||||||
"filename": "文件原名",
|
"filename": "文件原名",
|
||||||
"randomString": "number位隨機字符串",
|
"randomString": "number位隨機字符串",
|
||||||
"uuid": "隨機 UUID"
|
"uuid": "隨機 UUID",
|
||||||
|
"sha256": "SHA256 哈希",
|
||||||
|
"sha256-n": "SHA256 哈希(前n位)"
|
||||||
},
|
},
|
||||||
"imageProcessing": "圖片預處理設置",
|
"imageProcessing": "圖片預處理設置",
|
||||||
"deleteLocalFileAfterUpload": "上傳後刪除本地文件",
|
"deleteLocalFileAfterUpload": "上傳後刪除本地文件",
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ function getMd5(input: any): string {
|
|||||||
return window.node.crypto.createHash('md5').update(input).digest('hex')
|
return window.node.crypto.createHash('md5').update(input).digest('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSha256(input: any): string {
|
||||||
|
return window.node.crypto.createHash('sha256').update(input).digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
export function renameFileNameWithCustomString(oldName: string, customFormat: string, affixFileName?: string): string {
|
export function renameFileNameWithCustomString(oldName: string, customFormat: string, affixFileName?: string): string {
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
const year = date.getFullYear().toString()
|
const year = date.getFullYear().toString()
|
||||||
@@ -68,6 +72,7 @@ export function renameFileNameWithCustomString(oldName: string, customFormat: st
|
|||||||
'{ms}': () => date.getMilliseconds().toString().padStart(3, '0'),
|
'{ms}': () => date.getMilliseconds().toString().padStart(3, '0'),
|
||||||
'{md5}': () => getMd5(fileBaseName),
|
'{md5}': () => getMd5(fileBaseName),
|
||||||
'{md5-16}': () => getMd5(fileBaseName).slice(0, 16),
|
'{md5-16}': () => getMd5(fileBaseName).slice(0, 16),
|
||||||
|
'{sha256}': () => getSha256(fileBaseName),
|
||||||
'{filename}': () =>
|
'{filename}': () =>
|
||||||
affixFileName
|
affixFileName
|
||||||
? window.node.path.basename(affixFileName, window.node.path.extname(affixFileName))
|
? window.node.path.basename(affixFileName, window.node.path.extname(affixFileName))
|
||||||
@@ -87,6 +92,11 @@ export function renameFileNameWithCustomString(oldName: string, customFormat: st
|
|||||||
return acc.replace(new RegExp(cur, 'g'), conversionMap[cur]())
|
return acc.replace(new RegExp(cur, 'g'), conversionMap[cur]())
|
||||||
}, customFormat) + ext
|
}, customFormat) + ext
|
||||||
const strRegex = /{str-(\d+)}/gi
|
const strRegex = /{str-(\d+)}/gi
|
||||||
|
const sha256nRegex = /{sha256-(\d+)}/gi
|
||||||
|
newName = newName.replace(sha256nRegex, (_, group1) => {
|
||||||
|
const length = parseInt(group1, 10)
|
||||||
|
return getSha256(fileBaseName).slice(0, length)
|
||||||
|
})
|
||||||
newName = newName.replace(strRegex, (_, group1) => {
|
newName = newName.replace(strRegex, (_, group1) => {
|
||||||
const length = parseInt(group1, 10)
|
const length = parseInt(group1, 10)
|
||||||
return randomStringGenerator(length)
|
return randomStringGenerator(length)
|
||||||
@@ -239,54 +249,11 @@ export const customRenameFormatTable = [
|
|||||||
description: 'number位随机字符串',
|
description: 'number位随机字符串',
|
||||||
placeholderB: '{filename}',
|
placeholderB: '{filename}',
|
||||||
descriptionB: '原文件名'
|
descriptionB: '原文件名'
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
placeholder: '{sha256}',
|
||||||
export const buildInRenameFormatTable = [
|
description: 'SHA256 哈希',
|
||||||
{
|
placeholderB: '{sha256-n}',
|
||||||
placeholder: '{Y}',
|
descriptionB: 'SHA256 哈希(前n位)'
|
||||||
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)'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -608,7 +608,9 @@ const advancedRenameList = {
|
|||||||
categoryHash: [
|
categoryHash: [
|
||||||
{ label: t('pages.settings.upload.placeholder.md5'), value: '{md5}' },
|
{ label: t('pages.settings.upload.placeholder.md5'), value: '{md5}' },
|
||||||
{ label: t('pages.settings.upload.placeholder.md5-16'), value: '{md5-16}' },
|
{ label: t('pages.settings.upload.placeholder.md5-16'), value: '{md5-16}' },
|
||||||
{ label: t('pages.settings.upload.placeholder.uuid'), value: '{uuid}' }
|
{ label: t('pages.settings.upload.placeholder.uuid'), value: '{uuid}' },
|
||||||
|
{ label: t('pages.settings.upload.placeholder.sha256'), value: '{sha256}' },
|
||||||
|
{ label: t('pages.settings.upload.placeholder.sha256-n'), value: '{sha256-n}' }
|
||||||
],
|
],
|
||||||
categoryFile: [
|
categoryFile: [
|
||||||
{ label: t('pages.settings.upload.placeholder.filename'), value: '{filename}' },
|
{ label: t('pages.settings.upload.placeholder.filename'), value: '{filename}' },
|
||||||
|
|||||||
@@ -1487,7 +1487,9 @@ const advancedRenameList = {
|
|||||||
categoryHash: [
|
categoryHash: [
|
||||||
{ label: t('pages.settings.upload.placeholder.md5'), value: '{md5}' },
|
{ label: t('pages.settings.upload.placeholder.md5'), value: '{md5}' },
|
||||||
{ label: t('pages.settings.upload.placeholder.md5-16'), value: '{md5-16}' },
|
{ label: t('pages.settings.upload.placeholder.md5-16'), value: '{md5-16}' },
|
||||||
{ label: t('pages.settings.upload.placeholder.uuid'), value: '{uuid}' }
|
{ label: t('pages.settings.upload.placeholder.uuid'), value: '{uuid}' },
|
||||||
|
{ label: t('pages.settings.upload.placeholder.sha256'), value: '{sha256}' },
|
||||||
|
{ label: t('pages.settings.upload.placeholder.sha256-n'), value: '{sha256-n}' }
|
||||||
],
|
],
|
||||||
categoryFile: [
|
categoryFile: [
|
||||||
{ label: t('pages.settings.upload.placeholder.filename'), value: '{filename}' },
|
{ label: t('pages.settings.upload.placeholder.filename'), value: '{filename}' },
|
||||||
|
|||||||
Reference in New Issue
Block a user