Proper caching

This commit is contained in:
Ben Sarmiento
2023-10-18 12:36:34 +02:00
parent bd72dc4540
commit acee02377e
9 changed files with 126 additions and 65 deletions

View File

@@ -2,11 +2,13 @@ package davextra
import (
"fmt"
"net/url"
"path/filepath"
"regexp"
"strings"
)
// GetLinkFragment returns the longest alphanumeric string from a link
func GetLinkFragment(link string) string {
re := regexp.MustCompile(`\w+`)
matches := re.FindAllString(link, -1) // Returns all matches
@@ -19,8 +21,32 @@ func GetLinkFragment(link string) string {
return longestMatch[:4]
}
// InsertLinkFragment inserts the link ID into a filename
// returns the new filename
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)
}
// ExtractLinkFragment extracts the link ID from a filename
// returns the original filename and the link ID
func ExtractLinkFragment(filename string) (string, string) {
filenameV2, err := url.PathUnescape(filename)
if err != nil {
filenameV2 = filename
}
ext := filepath.Ext(filenameV2)
name := strings.TrimSuffix(filenameV2, ext)
r := regexp.MustCompile(`\sDMM(\w+)`)
matches := r.FindStringSubmatch(name)
if len(matches) < 2 {
// No ID found
return filenameV2, ""
}
// Remove ID from filename
originalName := strings.Replace(name, matches[0], "", 1)
return originalName + ext, matches[1]
}

View File

@@ -88,7 +88,7 @@ func GetTorrents(accessToken string) ([]Torrent, error) {
baseURL := "https://api.real-debrid.com/rest/1.0/torrents"
var allTorrents []Torrent
page := 1
limit := 2500
limit := 100
for {
params := url.Values{}
@@ -124,7 +124,7 @@ func GetTorrents(accessToken string) ([]Torrent, error) {
allTorrents = append(allTorrents, torrents...)
totalCountHeader := resp.Header.Get("x-total-count")
totalCountHeader := "100" // resp.Header.Get("x-total-count")
totalCount, err := strconv.Atoi(totalCountHeader)
if err != nil {
break