Fixed linter errors in offline state and cache duration functions.
This commit is contained in:
@@ -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)
|
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())
|
initPath, _ = filepath.Abs(initTmp.Name())
|
||||||
|
|
||||||
segData := static.GetOfflineMediaSegment()
|
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)
|
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())
|
segmentPath, _ = filepath.Abs(segTmp.Name())
|
||||||
|
|
||||||
return initPath, segmentPath, nil
|
return initPath, segmentPath, nil
|
||||||
|
|||||||
+14
-9
@@ -218,20 +218,25 @@ func GetCacheDurationSecondsForPath(filePath string) int {
|
|||||||
if filename == "thumbnail.jpg" || filename == "preview.gif" {
|
if filename == "thumbnail.jpg" || filename == "preview.gif" {
|
||||||
// Thumbnails & preview gif re-generate during live
|
// Thumbnails & preview gif re-generate during live
|
||||||
return 20
|
return 20
|
||||||
} else if fileExtension == ".js" || fileExtension == ".css" {
|
}
|
||||||
// Cache javascript & CSS
|
|
||||||
return 60 * 60 * 24 * defaultDaysCached
|
noCacheExts := map[string]bool{".m3u8": true, ".html": true}
|
||||||
} else if fileExtension == ".m4s" || fileExtension == ".mp4" || fileExtension == ".woff2" {
|
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.
|
// Cache video segments as long as you want. They can't change.
|
||||||
// This matters most for local hosting of segments for recordings
|
// This matters most for local hosting of segments for recordings
|
||||||
// and not for live or 3rd party storage.
|
// and not for live or 3rd party storage.
|
||||||
return 31557600
|
return 31557600
|
||||||
} else if fileExtension == ".m3u8" {
|
case defaultCacheExts[fileExtension]:
|
||||||
return 0
|
|
||||||
} else if fileExtension == ".jpg" || fileExtension == ".png" || fileExtension == ".gif" || fileExtension == ".svg" {
|
|
||||||
return 60 * 60 * 24 * defaultDaysCached
|
return 60 * 60 * 24 * defaultDaysCached
|
||||||
} else if fileExtension == ".html" || filename == "/" || fileExtension == "" {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default cache length in seconds
|
// Default cache length in seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user