internal/links.go

49 lines · 1032 bytes

 1package internal
 2
 3import "strings"
 4
 5// LinkPriorities defines the order of priority for link domains
 6var LinkPriorities = []string{
 7	"sharepoint.com",
 8	"wixmp.com",
 9	"dropbox.com",
10	"wetransfer.com",
11	"gogoanime.com",
12	// Add more domains in order of priority
13}
14
15// PrioritizeLink takes an array of links and returns a single link based on priority
16func PrioritizeLink(links []string) string {
17	if len(links) == 0 {
18		return ""
19	}
20
21	// Create a map for quick lookup of priorities
22	priorityMap := make(map[string]int)
23	for i, p := range LinkPriorities {
24		priorityMap[p] = len(LinkPriorities) - i // Higher index means higher priority
25	}
26
27	highestPriority := -1
28	var bestLink string
29
30	for _, link := range links {
31		for domain, priority := range priorityMap {
32			if strings.Contains(link, domain) {
33				if priority > highestPriority {
34					highestPriority = priority
35					bestLink = link
36				}
37				break
38			}
39		}
40	}
41
42	// If no priority link found, return the first link
43	if bestLink == "" {
44		return links[0]
45	}
46
47	return bestLink
48}
49