mirror of
https://github.com/kemko/icecast-ripper.git
synced 2026-01-01 15:55:42 +03:00
renamed database to filestore
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
.github
|
.github
|
||||||
bin
|
bin
|
||||||
.idea
|
.idea
|
||||||
|
/icecast-ripper
|
||||||
|
|||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
records
|
/records
|
||||||
bin
|
/bin
|
||||||
|
/icecast-ripper
|
||||||
|
|
||||||
# If you prefer the allow list template instead of the deny list, see community template:
|
# If you prefer the allow list template instead of the deny list, see community template:
|
||||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kemko/icecast-ripper/internal/config"
|
"github.com/kemko/icecast-ripper/internal/config"
|
||||||
"github.com/kemko/icecast-ripper/internal/database"
|
"github.com/kemko/icecast-ripper/internal/filestore"
|
||||||
"github.com/kemko/icecast-ripper/internal/logger"
|
"github.com/kemko/icecast-ripper/internal/logger"
|
||||||
"github.com/kemko/icecast-ripper/internal/recorder"
|
"github.com/kemko/icecast-ripper/internal/recorder"
|
||||||
"github.com/kemko/icecast-ripper/internal/rss"
|
"github.com/kemko/icecast-ripper/internal/rss"
|
||||||
@@ -51,7 +51,7 @@ func main() {
|
|||||||
storePath = changeExtension(cfg.DatabasePath, ".json")
|
storePath = changeExtension(cfg.DatabasePath, ".json")
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStore, err := database.InitDB(storePath)
|
fileStore, err := filestore.Init(storePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to initialize file store", "error", err)
|
slog.Error("Failed to initialize file store", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package database
|
// Package filestore provides functionality for storing and retrieving metadata about recorded files
|
||||||
|
package filestore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -21,18 +22,18 @@ type RecordedFile struct {
|
|||||||
RecordedAt time.Time `json:"recordedAt"`
|
RecordedAt time.Time `json:"recordedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileStore represents an in-memory store with optional file persistence
|
// Store represents an in-memory store with optional file persistence
|
||||||
type FileStore struct {
|
type Store struct {
|
||||||
files map[string]*RecordedFile
|
files map[string]*RecordedFile
|
||||||
storePath string
|
storePath string
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitDB initializes a new FileStore
|
// Init initializes a new Store
|
||||||
func InitDB(dataSourceName string) (*FileStore, error) {
|
func Init(dataSourceName string) (*Store, error) {
|
||||||
slog.Info("Initializing file store", "path", dataSourceName)
|
slog.Info("Initializing file store", "path", dataSourceName)
|
||||||
|
|
||||||
fs := &FileStore{
|
fs := &Store{
|
||||||
files: make(map[string]*RecordedFile),
|
files: make(map[string]*RecordedFile),
|
||||||
storePath: dataSourceName,
|
storePath: dataSourceName,
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,7 @@ func InitDB(dataSourceName string) (*FileStore, error) {
|
|||||||
return fs, nil
|
return fs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileStore) loadFromFile() error {
|
func (fs *Store) loadFromFile() error {
|
||||||
fs.mu.Lock()
|
fs.mu.Lock()
|
||||||
defer fs.mu.Unlock()
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ func (fs *FileStore) loadFromFile() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileStore) saveToFile() error {
|
func (fs *Store) saveToFile() error {
|
||||||
fs.mu.RLock()
|
fs.mu.RLock()
|
||||||
defer fs.mu.RUnlock()
|
defer fs.mu.RUnlock()
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ func (fs *FileStore) saveToFile() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRecordedFile adds a file to the store
|
// AddRecordedFile adds a file to the store
|
||||||
func (fs *FileStore) AddRecordedFile(filename, hash string, fileSize int64, duration time.Duration, recordedAt time.Time) (int64, error) {
|
func (fs *Store) AddRecordedFile(filename, hash string, fileSize int64, duration time.Duration, recordedAt time.Time) (int64, error) {
|
||||||
fs.mu.Lock()
|
fs.mu.Lock()
|
||||||
defer fs.mu.Unlock()
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ func (fs *FileStore) AddRecordedFile(filename, hash string, fileSize int64, dura
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRecordedFiles retrieves all recorded files, ordered by recording date descending
|
// GetRecordedFiles retrieves all recorded files, ordered by recording date descending
|
||||||
func (fs *FileStore) GetRecordedFiles(limit int) ([]RecordedFile, error) {
|
func (fs *Store) GetRecordedFiles(limit int) ([]RecordedFile, error) {
|
||||||
fs.mu.RLock()
|
fs.mu.RLock()
|
||||||
defer fs.mu.RUnlock()
|
defer fs.mu.RUnlock()
|
||||||
|
|
||||||
@@ -149,6 +150,6 @@ func (fs *FileStore) GetRecordedFiles(limit int) ([]RecordedFile, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close ensures all data is persisted
|
// Close ensures all data is persisted
|
||||||
func (fs *FileStore) Close() error {
|
func (fs *Store) Close() error {
|
||||||
return fs.saveToFile()
|
return fs.saveToFile()
|
||||||
}
|
}
|
||||||
@@ -13,14 +13,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kemko/icecast-ripper/internal/database"
|
"github.com/kemko/icecast-ripper/internal/filestore"
|
||||||
"github.com/kemko/icecast-ripper/internal/hash"
|
"github.com/kemko/icecast-ripper/internal/hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Recorder struct {
|
type Recorder struct {
|
||||||
tempPath string
|
tempPath string
|
||||||
recordingsPath string
|
recordingsPath string
|
||||||
db *database.FileStore
|
db *filestore.Store
|
||||||
client *http.Client
|
client *http.Client
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
isRecording bool
|
isRecording bool
|
||||||
@@ -28,7 +28,7 @@ type Recorder struct {
|
|||||||
streamName string
|
streamName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(tempPath, recordingsPath string, db *database.FileStore, streamName string) (*Recorder, error) {
|
func New(tempPath, recordingsPath string, db *filestore.Store, streamName string) (*Recorder, error) {
|
||||||
for _, dir := range []string{tempPath, recordingsPath} {
|
for _, dir := range []string{tempPath, recordingsPath} {
|
||||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create directory %s: %w", dir, err)
|
return nil, fmt.Errorf("failed to create directory %s: %w", dir, err)
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/feeds"
|
"github.com/gorilla/feeds"
|
||||||
"github.com/kemko/icecast-ripper/internal/config"
|
"github.com/kemko/icecast-ripper/internal/config"
|
||||||
"github.com/kemko/icecast-ripper/internal/database"
|
"github.com/kemko/icecast-ripper/internal/filestore"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generator creates RSS feeds
|
// Generator creates RSS feeds
|
||||||
type Generator struct {
|
type Generator struct {
|
||||||
fileStore *database.FileStore
|
fileStore *filestore.Store
|
||||||
feedBaseURL string
|
feedBaseURL string
|
||||||
recordingsPath string
|
recordingsPath string
|
||||||
feedTitle string
|
feedTitle string
|
||||||
@@ -22,7 +22,7 @@ type Generator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new RSS Generator instance
|
// New creates a new RSS Generator instance
|
||||||
func New(fileStore *database.FileStore, cfg *config.Config, title, description string) *Generator {
|
func New(fileStore *filestore.Store, cfg *config.Config, title, description string) *Generator {
|
||||||
baseURL := cfg.RSSFeedURL
|
baseURL := cfg.RSSFeedURL
|
||||||
if baseURL == "" {
|
if baseURL == "" {
|
||||||
slog.Warn("RSS_FEED_URL not set, using default")
|
slog.Warn("RSS_FEED_URL not set, using default")
|
||||||
|
|||||||
Reference in New Issue
Block a user