config: update more configuration options

This commit is contained in:
Tigor Hutasuhut 2024-04-09 23:17:23 +07:00
parent 9e71c3cbfa
commit 1b4e0c7669
4 changed files with 37 additions and 8 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/robfig/cron/v3"
"github.com/teivah/broadcast"
"github.com/tigorlazuardi/redmage/config"
"github.com/tigorlazuardi/redmage/db/queries"
"github.com/tigorlazuardi/redmage/pkg/errs"
"github.com/tigorlazuardi/redmage/pkg/log"
@ -20,15 +21,18 @@ type API struct {
scheduleMap map[cron.EntryID]queries.Subreddit
downloadBroadcast *broadcast.Relay[DownloadStatusMessage]
config *config.Config
}
func New(q *queries.Queries, db *sql.DB) *API {
func New(q *queries.Queries, db *sql.DB, cfg *config.Config) *API {
return &API{
queries: q,
db: db,
scheduler: cron.New(),
scheduleMap: make(map[cron.EntryID]queries.Subreddit, 8),
downloadBroadcast: broadcast.NewRelay[DownloadStatusMessage](),
config: cfg,
}
}

View file

@ -1,12 +1,27 @@
package api
import "context"
import (
"context"
"errors"
"github.com/tigorlazuardi/redmage/db/queries"
"github.com/tigorlazuardi/redmage/pkg/errs"
)
type DownloadSubredditParams struct {
Countback int
NSFW bool
Devices []queries.Device
}
var (
ErrNoDevices = errors.New("api: downloading subreddit images requires at least one device")
ErrDownloadDirNotSet = errors.New("api: downloading subreddit images require download directory to be set")
)
func (api *API) DownloadSubredditImages(ctx context.Context, subredditName string, params DownloadSubredditParams) error {
if len(params.Devices) == 0 {
return errs.Wrap(ErrNoDevices)
}
return nil
}

View file

@ -28,7 +28,7 @@ var serveCmd = &cobra.Command{
queries := queries.New(db)
api := api.New(queries, db)
api := api.New(queries, db, cfg)
server := server.New(cfg, api, PublicDir)

View file

@ -1,16 +1,26 @@
package config
var DefaultConfig = map[string]any{
"log.enable": true,
"log.source": true,
"log.format": "pretty",
"log.level": "info",
"log.output": "stderr",
"flags.containerized": false,
"log.enable": true,
"log.source": true,
"log.format": "pretty",
"log.level": "info",
"log.output": "stderr",
"log.file.enable": true,
"log.file.path": "redmage.log",
"db.driver": "sqlite3",
"db.string": "data.db",
"db.automigrate": true,
"download.concurrency": 5,
"download.directory": "",
"download.timeout.firstbyte": "30s",
"download.timeout.idleconnection": "5s",
"download.timeout.idlespeed": 10 * 1024, // 10KB
"http.port": "8080",
"http.host": "0.0.0.0",
"http.shutdown_timeout": "5s",