owncast/core/storageproviders/local.go
Gabe Kangas c6c6f0233d
Expanded linting + fix warnings (#1396)
* Expand the linters and types of warnings to improve consistency and safety

* Fail lint workflow if there are errors

* golint has been replaced by revive

* Hand-pick some of the default exclude list

* Ignore error when trying to delete preview gif

* Ignore linter warning opening playlist path

* Rename user field Id -> ID

* A bunch of renames to address linter warnings

* Rename ChatClient -> Client per linter suggestion best practice

* Rename ChatServer -> Server per linter suggestion best practice

* More linter warning fixes

* Add missing comments to all exported functions and properties
2021-09-12 00:18:15 -07:00

69 lines
1.9 KiB
Go

package storageproviders
import (
"path/filepath"
"time"
log "github.com/sirupsen/logrus"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/transcoder"
"github.com/owncast/owncast/utils"
)
// LocalStorage represents an instance of the local storage provider for HLS video.
type LocalStorage struct {
}
// Cleanup old public HLS content every N min from the webroot.
var _onlineCleanupTicker *time.Ticker
// Setup configures this storage provider.
func (s *LocalStorage) Setup() error {
// NOTE: This cleanup timer will have to be disabled to support recordings in the future
// as all HLS segments have to be publicly available on disk to keep a recording of them.
_onlineCleanupTicker = time.NewTicker(1 * time.Minute)
go func() {
for range _onlineCleanupTicker.C {
transcoder.CleanupOldContent(config.PublicHLSStoragePath)
}
}()
return nil
}
// SegmentWritten is called when a single segment of video is written.
func (s *LocalStorage) SegmentWritten(localFilePath string) {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Warnln(err)
}
}
// VariantPlaylistWritten is called when a variant hls playlist is written.
func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Errorln(err)
return
}
}
// MasterPlaylistWritten is called when the master hls playlist is written.
func (s *LocalStorage) MasterPlaylistWritten(localFilePath string) {
if _, err := s.Save(localFilePath, 0); err != nil {
log.Warnln(err)
}
}
// Save will save a local filepath using the storage provider.
func (s *LocalStorage) Save(filePath string, retryCount int) (string, error) {
newPath := ""
// This is a hack
if filePath == "hls/stream.m3u8" {
newPath = filepath.Join(config.PublicHLSStoragePath, filepath.Base(filePath))
} else {
newPath = filepath.Join(config.WebRoot, filePath)
}
err := utils.Copy(filePath, newPath)
return newPath, err
}