From c1bff94567a3f1bbfe631795608a24fa44394e76 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 13 Dec 2015 01:36:41 +0100 Subject: GroupName should now be only supplied for music pools added context SanityCheck before fetching files diff --git a/fetcher.go b/fetcher.go index a86f7ca..7d406b2 100644 --- a/fetcher.go +++ b/fetcher.go @@ -146,7 +146,6 @@ func FetchFileLocal(ctx *ImportContext, uri *url.URL) (err error) { type FetchFunc func(*ImportContext, *url.URL) (err error) - // TODO: implement fetchers for: // archiv:// // public:// diff --git a/importer.go b/importer.go index f365ea5..0fc5ecf 100644 --- a/importer.go +++ b/importer.go @@ -62,7 +62,7 @@ type ImportContext struct { ProgressCallBackData interface{} } -func NewImportContext(conf *Config, rddb *RdDb, user string, group string) *ImportContext { +func NewImportContext(conf *Config, rddb *RdDb, user string) *ImportContext { ctx := new(ImportContext) ctx.Config = conf ctx.RdDb = rddb @@ -71,11 +71,11 @@ func NewImportContext(conf *Config, rddb *RdDb, user string, group string) *Impo ctx.Trusted = false ctx.ShowId = 0 ctx.ClearShowCarts = false - ctx.GroupName = group + ctx.GroupName = "" ctx.Cart = 0 ctx.Cut = 0 ctx.Channels = 2 - ctx.NormalizationLevel = -1200 + ctx.NormalizationLevel = -12 ctx.AutotrimLevel = 0 ctx.UseMetaData = false ctx.SourceFile = "" @@ -86,6 +86,29 @@ func NewImportContext(conf *Config, rddb *RdDb, user string, group string) *Impo return ctx } +func (ctx *ImportContext) SanityCheck() error { + if ctx.UserName == "" { + return fmt.Errorf("empty Username is not allowed") + } + if ctx.Password == "" && !ctx.Trusted { + return fmt.Errorf("empty Password on untrusted control interface is not allowed") + } + if ctx.ShowId != 0 { + return nil + } + if ctx.GroupName != "" { + // TODO: check if GroupName is a music pool -> Error if not + return nil + } + if ctx.Cart == 0 { + return fmt.Errorf("either ShowId, PoolName or CartNumber must be supplied") + } + if ctx.Channels != 1 && ctx.Channels != 2 { + return fmt.Errorf("channles must be 1 or 2") + } + return nil +} + func (ctx *ImportContext) getPassword(cached bool) (err error) { req := getPasswordRequest{} req.username = ctx.UserName @@ -409,7 +432,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { // - add_cut(ctx, res) [200 -> OK] // - import_audio(ctx, res) [200 -> OK] return - } else if ctx.GroupName != "" && ctx.Cart == 0 { + } else if ctx.GroupName != "" { res.ResponseCode = 500 res.ErrorString = "Importing to music pools using the group name is not yet implemented" // TODO: fetch info from dropboxes (import-params) @@ -419,7 +442,8 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) { } else if ctx.Cart != 0 && ctx.Cut == 0 { res.ResponseCode = 500 res.ErrorString = "Importing to a Cart which might not exist is not yet implemented" - // TODO: (everything except Cut and ShowId must be in context) + // TODO: (everything except Cut, GroupName and ShowId must be in context) + // - ctx.GetGroupOfCart(ctx.Cart) // - remove_cart(ctx, res) [200 || 404 -> OK] // - add_cart(ctx, res) [200 -> OK] // - add_cut(ctx, res) [200 -> OK] -- cgit v0.10.2