fix checksum issue
This commit is contained in:
@@ -50,7 +50,7 @@ func Setup(app *aero.Application, c config.ConfigInterface, t *torrent.TorrentMa
|
|||||||
torrentsInDirectory := t.GetByDirectory(directory)
|
torrentsInDirectory := t.GetByDirectory(directory)
|
||||||
resp, err := createMultiTorrentResponse(fmt.Sprintf("/%s", directory), torrentsInDirectory)
|
resp, err := createMultiTorrentResponse(fmt.Sprintf("/%s", directory), torrentsInDirectory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot read directory (%s): %v\n", directory, err.Error())
|
log.Printf("Cannot read directory (%s): %v\n", directory, err)
|
||||||
return ctx.Error(http.StatusInternalServerError, "Cannot read directory")
|
return ctx.Error(http.StatusInternalServerError, "Cannot read directory")
|
||||||
}
|
}
|
||||||
return xmlResponse(ctx, *resp)
|
return xmlResponse(ctx, *resp)
|
||||||
@@ -62,7 +62,7 @@ func Setup(app *aero.Application, c config.ConfigInterface, t *torrent.TorrentMa
|
|||||||
sameNameTorrents := findAllTorrentsWithName(t, directory, torrentName)
|
sameNameTorrents := findAllTorrentsWithName(t, directory, torrentName)
|
||||||
resp, err := createSingleTorrentResponse(fmt.Sprintf("/%s", directory), sameNameTorrents, t)
|
resp, err := createSingleTorrentResponse(fmt.Sprintf("/%s", directory), sameNameTorrents, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot read directory (%s): %v\n", directory, err.Error())
|
log.Printf("Cannot read directory (%s): %v\n", directory, err)
|
||||||
return ctx.Error(http.StatusInternalServerError, "Cannot read directory")
|
return ctx.Error(http.StatusInternalServerError, "Cannot read directory")
|
||||||
}
|
}
|
||||||
return xmlResponse(ctx, *resp)
|
return xmlResponse(ctx, *resp)
|
||||||
@@ -119,7 +119,7 @@ func Setup(app *aero.Application, c config.ConfigInterface, t *torrent.TorrentMa
|
|||||||
func xmlResponse(ctx aero.Context, resp dav.MultiStatus) error {
|
func xmlResponse(ctx aero.Context, resp dav.MultiStatus) error {
|
||||||
output, err := xml.MarshalIndent(resp, "", " ")
|
output, err := xml.MarshalIndent(resp, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot marshal xml: %v\n", err.Error())
|
log.Printf("Cannot marshal xml: %v\n", err)
|
||||||
return ctx.Error(http.StatusInternalServerError, "Cannot read directory")
|
return ctx.Error(http.StatusInternalServerError, "Cannot read directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot marshal xml: %v\n", err.Error())
|
log.Printf("Cannot marshal xml: %v\n", err)
|
||||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func handleListOfTorrents(requestPath string, w http.ResponseWriter, r *http.Req
|
|||||||
torrents := t.GetByDirectory(basePath)
|
torrents := t.GetByDirectory(basePath)
|
||||||
resp, err := createMultiTorrentResponse(fmt.Sprintf("/%s", basePath), torrents)
|
resp, err := createMultiTorrentResponse(fmt.Sprintf("/%s", basePath), torrents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot read directory (%s): %v\n", basePath, err.Error())
|
log.Printf("Cannot read directory (%s): %v\n", basePath, err)
|
||||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ func handleSingleTorrent(requestPath string, w http.ResponseWriter, r *http.Requ
|
|||||||
var resp *dav.MultiStatus
|
var resp *dav.MultiStatus
|
||||||
resp, err := createSingleTorrentResponse(fmt.Sprintf("/%s", directory), sameNameTorrents, t)
|
resp, err := createSingleTorrentResponse(fmt.Sprintf("/%s", directory), sameNameTorrents, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot read directory (%s): %v\n", requestPath, err.Error())
|
log.Printf("Cannot read directory (%s): %v\n", requestPath, err)
|
||||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,10 +73,11 @@ func NewTorrentManager(config config.ConfigInterface) *TorrentManager {
|
|||||||
func (t *TorrentManager) getChecksum() string {
|
func (t *TorrentManager) getChecksum() string {
|
||||||
torrents, totalCount, err := realdebrid.GetTorrents(t.token, 1)
|
torrents, totalCount, err := realdebrid.GetTorrents(t.token, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot get torrents: %v\n", err.Error())
|
log.Printf("Cannot get torrents: %v\n", err)
|
||||||
return t.checksum
|
return t.checksum
|
||||||
}
|
}
|
||||||
if len(torrents) == 0 {
|
if len(torrents) == 0 {
|
||||||
|
log.Println("Huh, no torrents returned")
|
||||||
return t.checksum
|
return t.checksum
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%d-%s", totalCount, torrents[0].ID)
|
return fmt.Sprintf("%d-%s", totalCount, torrents[0].ID)
|
||||||
@@ -87,7 +88,7 @@ func (t *TorrentManager) getAll() []Torrent {
|
|||||||
|
|
||||||
torrents, totalCount, err := realdebrid.GetTorrents(t.token, 0)
|
torrents, totalCount, err := realdebrid.GetTorrents(t.token, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot get torrents: %v\n", err.Error())
|
log.Printf("Cannot get torrents: %v\n", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
t.checksum = fmt.Sprintf("%d-%s", totalCount, torrents[0].ID)
|
t.checksum = fmt.Sprintf("%d-%s", totalCount, torrents[0].ID)
|
||||||
@@ -148,10 +149,10 @@ func (t *TorrentManager) RefreshInfo(torrentID string) {
|
|||||||
}
|
}
|
||||||
err = os.Remove(filePath)
|
err = os.Remove(filePath)
|
||||||
if err != nil && !os.IsNotExist(err) { // File doesn't exist or other error
|
if err != nil && !os.IsNotExist(err) { // File doesn't exist or other error
|
||||||
log.Printf("Cannot remove file: %v\n", err.Error())
|
log.Printf("Cannot remove file: %v\n", err)
|
||||||
}
|
}
|
||||||
} else if !os.IsNotExist(err) { // Error other than file not existing
|
} else if !os.IsNotExist(err) { // Error other than file not existing
|
||||||
log.Printf("Error checking file info: %v\n", err.Error())
|
log.Printf("Error checking file info: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
info := t.getInfo(torrentID)
|
info := t.getInfo(torrentID)
|
||||||
@@ -170,7 +171,7 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent {
|
|||||||
log.Println("Getting info for", torrentID)
|
log.Println("Getting info for", torrentID)
|
||||||
info, err := realdebrid.GetTorrentInfo(t.token, torrentID)
|
info, err := realdebrid.GetTorrentInfo(t.token, torrentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot get info: %v\n", err.Error())
|
log.Printf("Cannot get info: %v\n", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var selectedFiles []File
|
var selectedFiles []File
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ func GetTorrents(accessToken string, customLimit int) ([]Torrent, int, error) {
|
|||||||
allTorrents = append(allTorrents, torrents...)
|
allTorrents = append(allTorrents, torrents...)
|
||||||
|
|
||||||
totalCountHeader := resp.Header.Get("x-total-count")
|
totalCountHeader := resp.Header.Get("x-total-count")
|
||||||
totalCount, err := strconv.Atoi(totalCountHeader)
|
totalCount, err = strconv.Atoi(totalCountHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user