renamed database to filestore

This commit is contained in:
Dmitrii Andreev
2025-04-07 12:47:36 +03:00
parent a3038b43ab
commit a1c189c885
6 changed files with 24 additions and 21 deletions

View File

@@ -1,3 +1,4 @@
.github
bin
.idea
/icecast-ripper

5
.gitignore vendored
View File

@@ -1,5 +1,6 @@
records
bin
/records
/bin
/icecast-ripper
# 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

View File

@@ -12,7 +12,7 @@ import (
"time"
"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/recorder"
"github.com/kemko/icecast-ripper/internal/rss"
@@ -51,7 +51,7 @@ func main() {
storePath = changeExtension(cfg.DatabasePath, ".json")
}
fileStore, err := database.InitDB(storePath)
fileStore, err := filestore.Init(storePath)
if err != nil {
slog.Error("Failed to initialize file store", "error", err)
os.Exit(1)

View File

@@ -1,4 +1,5 @@
package database
// Package filestore provides functionality for storing and retrieving metadata about recorded files
package filestore
import (
"encoding/json"
@@ -21,18 +22,18 @@ type RecordedFile struct {
RecordedAt time.Time `json:"recordedAt"`
}
// FileStore represents an in-memory store with optional file persistence
type FileStore struct {
// Store represents an in-memory store with optional file persistence
type Store struct {
files map[string]*RecordedFile
storePath string
mu sync.RWMutex
}
// InitDB initializes a new FileStore
func InitDB(dataSourceName string) (*FileStore, error) {
// Init initializes a new Store
func Init(dataSourceName string) (*Store, error) {
slog.Info("Initializing file store", "path", dataSourceName)
fs := &FileStore{
fs := &Store{
files: make(map[string]*RecordedFile),
storePath: dataSourceName,
}
@@ -46,7 +47,7 @@ func InitDB(dataSourceName string) (*FileStore, error) {
return fs, nil
}
func (fs *FileStore) loadFromFile() error {
func (fs *Store) loadFromFile() error {
fs.mu.Lock()
defer fs.mu.Unlock()
@@ -73,7 +74,7 @@ func (fs *FileStore) loadFromFile() error {
return nil
}
func (fs *FileStore) saveToFile() error {
func (fs *Store) saveToFile() error {
fs.mu.RLock()
defer fs.mu.RUnlock()
@@ -105,7 +106,7 @@ func (fs *FileStore) saveToFile() error {
}
// 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()
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
func (fs *FileStore) GetRecordedFiles(limit int) ([]RecordedFile, error) {
func (fs *Store) GetRecordedFiles(limit int) ([]RecordedFile, error) {
fs.mu.RLock()
defer fs.mu.RUnlock()
@@ -149,6 +150,6 @@ func (fs *FileStore) GetRecordedFiles(limit int) ([]RecordedFile, error) {
}
// Close ensures all data is persisted
func (fs *FileStore) Close() error {
func (fs *Store) Close() error {
return fs.saveToFile()
}

View File

@@ -13,14 +13,14 @@ import (
"sync"
"time"
"github.com/kemko/icecast-ripper/internal/database"
"github.com/kemko/icecast-ripper/internal/filestore"
"github.com/kemko/icecast-ripper/internal/hash"
)
type Recorder struct {
tempPath string
recordingsPath string
db *database.FileStore
db *filestore.Store
client *http.Client
mu sync.Mutex
isRecording bool
@@ -28,7 +28,7 @@ type Recorder struct {
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} {
if err := os.MkdirAll(dir, 0755); err != nil {
return nil, fmt.Errorf("failed to create directory %s: %w", dir, err)

View File

@@ -9,12 +9,12 @@ import (
"github.com/gorilla/feeds"
"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
type Generator struct {
fileStore *database.FileStore
fileStore *filestore.Store
feedBaseURL string
recordingsPath string
feedTitle string
@@ -22,7 +22,7 @@ type Generator struct {
}
// 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
if baseURL == "" {
slog.Warn("RSS_FEED_URL not set, using default")