Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299

Liang Ding569cd2814a5f
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 3a8389b9e0..b21cd93d7e 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -901,7 +901,7 @@
"103": "The update installation package has been automatically downloaded in the background. When exiting, you will be asked whether to install the new version",
"104": "The update installation package failed to download, please check the network connection",
"105": "Corrupted data repo have been automatically reset",
- "106": "The maximum length of the document name is 512 characters",
+ "106": "Maximum length is limited to 512 characters",
"107": "Moving document [%s]",
"108": "Cleaning obsolete indexes...",
"109": "Remove reminder completed [%s]",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 9a4cb5100a..3bdc5275b0 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -901,7 +901,7 @@
"103": "El paquete de instalación de la actualización se ha descargado automáticamente en segundo plano. Al salir, se le preguntará si desea instalar la nueva versión",
"104": "El paquete de instalación de la actualización no se pudo descargar, verifique la conexión de red",
"105": "El repositorio de datos corruptos se ha restablecido automáticamente",
- "106": "La longitud máxima del nombre del documento es de 512 caracteres.",
+ "106": "La longitud máxima está limitada a 512 caracteres",
"107": "Moviendo documento [%s]",
"108": "Limpiando índices obsoletos...",
"109": "Eliminación de recordatorios completada [%s]",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index 22eea66505..a589088b0c 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -901,7 +901,7 @@
"103": "Le package d'installation de la mise à jour a été automatiquement téléchargé en arrière-plan. En quittant, il vous sera demandé si vous souhaitez installer la nouvelle version",
"104": "Le package d'installation de la mise à jour n'a pas pu être téléchargé, veuillez vérifier la connexion réseau",
"105": "Le référentiel de données corrompu a été automatiquement réinitialisé",
- "106": "La longueur maximale du nom du document est de 512 caractères",
+ "106": "La longueur maximale est limitée à 512 caractères",
"107": "Déplacement du document [%s]",
"108": "Nettoyage des index obsolètes...",
"109": "Supprimer le rappel terminé [%s]",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index af94ca843b..eb418e1b38 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -901,7 +901,7 @@
"103": "已經在後台開始自動下載更新安裝包,退出時將詢問是否安裝新版本",
"104": "更新安裝包下載失敗,請檢查網絡連接",
"105": "已經自動重置損壞的數據倉庫",
- "106": "文檔名最大長度限制為 512 字符",
+ "106": "最大長度限制為 512 字符",
"107": "正在移動文檔 [%s]",
"108": "正在清理已過時的索引...",
"109": "移除提醒完畢 [%s]",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index b6165f387d..f119641b21 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -901,7 +901,7 @@
"103": "已经在后台开始自动下载更新安装包,退出时将询问是否安装新版本",
"104": "更新安装包下载失败,请检查网络连接",
"105": "已经自动重置损坏的数据仓库",
- "106": "文档名最大长度限制为 512 字符",
+ "106": "最大长度限制为 512 字符",
"107": "正在移动文档 [%s]",
"108": "正在清理已过时的索引...",
"109": "移除提醒完毕 [%s]",
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 678bce1e22..c50d7bc99e 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -1270,7 +1270,7 @@ func RenameDoc(boxID, p, title string) (err error) {
title = gulu.Str.RemoveInvisible(title)
if 512 < utf8.RuneCountInString(title) {
- // 限制文档名称最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
+ // 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
return errors.New(Conf.Language(106))
}
@@ -1391,9 +1391,8 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
func createDoc(boxID, p, title, dom string) (err error) {
title = gulu.Str.RemoveInvisible(title)
-
if 512 < utf8.RuneCountInString(title) {
- // 限制文档名称最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
+ // 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
return errors.New(Conf.Language(106))
}
diff --git a/kernel/model/mount.go b/kernel/model/mount.go
index c53dcc234a..ad35cebdad 100644
--- a/kernel/model/mount.go
+++ b/kernel/model/mount.go
@@ -24,6 +24,7 @@ import (
"runtime/debug"
"strings"
"time"
+ "unicode/utf8"
"github.com/88250/gulu"
"github.com/88250/lute/ast"
@@ -34,6 +35,13 @@ import (
)
func CreateBox(name string) (id string, err error) {
+ name = gulu.Str.RemoveInvisible(name)
+ if 512 < utf8.RuneCountInString(name) {
+ // 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
+ err = errors.New(Conf.Language(106))
+ return
+ }
+
id = ast.NewNodeID()
boxLocalPath := filepath.Join(util.DataDir, id)
err = os.MkdirAll(boxLocalPath, 0755)