优化安全码导出文件命名
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-10-06 11:08:07 +08:00
1 parent 3365f4827e
commit 288dc4b085
3 files changed
+25 -7

No files matched your search

+13 -2
View File
@@ -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')
}