Add get_library_pattern endpoint

This commit is contained in:
zv0n 2022-03-12 22:54:01 +01:00
parent 1a495149b2
commit 87811418b1
4 changed files with 38 additions and 0 deletions

View File

@ -55,6 +55,7 @@ std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::strin
rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" ); rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" );
rl.canRenameMultipleFiles = ( const bool(*)() ) dlsym( libhndl, "canRenameMultipleFiles" ); rl.canRenameMultipleFiles = ( const bool(*)() ) dlsym( libhndl, "canRenameMultipleFiles" );
rl.shouldPerformSearch = ( const bool(*)() ) dlsym( libhndl, "shouldPerformSearch" ); rl.shouldPerformSearch = ( const bool(*)() ) dlsym( libhndl, "shouldPerformSearch" );
rl.choiceDisplay = ( const std::string(*)() ) dlsym( libhndl, "choiceDisplay" );
rl.config = library.second; rl.config = library.second;
result.push_back( rl ); result.push_back( rl );
} }

View File

@ -34,6 +34,7 @@ const string getCustomKeyDefault(const string &key);
const string getName(); const string getName();
const bool canRenameMultipleFiles(); const bool canRenameMultipleFiles();
const bool shouldPerformSearch(); const bool shouldPerformSearch();
const std::string choiceDisplay();
} }
#endif // TV_RENAME_HPP #endif // TV_RENAME_HPP

View File

@ -182,6 +182,13 @@ std::string getFieldDefault( size_t library_id, const std::string &field ) {
return libraries[library_id].getCustomKeyDefault( field ); return libraries[library_id].getCustomKeyDefault( field );
} }
std::string getLibraryPattern( size_t library_id ) {
if ( library_id >= libraries.size() ) {
return "";
}
return libraries[library_id].choiceDisplay();
}
std::string getCustomKeysJson( size_t library_id ) { std::string getCustomKeysJson( size_t library_id ) {
std::ostringstream res; std::ostringstream res;
res << "{\n \"custom_keys\": [\n"; res << "{\n \"custom_keys\": [\n";
@ -229,6 +236,13 @@ std::string getFieldDefaultJson( size_t library_id, const std::string &field ) {
return res.str(); return res.str();
} }
std::string getLibraryPatternJson( size_t library_id ) {
std::ostringstream res;
res << "{\n \"pattern\": \"" << getLibraryPattern( library_id )
<< "\"}";
return res.str();
}
void getCustomKeysRest( const std::shared_ptr< restbed::Session > &session, void getCustomKeysRest( const std::shared_ptr< restbed::Session > &session,
rapidjson::GenericDocument< rapidjson::UTF8<> > &doc ) { rapidjson::GenericDocument< rapidjson::UTF8<> > &doc ) {
if ( doc.FindMember( "library_id" ) == doc.MemberEnd() || if ( doc.FindMember( "library_id" ) == doc.MemberEnd() ||
@ -276,6 +290,18 @@ void getFieldDefaultRest(
sendResponse( getFieldDefaultJson( library_id, field ), 200, session ); sendResponse( getFieldDefaultJson( library_id, field ), 200, session );
} }
void getLibraryPatternRest(
const std::shared_ptr< restbed::Session > &session,
rapidjson::GenericDocument< rapidjson::UTF8<> > &doc ) {
if ( doc.FindMember( "library_id" ) == doc.MemberEnd() ||
!doc["library_id"].IsUint64() ) {
sendResponse( "ERROR: Invalid library_id!", 401, session );
return;
}
auto library_id = doc["library_id"].GetUint64();
sendResponse( getLibraryPatternJson( library_id ), 200, session );
}
std::pair< bool, std::string > renamePath( std::string path, std::pair< bool, std::string > renamePath( std::string path,
const RenameObject &renamer ) { const RenameObject &renamer ) {
if ( renamer.getLibraryId() >= libraries.size() ) { if ( renamer.getLibraryId() >= libraries.size() ) {
@ -620,6 +646,10 @@ void getFieldDefaultCall( const std::shared_ptr< restbed::Session > &session ) {
performPostFunc( session, getFieldDefaultRest ); performPostFunc( session, getFieldDefaultRest );
} }
void getLibraryPatternCall( const std::shared_ptr< restbed::Session > &session ) {
performPostFunc( session, getLibraryPatternRest );
}
void renameCall( const std::shared_ptr< restbed::Session > &session ) { void renameCall( const std::shared_ptr< restbed::Session > &session ) {
performPostFunc( session, renamePathRest ); performPostFunc( session, renamePathRest );
} }
@ -684,6 +714,11 @@ int main( int argc, char **argv ) {
field_default->set_method_handler( "POST", getFieldDefaultCall ); field_default->set_method_handler( "POST", getFieldDefaultCall );
service.publish( field_default ); service.publish( field_default );
auto library_pattern = std::make_shared< restbed::Resource >();
library_pattern->set_path( "/get_library_pattern" );
library_pattern->set_method_handler( "POST", getLibraryPatternCall );
service.publish( library_pattern );
auto rename_path = std::make_shared< restbed::Resource >(); auto rename_path = std::make_shared< restbed::Resource >();
rename_path->set_path( "/rename" ); rename_path->set_path( "/rename" );
rename_path->set_method_handler( "POST", renameCall ); rename_path->set_method_handler( "POST", renameCall );

View File

@ -15,6 +15,7 @@ struct RenameLibrary {
const std::string ( *getName )(); const std::string ( *getName )();
const bool ( *canRenameMultipleFiles )(); const bool ( *canRenameMultipleFiles )();
const bool ( *shouldPerformSearch )(); const bool ( *shouldPerformSearch )();
const std::string ( *choiceDisplay )();
void *libhndl; void *libhndl;
std::string name; std::string name;
std::string config; std::string config;