{"record":{"id":"6c3a8e14e097a99a","repo":"siyuan-note/siyuan","slug":"conf-language-314-6c3a8e","errorCode":null,"errorMessage":"Conf.Language(314)","messagePattern":"Conf\\.Language\\(314\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":2584,"sourceCode":"\treturn &crypt, nil\n}\n\n// copyAssetDecryptIfEncrypted 把 srcPath 的 asset 复制到 destPath。\n// 若 srcPath 在已解锁的加密笔记本下，读密文→解密→写明文到 destPath（导出目录）；\n// 否则走 filelock.Copy 原路径（字节级复制，密文/明文均可）。\nfunc copyAssetDecryptIfEncrypted(srcPath, destPath string) error {\n\tif err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {\n\t\treturn err\n\t}\n\n\tboxID := ExtractBoxIDFromAssetsPath(srcPath)\n\tif boxID != \"\" && IsEncryptedBox(boxID) {\n\t\tHoldBoxReadLock(boxID)\n\t\tdefer ReleaseBoxReadLock(boxID)\n\t\tdek, err := GetDEKIfUnlocked(boxID)\n\t\tif err != nil {\n\t\t\t// 加密笔记本未解锁：fail-closed，拒绝复制（不复制密文，避免泄漏无效文件）\n\t\t\treturn errors.New(Conf.Language(314))\n\t\t}\n\t\traw, readErr := filelock.ReadFile(srcPath)\n\t\tif readErr != nil {\n\t\t\treturn readErr\n\t\t}\n\t\tdiskName := filepath.Base(srcPath)\n\t\tplain, decErr := DecryptAsset(boxID, diskName, dek, raw)\n\t\tif decErr != nil {\n\t\t\treturn errors.New(Conf.Language(316))\n\t\t}\n\t\tif err := filelock.WriteFile(destPath, plain); err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn nil\n\t}\n\treturn filelock.Copy(srcPath, destPath)\n}\n","sourceCodeStart":2566,"sourceCodeEnd":2602,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L2566-L2602","documentation":"copyAssetDecryptIfEncrypted copies an asset file from a notebook to an export destination, decrypting it first when the source notebook is an encrypted box. When GetDEKIfUnlocked cannot return the box's data-encryption key, the notebook is locked (or its key state is unavailable), and the function fail-closes: it refuses to copy ciphertext or placeholder data to the export directory to avoid leaking unusable/invalid files, returning the localized message 314 ('Please unlock the encrypted notebook first').","triggerScenarios":"Exporting/copying assets (e.g. export document, copy asset) whose srcPath resolves via ExtractBoxIDFromAssetsPath to an encrypted box (IsEncryptedBox(boxID) true) while the box's DEK is not cached because the user has not unlocked the notebook since kernel start, or the unlock session expired/was cleared.","commonSituations":"User restarts SiYuan (encrypted notebooks start locked) and then exports a document containing assets from an encrypted notebook; automated export via API/script without prior unlock; unlocking only one of several encrypted boxes and exporting assets from another; enabling encryption on an existing notebook but not completing the unlock dialog.","solutions":["Unlock the encrypted notebook in the UI (enter the notebook password) so its DEK is cached, then retry the export/copy.","If exporting programmatically, call the unlock API for the target box before triggering the export.","If the notebook should not be encrypted, remove encryption from the notebook so assets copy in plaintext.","Check GetDEKIfUnlocked/box lock state if you believe the notebook is unlocked (lock was lost, e.g. after kernel restart)."],"exampleFix":"// before: export fails with Conf.Language(314)\nexportDoc(exportPath, boxID)\n// after: ensure the box is unlocked first\nif err := UnlockBox(boxID, password); err != nil { return err }\nexportDoc(exportPath, boxID)","handlingStrategy":"try-catch","validationCode":"// Go: check unlock state before exporting assets from an encrypted box\nde, err := model.GetDEKIfUnlocked(boxID)\nif err != nil {\n    // notebook locked: prompt user to unlock before exporting\n    return fmt.Errorf(\"unlock notebook %s first\", boxID)\n}","typeGuard":null,"tryCatchPattern":"err := exportDoc(path)\nif err != nil && err.Error() == conf.Language(314) {\n    // show unlock dialog, then retry export\n    promptUnlock(boxID)\n}","preventionTips":["Unlock all encrypted notebooks right after kernel startup if you plan to export","Batch exports only after confirming every involved box is unlocked","Surface the localized 314 message directly to end users instead of wrapping it","Avoid manually copying files out of encrypted notebooks' assets folders"],"tags":["encryption","notebook","export","locked"],"backgroundTag":"authentication-required","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}