Allow accessing same filename differently

This commit is contained in:
Ben Sarmiento
2023-10-17 10:50:10 +02:00
parent da2c53bf86
commit c5f365c8b4
8 changed files with 124 additions and 60 deletions

26
pkg/davextra/util.go Normal file
View File

@@ -0,0 +1,26 @@
package davextra
import (
"fmt"
"path/filepath"
"regexp"
"strings"
)
func GetLinkFragment(link string) string {
re := regexp.MustCompile(`\w+`)
matches := re.FindAllString(link, -1) // Returns all matches
var longestMatch string
for _, match := range matches {
if len(match) > len(longestMatch) {
longestMatch = match
}
}
return longestMatch[:4]
}
func InsertLinkFragment(filename, dupeID string) string {
ext := filepath.Ext(filename)
name := strings.TrimSuffix(filename, ext)
return fmt.Sprintf("%s DMM%s%s", name, dupeID, ext)
}