优化安全码导出文件命名
This commit is contained in:
1 parent
c4a14ef1fa
commit
b4297bd72d
3 files changed
+25
-7
No files matched your search
@@ -1,4 +1,15 @@
|
||||
export function downloadRecoveryCodes(codes, documentRef = document, urlApi = URL) {
|
||||
export function buildRecoveryCodesFilename(username) {
|
||||
const normalizedUsername = String(username || '')
|
||||
.trim()
|
||||
.replace(/[<>:"/\\|?*\u0000-\u001F]/g, '-')
|
||||
.replace(/^[. -]+/g, '')
|
||||
.replace(/-{2,}/g, '-')
|
||||
.replace(/[. ]+$/g, '')
|
||||
|
||||
return `smail-${normalizedUsername || 'recovery-codes'}.txt`
|
||||
}
|
||||
|
||||
export function downloadRecoveryCodes(codes, username, documentRef = document, urlApi = URL) {
|
||||
if (!Array.isArray(codes) || codes.length === 0) return false
|
||||
|
||||
const blob = new Blob([`${codes.join('\n')}\n`], {
|
||||
@@ -8,7 +19,7 @@ export function downloadRecoveryCodes(codes, documentRef = document, urlApi = UR
|
||||
const anchor = documentRef.createElement('a')
|
||||
|
||||
anchor.href = objectUrl
|
||||
anchor.download = 'smail-recovery-codes.txt'
|
||||
anchor.download = buildRecoveryCodesFilename(username)
|
||||
anchor.style.display = 'none'
|
||||
documentRef.body.appendChild(anchor)
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ export function usePage() {
|
||||
|
||||
const saveRecoveryCodes = () => {
|
||||
if (!generatedCodes.value.length) return
|
||||
downloadRecoveryCodes(generatedCodes.value)
|
||||
downloadRecoveryCodes(generatedCodes.value, globalStatus.userInfos.account)
|
||||
notify('安全码已保存到本地文件,文件不会上传服务器', 'success')
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user