27 lines
555 B
Go
27 lines
555 B
Go
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)
|
|
}
|