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") {
|
if file == nil || !strings.HasPrefix(file.Link, "http") {
|
||||||
continue
|
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>")
|
fmt.Fprint(w, "</d:multistatus>")
|
||||||
|
|||||||
@@ -365,6 +365,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
selectedFiles = append(selectedFiles, &File{
|
selectedFiles = append(selectedFiles, &File{
|
||||||
File: file,
|
File: file,
|
||||||
Added: info.Added,
|
Added: info.Added,
|
||||||
|
Ended: info.Ended,
|
||||||
Link: "", // no link yet
|
Link: "", // no link yet
|
||||||
ZurgFS: hashStringToFh(file.Path + info.Hash),
|
ZurgFS: hashStringToFh(file.Path + info.Hash),
|
||||||
})
|
})
|
||||||
@@ -495,6 +496,7 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
|||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
if result.Response.Streamable == 1 {
|
if result.Response.Streamable == 1 {
|
||||||
|
now := time.Now().Format(time.RFC3339)
|
||||||
selectedFiles = append(selectedFiles, &File{
|
selectedFiles = append(selectedFiles, &File{
|
||||||
File: realdebrid.File{
|
File: realdebrid.File{
|
||||||
ID: math.MaxInt32,
|
ID: math.MaxInt32,
|
||||||
@@ -502,7 +504,8 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
|||||||
Bytes: result.Response.Filesize,
|
Bytes: result.Response.Filesize,
|
||||||
Selected: 1,
|
Selected: 1,
|
||||||
},
|
},
|
||||||
Added: time.Now().Format(time.RFC3339),
|
Added: now,
|
||||||
|
Ended: now,
|
||||||
Link: result.Response.Link,
|
Link: result.Response.Link,
|
||||||
ZurgFS: hashStringToFh(result.Response.Filename),
|
ZurgFS: hashStringToFh(result.Response.Filename),
|
||||||
})
|
})
|
||||||
@@ -593,6 +596,7 @@ func (t *TorrentManager) Repair(accessKey string) {
|
|||||||
fileCopy := &File{
|
fileCopy := &File{
|
||||||
File: file.File,
|
File: file.File,
|
||||||
Added: file.Added,
|
Added: file.Added,
|
||||||
|
Ended: file.Ended,
|
||||||
Link: file.Link,
|
Link: file.Link,
|
||||||
ZurgFS: file.ZurgFS,
|
ZurgFS: file.ZurgFS,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ func (t *Torrent) InProgress() bool {
|
|||||||
type File struct {
|
type File struct {
|
||||||
realdebrid.File
|
realdebrid.File
|
||||||
Added string
|
Added string
|
||||||
|
Ended string
|
||||||
Link string
|
Link string
|
||||||
ZurgFS uint64
|
ZurgFS uint64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ import (
|
|||||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
"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]) {
|
func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, cache *expirable.LRU[string, string]) {
|
||||||
log := logutil.NewLogger().Named("head")
|
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 {
|
if data, exists := cache.Get("head:" + requestPath); exists {
|
||||||
splits := strings.Split(data, " ")
|
splits := strings.Split(data, SPLIT_TOKEN)
|
||||||
contentType := splits[0]
|
contentType := splits[0]
|
||||||
contentLength := splits[1]
|
contentLength := splits[1]
|
||||||
|
lastModified := splits[2]
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
w.Header().Set("Content-Length", contentLength)
|
w.Header().Set("Content-Length", contentLength)
|
||||||
|
w.Header().Set("Last-Modified", lastModified)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -70,9 +76,12 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
|
|||||||
}
|
}
|
||||||
contentType := getContentMimeType(filename)
|
contentType := getContentMimeType(filename)
|
||||||
contentLength := fmt.Sprintf("%d", file.Bytes)
|
contentLength := fmt.Sprintf("%d", file.Bytes)
|
||||||
|
lastModified := file.Ended
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
w.Header().Set("Content-Length", contentLength)
|
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)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type TorrentInfo struct {
|
|||||||
Progress int `json:"-"`
|
Progress int `json:"-"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Added string `json:"added"`
|
Added string `json:"added"`
|
||||||
|
Ended string `json:"ended"`
|
||||||
Bytes int64 `json:"bytes"`
|
Bytes int64 `json:"bytes"`
|
||||||
Links []string `json:"links"`
|
Links []string `json:"links"`
|
||||||
OriginalName string `json:"original_filename"` // from info
|
OriginalName string `json:"original_filename"` // from info
|
||||||
|
|||||||
Reference in New Issue
Block a user