Set time by ended or added correctly
This commit is contained in:
@@ -110,7 +110,7 @@ func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.Torre
|
||||
if file == nil || !strings.HasPrefix(file.Link, "http") {
|
||||
continue
|
||||
}
|
||||
fmt.Fprint(w, dav.File(filepath.Join(requestPath, filename), file.Bytes, tor.LatestAdded))
|
||||
fmt.Fprint(w, dav.File(filepath.Join(requestPath, filename), file.Bytes, file.Ended))
|
||||
}
|
||||
|
||||
fmt.Fprint(w, "</d:multistatus>")
|
||||
|
||||
@@ -365,6 +365,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
selectedFiles = append(selectedFiles, &File{
|
||||
File: file,
|
||||
Added: info.Added,
|
||||
Ended: info.Ended,
|
||||
Link: "", // no link yet
|
||||
ZurgFS: hashStringToFh(file.Path + info.Hash),
|
||||
})
|
||||
@@ -495,6 +496,7 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
||||
}
|
||||
if !found {
|
||||
if result.Response.Streamable == 1 {
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
selectedFiles = append(selectedFiles, &File{
|
||||
File: realdebrid.File{
|
||||
ID: math.MaxInt32,
|
||||
@@ -502,7 +504,8 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
||||
Bytes: result.Response.Filesize,
|
||||
Selected: 1,
|
||||
},
|
||||
Added: time.Now().Format(time.RFC3339),
|
||||
Added: now,
|
||||
Ended: now,
|
||||
Link: result.Response.Link,
|
||||
ZurgFS: hashStringToFh(result.Response.Filename),
|
||||
})
|
||||
@@ -593,6 +596,7 @@ func (t *TorrentManager) Repair(accessKey string) {
|
||||
fileCopy := &File{
|
||||
File: file.File,
|
||||
Added: file.Added,
|
||||
Ended: file.Ended,
|
||||
Link: file.Link,
|
||||
ZurgFS: file.ZurgFS,
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ func (t *Torrent) InProgress() bool {
|
||||
type File struct {
|
||||
realdebrid.File
|
||||
Added string
|
||||
Ended string
|
||||
Link string
|
||||
ZurgFS uint64
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ import (
|
||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||
)
|
||||
|
||||
const (
|
||||
SPLIT_TOKEN = "$"
|
||||
)
|
||||
|
||||
func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, cache *expirable.LRU[string, string]) {
|
||||
log := logutil.NewLogger().Named("head")
|
||||
|
||||
@@ -30,11 +34,13 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
|
||||
}
|
||||
|
||||
if data, exists := cache.Get("head:" + requestPath); exists {
|
||||
splits := strings.Split(data, " ")
|
||||
splits := strings.Split(data, SPLIT_TOKEN)
|
||||
contentType := splits[0]
|
||||
contentLength := splits[1]
|
||||
lastModified := splits[2]
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Length", contentLength)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
@@ -70,9 +76,12 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
|
||||
}
|
||||
contentType := getContentMimeType(filename)
|
||||
contentLength := fmt.Sprintf("%d", file.Bytes)
|
||||
lastModified := file.Ended
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Length", contentLength)
|
||||
cache.Add("head:"+requestPath, contentType+" "+contentLength)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
cacheVal := strings.Join([]string{contentType, contentLength, lastModified}, SPLIT_TOKEN)
|
||||
cache.Add("head:"+requestPath, cacheVal)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user