Consider file case when doing filename comparisons
This commit is contained in:
@@ -73,7 +73,8 @@ func CheckVersionFile(w http.ResponseWriter, req *http.Request, torMgr *torrent.
|
||||
}
|
||||
|
||||
func getContentMimeType(filePath string) string {
|
||||
switch filepath.Ext(filePath) {
|
||||
fileExt := strings.ToLower(filepath.Ext(filePath))
|
||||
switch fileExt {
|
||||
case ".mkv":
|
||||
return "video/x-matroska"
|
||||
case ".mp4":
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user