diff --git a/ChangeLog b/ChangeLog index 1b609ec9..fb432769 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15493,3 +15493,6 @@ 2016-11-28 Fred Gleason * Updated 'docs/tables/services.txt' to reflect changes made in database version 259. +2016-11-28 Fred Gleason + * Added 'CREATE' and 'GROUP_NAME' call fields to the 'Import' web + API call in 'web/rdxport/import.cpp'. diff --git a/docs/docbook/web_api.xml b/docs/docbook/web_api.xml index 1a17006b..449a9c9a 100644 --- a/docs/docbook/web_api.xml +++ b/docs/docbook/web_api.xml @@ -1778,6 +1778,28 @@ Mandatory, 0 = No, 1 = Yes + + + CREATE + + + Create cart/cut if it does not exist + + + Optional, 0 = No, 1 = Yes + + + + + GROUP_NAME + + + Add newly created cart/cut to specified group. + + + Optional + + FILENAME diff --git a/web/rdxport/import.cpp b/web/rdxport/import.cpp index 94db1ab6..c9a8e018 100644 --- a/web/rdxport/import.cpp +++ b/web/rdxport/import.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -66,16 +67,24 @@ void Xport::Import() if(!xport_post->getValue("USE_METADATA",&use_metadata)) { XmlExit("Missing USE_METADATA",400); } + int create=0; + if(!xport_post->getValue("CREATE",&create)) { + create=-1; + } + QString group_name; + xport_post->getValue("GROUP_NAME",&group_name); QString filename; if(!xport_post->getValue("FILENAME",&filename)) { XmlExit("Missing FILENAME",400); } + /* if(!RDCart::exists(cartnum)) { XmlExit("No such cart",404); } if(!RDCut::exists(cartnum,cutnum)) { XmlExit("No such cut",404); } + */ if(!xport_post->isFile("FILENAME")) { XmlExit("Missing file data",400); } @@ -83,18 +92,64 @@ void Xport::Import() // // Verify User Perms // - if(!xport_user->cartAuthorized(cartnum)) { - XmlExit("No such cart",404); + if(RDCart::exists(cartnum)) { + if(!xport_user->cartAuthorized(cartnum)) { + XmlExit("No such cart",404); + } + } + else { + if(create) { + if(!xport_user->groupAuthorized(group_name)) { + XmlExit("No such cart",404); + } + } + else { + XmlExit("No such cart",404); + } } if(!xport_user->editAudio()) { XmlExit("Unauthorized",401); } + if(create&&(!xport_user->createCarts())) { + XmlExit("Unauthorized",401); + } // // Load Configuration // RDCart *cart=new RDCart(cartnum); - RDCut *cut=new RDCut(cartnum,cutnum); + if(!RDCart::exists(cartnum)) { + if(create) { + if(group_name.isEmpty()) { + XmlExit("Missing GROUP_NAME",400); + } + RDGroup *group=new RDGroup(group_name); + if(!group->exists()) { + XmlExit("No such group",404); + } + if(!group->cartNumberValid(cartnum)) { + XmlExit("Cart number out of range for group",401); + } + cart->create(group_name,RDCart::Audio); + delete group; + } + else { + XmlExit("No such cart",404); + } + } + RDCut *cut=NULL; + if(RDCut::exists(cartnum,cutnum)) { + cut=new RDCut(cartnum,cutnum); + } + else { + if(create) { + cut=new RDCut(cartnum,cutnum,true); + cut->setDescription(QString().sprintf("Cut %03d",cutnum)); + } + else { + XmlExit("No such cut",404); + } + } RDLibraryConf *conf=new RDLibraryConf(xport_config->stationName(),0); RDSettings *settings=new RDSettings(); switch(conf->defaultFormat()) { diff --git a/web/tests/import.html b/web/tests/import.html index 2afb0887..64fd147c 100644 --- a/web/tests/import.html +++ b/web/tests/import.html @@ -38,6 +38,14 @@ +CREATE: + + + +GROUP_NAME: + + + FILE: