Fix verify download link logic, remove the setting
This commit is contained in:
@@ -62,7 +62,9 @@ func MainApp(configPath string) {
|
|||||||
log.Named("unrestrict_client"),
|
log.Named("unrestrict_client"),
|
||||||
)
|
)
|
||||||
|
|
||||||
api := realdebrid.NewRealDebrid(apiClient, unrestrictClient, log.Named("realdebrid"))
|
downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetDownloadTimeoutSecs(), true, config, log.Named("download_client"))
|
||||||
|
|
||||||
|
api := realdebrid.NewRealDebrid(apiClient, unrestrictClient, downloadClient, log.Named("realdebrid"))
|
||||||
|
|
||||||
premium.MonitorPremiumStatus(api, zurglog)
|
premium.MonitorPremiumStatus(api, zurglog)
|
||||||
|
|
||||||
@@ -76,7 +78,6 @@ func MainApp(configPath string) {
|
|||||||
utils.EnsureDirExists("data") // Ensure the data directory exists
|
utils.EnsureDirExists("data") // Ensure the data directory exists
|
||||||
torrentMgr := torrent.NewTorrentManager(config, api, workerPool, log.Named("manager"))
|
torrentMgr := torrent.NewTorrentManager(config, api, workerPool, log.Named("manager"))
|
||||||
|
|
||||||
downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetDownloadTimeoutSecs(), true, config, log.Named("download_client"))
|
|
||||||
downloader := universal.NewDownloader(downloadClient)
|
downloader := universal.NewDownloader(downloadClient)
|
||||||
|
|
||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type ConfigInterface interface {
|
|||||||
EnableRetainRDTorrentName() bool
|
EnableRetainRDTorrentName() bool
|
||||||
ShouldIgnoreRenames() bool
|
ShouldIgnoreRenames() bool
|
||||||
ShouldServeFromRclone() bool
|
ShouldServeFromRclone() bool
|
||||||
ShouldVerifyDownloadLink() bool
|
|
||||||
ShouldForceIPv6() bool
|
ShouldForceIPv6() bool
|
||||||
GetApiTimeoutSecs() int
|
GetApiTimeoutSecs() int
|
||||||
GetDownloadTimeoutSecs() int
|
GetDownloadTimeoutSecs() int
|
||||||
@@ -157,10 +156,6 @@ func (z *ZurgConfig) ShouldServeFromRclone() bool {
|
|||||||
return z.ServeFromRclone
|
return z.ServeFromRclone
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZurgConfig) ShouldVerifyDownloadLink() bool {
|
|
||||||
return z.VerifyDownloadLink
|
|
||||||
}
|
|
||||||
|
|
||||||
func (z *ZurgConfig) ShouldForceIPv6() bool {
|
func (z *ZurgConfig) ShouldForceIPv6() bool {
|
||||||
return z.ForceIPv6
|
return z.ForceIPv6
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,10 +234,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
|||||||
<td>Serve From Rclone</td>
|
<td>Serve From Rclone</td>
|
||||||
<td>%t</td>
|
<td>%t</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>Verify Download Link</td>
|
|
||||||
<td>%t</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Force IPv6</td>
|
<td>Force IPv6</td>
|
||||||
<td>%t</td>
|
<td>%t</td>
|
||||||
@@ -318,7 +314,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
|||||||
response.Config.GetRetriesUntilFailed(),
|
response.Config.GetRetriesUntilFailed(),
|
||||||
response.Config.GetNetworkBufferSize(),
|
response.Config.GetNetworkBufferSize(),
|
||||||
response.Config.ShouldServeFromRclone(),
|
response.Config.ShouldServeFromRclone(),
|
||||||
response.Config.ShouldVerifyDownloadLink(),
|
|
||||||
response.Config.ShouldForceIPv6(),
|
response.Config.ShouldForceIPv6(),
|
||||||
response.Config.GetOnLibraryUpdate(),
|
response.Config.GetOnLibraryUpdate(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -80,13 +80,6 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cfg.ShouldServeFromRclone() {
|
if cfg.ShouldServeFromRclone() {
|
||||||
if cfg.ShouldVerifyDownloadLink() {
|
|
||||||
if !dl.client.CanFetchFirstByte(unrestrict.Download) {
|
|
||||||
log.Warnf("File %s is not available", fileName)
|
|
||||||
http.Error(resp, "File is not available", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
redirect(resp, req, unrestrict.Download, cfg)
|
redirect(resp, req, unrestrict.Download, cfg)
|
||||||
} else {
|
} else {
|
||||||
dl.streamFileToResponse(torrent, file, unrestrict, resp, req, torMgr, cfg, log)
|
dl.streamFileToResponse(torrent, file, unrestrict, resp, req, torMgr, cfg, log)
|
||||||
@@ -105,13 +98,6 @@ func (dl *Downloader) DownloadLink(fileName, link string, resp http.ResponseWrit
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if cfg.ShouldServeFromRclone() {
|
if cfg.ShouldServeFromRclone() {
|
||||||
if cfg.ShouldVerifyDownloadLink() {
|
|
||||||
if !dl.client.CanFetchFirstByte(unrestrict.Download) {
|
|
||||||
log.Warnf("File %s is not available", fileName)
|
|
||||||
http.Error(resp, "File is not available", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
redirect(resp, req, unrestrict.Download, cfg)
|
redirect(resp, req, unrestrict.Download, cfg)
|
||||||
} else {
|
} else {
|
||||||
dl.streamFileToResponse(nil, nil, unrestrict, resp, req, torMgr, cfg, log)
|
dl.streamFileToResponse(nil, nil, unrestrict, resp, req, torMgr, cfg, log)
|
||||||
|
|||||||
@@ -15,13 +15,15 @@ import (
|
|||||||
type RealDebrid struct {
|
type RealDebrid struct {
|
||||||
client *zurghttp.HTTPClient
|
client *zurghttp.HTTPClient
|
||||||
unrestrictClient *zurghttp.HTTPClient
|
unrestrictClient *zurghttp.HTTPClient
|
||||||
|
downloadClient *zurghttp.HTTPClient
|
||||||
log *logutil.Logger
|
log *logutil.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRealDebrid(client, unrestrictClient *zurghttp.HTTPClient, log *logutil.Logger) *RealDebrid {
|
func NewRealDebrid(client, unrestrictClient, downloadClient *zurghttp.HTTPClient, log *logutil.Logger) *RealDebrid {
|
||||||
return &RealDebrid{
|
return &RealDebrid{
|
||||||
client: client,
|
client: client,
|
||||||
unrestrictClient: unrestrictClient,
|
unrestrictClient: unrestrictClient,
|
||||||
|
downloadClient: downloadClient,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +103,7 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa
|
|||||||
return nil, fmt.Errorf("undecodable response: %v", err)
|
return nil, fmt.Errorf("undecodable response: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkFirstByte && !rd.client.CanFetchFirstByte(response.Download) {
|
if checkFirstByte && !rd.downloadClient.CanFetchFirstByte(response.Download) {
|
||||||
return nil, fmt.Errorf("can't fetch first byte")
|
return nil, fmt.Errorf("can't fetch first byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user