Add more metadata

This commit is contained in:
Ben Sarmiento
2023-10-17 12:36:33 +02:00
parent c5f365c8b4
commit 44216343e2
9 changed files with 139 additions and 39 deletions

View File

@@ -60,14 +60,14 @@ func createSingleTorrentResponse(torrent realdebrid.Torrent, db *repo.Database)
path := filepath.Join(currentPath, filenameV2)
response := dav.File(
path,
int(unrestrict.Filesize),
torrent.Added, // Assuming you want to use the torrent added time here
unrestrict.Filesize,
convertDate(torrent.Added),
link,
)
responses = append(responses, response)
} else {
// This link is not cached yet
unrestrictFn := func() (realdebrid.UnrestrictResponse, error) {
unrestrictFn := func() (*realdebrid.UnrestrictResponse, error) {
return realdebrid.UnrestrictCheck(os.Getenv("RD_TOKEN"), link)
}
unrestrict := realdebrid.RetryUntilOk(unrestrictFn)
@@ -79,15 +79,14 @@ func createSingleTorrentResponse(torrent realdebrid.Torrent, db *repo.Database)
Host: "",
})
continue
} else {
db.Insert(torrent.Hash, torrent.Filename, *unrestrict)
}
db.Insert(torrent.Hash, torrent.Filename, *unrestrict)
filenameV2 := davextra.InsertLinkFragment(unrestrict.Filename, davextra.GetLinkFragment(unrestrict.Link))
path := filepath.Join(currentPath, filenameV2)
response := dav.File(
path,
int(unrestrict.Filesize),
torrent.Added,
unrestrict.Filesize,
convertDate(torrent.Added),
link,
)
responses = append(responses, response)

View File

@@ -116,7 +116,7 @@ func Router(mux *http.ServeMux, db *repo.Database) {
return
}
unrestrictFn := func() (realdebrid.UnrestrictResponse, error) {
unrestrictFn := func() (*realdebrid.UnrestrictResponse, error) {
return realdebrid.UnrestrictLink(os.Getenv("RD_TOKEN"), unrestrict.Link)
}
resp := realdebrid.RetryUntilOk(unrestrictFn)

15
internal/dav/util.go Normal file
View File

@@ -0,0 +1,15 @@
package dav
import (
"fmt"
"time"
)
func convertDate(input string) string {
t, err := time.Parse(time.RFC3339, input)
if err != nil {
fmt.Println("Error:", err)
return ""
}
return t.Format("Mon, 02 Jan 2006 15:04:05 GMT")
}