public const
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Arnas Udovic 2023-06-27 13:01:05 +03:00
parent b96d4c5452
commit b1501ba23d

12
tree.go
View file

@ -37,7 +37,7 @@ type Tree struct {
var readableFormats = []string{".md"} var readableFormats = []string{".md"}
const attachmentDirName = "__a" const AttachmentDirName = "__a"
func (t Tree) FileById(id string) (File, error) { func (t Tree) FileById(id string) (File, error) {
for _, f := range t.Files { for _, f := range t.Files {
@ -188,7 +188,7 @@ func moveAttachments(dir string) (map[string]string, error) {
} }
var clearDir = strings.TrimPrefix(dir, "./") var clearDir = strings.TrimPrefix(dir, "./")
if info.Mode().IsRegular() && !slices.Contains(readableFormats, path.Ext(fullPath)) && !strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, attachmentDirName)) { if info.Mode().IsRegular() && !slices.Contains(readableFormats, path.Ext(fullPath)) && !strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, AttachmentDirName)) {
f, err := os.Open(fullPath) f, err := os.Open(fullPath)
if err != nil { if err != nil {
return err return err
@ -200,10 +200,10 @@ func moveAttachments(dir string) (map[string]string, error) {
return err return err
} }
_ = os.Mkdir(fmt.Sprintf("%s/%s", dir, attachmentDirName), 0755) _ = os.Mkdir(fmt.Sprintf("%s/%s", dir, AttachmentDirName), 0755)
attachmentRegistry[fullPath] = fmt.Sprintf("%s/%x%s", attachmentDirName, h.Sum(nil), path.Ext(fullPath)) attachmentRegistry[fullPath] = fmt.Sprintf("%s/%x%s", AttachmentDirName, h.Sum(nil), path.Ext(fullPath))
newPath := fmt.Sprintf("%s/%s/%x%s", dir, attachmentDirName, h.Sum(nil), path.Ext(fullPath)) newPath := fmt.Sprintf("%s/%s/%x%s", dir, AttachmentDirName, h.Sum(nil), path.Ext(fullPath))
err = os.Rename(fullPath, newPath) err = os.Rename(fullPath, newPath)
if err != nil { if err != nil {
return err return err
@ -434,7 +434,7 @@ func readPath(dirPath string, category []string, meta []string) (Tree, error) {
for _, file := range files { for _, file := range files {
fullPath := path.Join(dirPath, file.Name()) fullPath := path.Join(dirPath, file.Name())
if file.IsDir() { if file.IsDir() {
if strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, attachmentDirName)) { if strings.HasPrefix(fullPath, fmt.Sprintf("%s/%s", clearDir, AttachmentDirName)) {
continue continue
} }