Consider file case when doing filename comparisons

This commit is contained in:
Ben Sarmiento
2024-01-27 11:54:28 +01:00
parent 803240b2eb
commit e01622064d
3 changed files with 12 additions and 14 deletions

View File

@@ -64,18 +64,15 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
http.Error(resp, "File is not available", http.StatusNotFound)
return
} else {
unrestrictFilename := strings.TrimPrefix(unrestrict.Filename, "/")
if !strings.Contains(fileName, unrestrictFilename) {
if unrestrict.Filesize != file.Bytes {
// this is possible if there's only 1 streamable file in the torrent
// and then suddenly it's a rar file
actualExt := filepath.Ext(unrestrictFilename)
expectedExt := filepath.Ext(fileName)
actualExt := strings.ToLower(filepath.Ext(unrestrict.Filename))
expectedExt := strings.ToLower(filepath.Ext(fileName))
if actualExt != expectedExt && unrestrict.Streamable != 1 {
log.Warnf("File was changed and is not streamable: %s and %s (link=%s)", fileName, unrestrict.Filename, unrestrict.Link)
http.Error(resp, "File is not available", http.StatusNotFound)
return
} else {
log.Warnf("Filename mismatch: %s and %s", fileName, unrestrict.Filename)
log.Warnf("File mismatch: %s and %s", fileName, unrestrict.Filename)
}
}
if cfg.ShouldServeFromRclone() {
@@ -109,15 +106,15 @@ func (dl *Downloader) DownloadLink(fileName, link string, resp http.ResponseWrit
http.Error(resp, "File is not available", http.StatusNotFound)
return
} else {
if unrestrict.Filename != fileName {
lFilename := strings.ToLower(fileName)
unrestrictFilename := strings.ToLower(strings.TrimPrefix(unrestrict.Filename, "/"))
if strings.Contains(lFilename, unrestrictFilename) {
// this is possible if there's only 1 streamable file in the torrent
// and then suddenly it's a rar file
actualExt := filepath.Ext(unrestrict.Filename)
expectedExt := filepath.Ext(fileName)
actualExt := filepath.Ext(unrestrictFilename)
expectedExt := filepath.Ext(lFilename)
if actualExt != expectedExt && unrestrict.Streamable != 1 {
log.Warnf("File was changed and is not streamable: %s and %s (link=%s)", fileName, unrestrict.Filename, unrestrict.Link)
http.Error(resp, "File is not available", http.StatusNotFound)
return
} else {
log.Warnf("Filename mismatch: %s and %s", fileName, unrestrict.Filename)
}