Fixed linter errors in offline state and cache duration functions.

This commit is contained in:
2026-04-02 09:21:55 -04:00
parent f0aa545d32
commit e0673b084b
2 changed files with 20 additions and 11 deletions
+6 -2
View File
@@ -112,7 +112,9 @@ func saveOfflineFMP4ToDisk() (initPath string, segmentPath string, err error) {
return "", "", fmt.Errorf("unable to write offline init segment to disk: %s", err)
}
initTmp.Close()
if err := initTmp.Close(); err != nil {
return "", "", fmt.Errorf("unable to close offline init segment: %s", err)
}
initPath, _ = filepath.Abs(initTmp.Name())
segData := static.GetOfflineMediaSegment()
@@ -125,7 +127,9 @@ func saveOfflineFMP4ToDisk() (initPath string, segmentPath string, err error) {
return "", "", fmt.Errorf("unable to write offline media segment to disk: %s", err)
}
segTmp.Close()
if err := segTmp.Close(); err != nil {
return "", "", fmt.Errorf("unable to close offline media segment: %s", err)
}
segmentPath, _ = filepath.Abs(segTmp.Name())
return initPath, segmentPath, nil
+14 -9
View File
@@ -218,20 +218,25 @@ func GetCacheDurationSecondsForPath(filePath string) int {
if filename == "thumbnail.jpg" || filename == "preview.gif" {
// Thumbnails & preview gif re-generate during live
return 20
} else if fileExtension == ".js" || fileExtension == ".css" {
// Cache javascript & CSS
return 60 * 60 * 24 * defaultDaysCached
} else if fileExtension == ".m4s" || fileExtension == ".mp4" || fileExtension == ".woff2" {
}
noCacheExts := map[string]bool{".m3u8": true, ".html": true}
longCacheExts := map[string]bool{".m4s": true, ".mp4": true, ".woff2": true}
defaultCacheExts := map[string]bool{
".js": true, ".css": true,
".jpg": true, ".png": true, ".gif": true, ".svg": true,
}
switch {
case noCacheExts[fileExtension] || filename == "/" || fileExtension == "":
return 0
case longCacheExts[fileExtension]:
// Cache video segments as long as you want. They can't change.
// This matters most for local hosting of segments for recordings
// and not for live or 3rd party storage.
return 31557600
} else if fileExtension == ".m3u8" {
return 0
} else if fileExtension == ".jpg" || fileExtension == ".png" || fileExtension == ".gif" || fileExtension == ".svg" {
case defaultCacheExts[fileExtension]:
return 60 * 60 * 24 * defaultDaysCached
} else if fileExtension == ".html" || filename == "/" || fileExtension == "" {
return 0
}
// Default cache length in seconds