A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:bug: PDF files with too long file names cannot generate annotated images https://github.com/siyuan-note/siyuan/issues/15739 https://github.com/siyuan-note/siyuan/issues/10666

Daniel cfb976eb 1e95b68d

+34 -15
+1 -1
kernel/api/extension.go
··· 154 154 fName += ext 155 155 } 156 156 157 - fName = util.AssetName(fName) 157 + fName = util.AssetName(fName, ast.NewNodeID()) 158 158 writePath := filepath.Join(assets, fName) 159 159 if err = filelock.WriteFile(writePath, data); err != nil { 160 160 ret.Code = -1
+2 -1
kernel/mobile/kernel.go
··· 26 26 "time" 27 27 28 28 "github.com/88250/gulu" 29 + "github.com/88250/lute/ast" 29 30 "github.com/siyuan-note/filelock" 30 31 "github.com/siyuan-note/httpclient" 31 32 "github.com/siyuan-note/logging" ··· 289 290 } 290 291 291 292 func AssetName(name string) string { 292 - return util.AssetName(name) 293 + return util.AssetName(name, ast.NewNodeID()) 293 294 }
+3 -3
kernel/model/assets.go
··· 201 201 name := filepath.Base(u) 202 202 name = util.FilterUploadFileName(name) 203 203 name = "network-asset-" + name 204 - name = util.AssetName(name) 204 + name = util.AssetName(name, ast.NewNodeID()) 205 205 writePath := filepath.Join(assetsDirPath, name) 206 206 if err = filelock.Copy(u, writePath); err != nil { 207 207 logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err) ··· 303 303 name += ext 304 304 } 305 305 } 306 - name = util.AssetName(name) 306 + name = util.AssetName(name, ast.NewNodeID()) 307 307 name = "network-asset-" + name 308 308 writePath := filepath.Join(assetsDirPath, name) 309 309 if err = filelock.WriteFile(writePath, data); err != nil { ··· 737 737 return 738 738 } 739 739 740 - newName = util.AssetName(newName + filepath.Ext(oldPath)) 740 + newName = util.AssetName(newName+filepath.Ext(oldPath), ast.NewNodeID()) 741 741 parentDir := path.Dir(oldPath) 742 742 newPath = path.Join(parentDir, newName) 743 743 oldAbsPath, getErr := GetAssetAbsPath(oldPath)
+2 -1
kernel/model/carddav.go
··· 28 28 "sync" 29 29 30 30 "github.com/88250/gulu" 31 + "github.com/88250/lute/ast" 31 32 "github.com/emersion/go-vcard" 32 33 "github.com/emersion/go-webdav/carddav" 33 34 "github.com/siyuan-note/logging" ··· 640 641 addressesWaitGroup.Add(1) 641 642 go func() { 642 643 defer addressesWaitGroup.Done() 643 - filename_ := util.AssetName(filename) 644 + filename_ := util.AssetName(filename, ast.NewNodeID()) 644 645 address := &AddressObject{ 645 646 FilePath: path.Join(b.DirectoryPath, filename_), 646 647 BookPath: b.MetaData.Path,
+3 -3
kernel/model/import.go
··· 981 981 if "" == existName { 982 982 name = filepath.Base(absolutePath) 983 983 name = util.FilterUploadFileName(name) 984 - name = util.AssetName(name) 984 + name = util.AssetName(name, ast.NewNodeID()) 985 985 assetTargetPath := filepath.Join(assetDirPath, name) 986 986 if err = filelock.Copy(absolutePath, assetTargetPath); err != nil { 987 987 logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err) ··· 1104 1104 if "" == existName { 1105 1105 name = filepath.Base(absolutePath) 1106 1106 name = util.FilterUploadFileName(name) 1107 - name = util.AssetName(name) 1107 + name = util.AssetName(name, ast.NewNodeID()) 1108 1108 assetTargetPath := filepath.Join(assetDirPath, name) 1109 1109 if err = filelock.Copy(absolutePath, assetTargetPath); err != nil { 1110 1110 logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err) ··· 1249 1249 name = alt.TokensStr() + ext 1250 1250 } 1251 1251 name = util.FilterUploadFileName(name) 1252 - name = util.AssetName(name) 1252 + name = util.AssetName(name, ast.NewNodeID()) 1253 1253 1254 1254 tmp := filepath.Join(base64TmpDir, name) 1255 1255 tmpFile, openErr := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE, 0644)
+21 -4
kernel/model/upload.go
··· 25 25 "strings" 26 26 27 27 "github.com/88250/gulu" 28 + "github.com/88250/lute/ast" 28 29 "github.com/gin-gonic/gin" 29 30 "github.com/siyuan-note/filelock" 30 31 "github.com/siyuan-note/logging" ··· 93 94 // 已经存在同样数据的资源文件的话不重复保存 94 95 succMap[baseName] = existAsset.Path 95 96 } else { 96 - fName = util.AssetName(fName) 97 + fName = util.AssetName(fName, ast.NewNodeID()) 97 98 writePath := filepath.Join(assetsDirPath, fName) 98 99 if _, err = f.Seek(0, io.SeekStart); err != nil { 99 100 f.Close() ··· 163 164 164 165 for _, file := range files { 165 166 baseName := file.Filename 167 + _, lastID := util.LastID(baseName) 168 + if !ast.IsNodeIDPattern(lastID) { 169 + lastID = "" 170 + } 166 171 167 172 needUnzip2Dir := false 168 173 if gulu.OS.IsDarwin() { ··· 198 203 } else { 199 204 if skipIfDuplicated { 200 205 // 复制 PDF 矩形注解时不再重复插入图片 No longer upload image repeatedly when copying PDF rectangle annotation https://github.com/siyuan-note/siyuan/issues/10666 201 - matches, globErr := filepath.Glob(assetsDirPath + string(os.PathSeparator) + strings.TrimSuffix(fName, ext) + "*" + ext) 206 + pattern := assetsDirPath + string(os.PathSeparator) + strings.TrimSuffix(fName, ext) 207 + _, patternLastID := util.LastID(fName) 208 + if lastID != "" && lastID != patternLastID { 209 + // 文件名太长被截断了,通过之前的 lastID 来匹配 PDF files with too long file names cannot generate annotated images https://github.com/siyuan-note/siyuan/issues/15739 210 + pattern = assetsDirPath + string(os.PathSeparator) + "*" + lastID + ext 211 + } else { 212 + pattern += "*" + ext 213 + } 214 + 215 + matches, globErr := filepath.Glob(pattern) 202 216 if nil != globErr { 203 217 logging.LogErrorf("glob failed: %s", globErr) 204 218 } else { ··· 211 225 } 212 226 } 213 227 214 - fName = util.AssetName(fName) 228 + if "" == lastID { 229 + lastID = ast.NewNodeID() 230 + } 231 + fName = util.AssetName(fName, lastID) 215 232 writePath := filepath.Join(assetsDirPath, fName) 216 233 tmpDir := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7)) 217 234 if needUnzip2Dir { ··· 248 265 fName = strings.TrimSuffix(fName, ext) 249 266 ext = strings.ToLower(ext) 250 267 fName += ext 251 - fName = util.AssetName(fName) 268 + fName = util.AssetName(fName, ast.NewNodeID()) 252 269 tmpDir2 := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7)) 253 270 if err = gulu.Zip.Unzip(writePath, tmpDir2); err != nil { 254 271 errFiles = append(errFiles, fName)
+2 -2
kernel/util/file.go
··· 172 172 return 173 173 } 174 174 175 - func AssetName(name string) string { 175 + func AssetName(name, newID string) string { 176 176 _, id := LastID(name) 177 177 ext := Ext(name) 178 178 name = name[0 : len(name)-len(ext)] 179 179 if !ast.IsNodeIDPattern(id) { 180 - id = ast.NewNodeID() 180 + id = newID 181 181 name = name + "-" + id + ext 182 182 } else { 183 183 if !ast.IsNodeIDPattern(name) {