Allow accessing same filename differently
This commit is contained in:
26
pkg/davextra/util.go
Normal file
26
pkg/davextra/util.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user