Bug fixes

This commit is contained in:
Ben Adrian Sarmiento
2024-06-28 20:18:30 +02:00
parent f8f31b3b67
commit 7cd8c9e5c9
4 changed files with 25 additions and 8 deletions

View File

@@ -31,9 +31,21 @@ func loadV1Config(content []byte, log *logutil.Logger) (*ZurgConfigV1, error) {
configV1.Token = utils.MaskToken(configV1.Token)
bufPassword := configV1.Password
configV1.Password = strings.Repeat("*", len(bufPassword))
// mask download tokens
bufDownloadTokens := configV1.DownloadTokens
maskedDownloadTokens := make([]string, len(configV1.DownloadTokens))
for i, token := range configV1.DownloadTokens {
maskedDownloadTokens[i] = utils.MaskToken(token)
}
configV1.DownloadTokens = maskedDownloadTokens
log.Debugf("Config dump: %+v", configV1)
// restore original values
configV1.Token = bufToken
configV1.Password = bufPassword
configV1.DownloadTokens = bufDownloadTokens
configV1.log = log
return &configV1, nil

View File

@@ -30,7 +30,7 @@ type RootResponse struct {
Infuse string `json:"infuse"`
Logs string `json:"logs"`
UserInfo *realdebrid.User `json:"user_info"`
APITrafficMB uint64 `json:"traffic_from_api"`
APITraffic uint64 `json:"traffic_from_api"`
RequestedMB uint64 `json:"requested_mb"`
ServedMB uint64 `json:"served_mb"`
LibrarySize int `json:"library_size"` // Number of torrents in the library
@@ -102,7 +102,7 @@ func (zr *Handlers) generateResponse(resp http.ResponseWriter, req *http.Request
Infuse: fmt.Sprintf("//%s/infuse/", req.Host),
Logs: fmt.Sprintf("//%s/logs/", req.Host),
UserInfo: userInfo,
APITrafficMB: bToMb(uint64(trafficFromAPI)),
APITraffic: uint64(trafficFromAPI),
RequestedMB: bToMb(zr.downloader.RequestedBytes.Load()),
ServedMB: bToMb(zr.downloader.TotalBytes.Load()),
LibrarySize: allTorrents.Count(),
@@ -199,10 +199,10 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
}
efficiency := response.ServedMB * 100 / denominator
if zr.trafficOnStartup.Load() > response.APITrafficMB {
if zr.trafficOnStartup.Load() > response.APITraffic {
// it cannot be bigger than traffic logged
// so it must be a reset back to 0
zr.trafficOnStartup.Store(response.APITrafficMB * 1024 * 1024)
zr.trafficOnStartup.Store(0)
}
out += fmt.Sprintf(`
@@ -252,8 +252,8 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
response.Sys,
response.NumGC,
response.PID,
response.APITrafficMB,
response.APITrafficMB-bToMb(zr.trafficOnStartup.Load()),
bToMb(response.APITraffic),
bToMb(response.APITraffic-zr.trafficOnStartup.Load()),
response.RequestedMB,
response.ServedMB,
efficiency,

View File

@@ -27,7 +27,7 @@ func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, r
}
file, ok := torrent.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") {
if !ok || file.State.Is("deleted_file") {
// log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
http.Error(w, "File not found", http.StatusNotFound)
return

View File

@@ -84,12 +84,17 @@ func (dl *Downloader) DownloadFile(
}
file, ok := torrent.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") {
if !ok || file.State.Is("deleted_file") {
log.Errorf("Cannot find file %s from path %s", fileName, req.URL.Path)
http.Error(resp, "File not found", http.StatusNotFound)
return
}
if file.State.Is("broken_file") {
http.Error(resp, "File is not available (being repaired)", http.StatusNotFound)
return
}
unrestrict, err := torMgr.UnrestrictFile(file)
if utils.AreAllTokensExpired(err) {
// log.Errorf("Your account has reached the bandwidth limit, please try again after 12AM CET")