diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-13 00:36:41 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-13 00:36:41 (GMT) |
commit | cccba3ce2e7a5797c84c78bce7e8d24fdcb8fce7 (patch) | |
tree | bd47642c036facf30b693a4c6a93131a14301f1d /src/helsinki.at/rhimport | |
parent | 60a2313659b57f66d502d44729b6b78f07bd3883 (diff) |
GroupName should now be only supplied for music pools
added context SanityCheck before fetching files
Diffstat (limited to 'src/helsinki.at/rhimport')
-rw-r--r-- | src/helsinki.at/rhimport/fetcher.go | 1 | ||||
-rw-r--r-- | src/helsinki.at/rhimport/importer.go | 34 |
2 files changed, 29 insertions, 6 deletions
diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go index a86f7ca..7d406b2 100644 --- a/src/helsinki.at/rhimport/fetcher.go +++ b/src/helsinki.at/rhimport/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/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index f365ea5..0fc5ecf 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/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] |