Custom keys now say what type they are
This commit is contained in:
parent
7cb55f1fdf
commit
2b47f2c825
@ -34,7 +34,7 @@ std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::strin
|
||||
result.push_back( rl );
|
||||
goto dlsymerror;
|
||||
}
|
||||
rl.getCustomKeys = ( std::vector< std::string >( * )() )dlsym(
|
||||
rl.getCustomKeys = ( std::vector< std::pair< std::string, std::string > >( * )() )dlsym(
|
||||
libhndl, "getCustomKeys" );
|
||||
if ( !rl.getCustomKeys ) {
|
||||
result.push_back( rl );
|
||||
|
@ -15,11 +15,17 @@ using string = std::string;
|
||||
|
||||
#endif
|
||||
|
||||
#define STRING_TYPE "string"
|
||||
#define NUM_TYPE "number"
|
||||
#define YEAR_TYPE "year"
|
||||
#define DATE_TYPE "date"
|
||||
#define BOOL_TYPE "bool"
|
||||
|
||||
extern "C" {
|
||||
bool init(const string &configuration);
|
||||
std::vector< RenameObject > getOptions( const RenameObject &search );
|
||||
bool renamePath( const string &path, const RenameObject &renamer );
|
||||
std::vector< string > getCustomKeys();
|
||||
std::vector< std::pair<string, string> > getCustomKeys();
|
||||
const string getName();
|
||||
const bool canRenameMultipleFiles();
|
||||
}
|
||||
|
8
main.cpp
8
main.cpp
@ -138,7 +138,7 @@ void getOptionsRest( const std::shared_ptr< restbed::Session > &session, rapidjs
|
||||
sendResponse(getOptionsJson(search), 200, session);
|
||||
}
|
||||
|
||||
std::vector< std::string > getCustomKeys(size_t library_id) {
|
||||
std::vector< std::pair< std::string, std::string > > getCustomKeys(size_t library_id) {
|
||||
if(library_id >= libraries.size()) {
|
||||
return {};
|
||||
}
|
||||
@ -148,16 +148,16 @@ std::vector< std::string > getCustomKeys(size_t library_id) {
|
||||
|
||||
std::string getCustomKeysJson(size_t library_id) {
|
||||
std::ostringstream res;
|
||||
res << "{\n \"custom_keys\": [\n";
|
||||
res << "{\n \"custom_keys\": {\n";
|
||||
auto custom_keys = getCustomKeys(library_id);
|
||||
if(!custom_keys.empty()) {
|
||||
for(auto &key : custom_keys) {
|
||||
res << "\"" << safeJson(key) << "\",\n";
|
||||
res << "\"" << safeJson(key.first) << "\": \"" << safeJson(key.second) << "\",\n";
|
||||
}
|
||||
res.seekp( -2, std::ios_base::end );
|
||||
res << "\n";
|
||||
}
|
||||
res << " ]\n}";
|
||||
res << " }\n}";
|
||||
return res.str();
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ struct RenameLibrary {
|
||||
bool ( *init )( const std::string & );
|
||||
std::vector< RenameObject > ( *getOptions )( const RenameObject & );
|
||||
bool ( *renamePath )( const std::string &, const RenameObject & );
|
||||
std::vector< std::string > ( *getCustomKeys )();
|
||||
std::vector< std::pair< std::string, std::string > > ( *getCustomKeys )();
|
||||
const std::string ( *getName )();
|
||||
const bool ( *canRenameMultipleFiles )();
|
||||
void *libhndl;
|
||||
|
@ -40,14 +40,17 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( new_name.find('/') != string::npos || new_name.find('\\') != string::npos ) {
|
||||
if ( new_name.find( '/' ) != string::npos ||
|
||||
new_name.find( '\\' ) != string::npos ) {
|
||||
return false;
|
||||
}
|
||||
return FSLib::rename( path, FSLib::canonical( FSLib::getContainingDirectory(path) ) + "/" + new_name );
|
||||
return FSLib::rename(
|
||||
path, FSLib::canonical( FSLib::getContainingDirectory( path ) ) + "/" +
|
||||
new_name );
|
||||
}
|
||||
|
||||
std::vector< string > getCustomKeys() {
|
||||
return { "new_name" };
|
||||
std::vector< std::pair< string, string > > getCustomKeys() {
|
||||
return { { "new_name", STRING_TYPE } };
|
||||
}
|
||||
|
||||
const string getName() {
|
||||
|
@ -277,8 +277,12 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
|
||||
year );
|
||||
}
|
||||
|
||||
std::vector< string > getCustomKeys() {
|
||||
return { "id", "language", "year", "original_title", "use_original" };
|
||||
std::vector< std::pair< string, string > > getCustomKeys() {
|
||||
return { { "id", NUM_TYPE },
|
||||
{ "language", STRING_TYPE },
|
||||
{ "year", YEAR_TYPE },
|
||||
{ "original_title", STRING_TYPE },
|
||||
{ "use_original", BOOL_TYPE } };
|
||||
}
|
||||
|
||||
const string getName() {
|
||||
|
@ -401,8 +401,11 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector< string > getCustomKeys() {
|
||||
return { "id", "language", "pattern", "order" };
|
||||
std::vector< std::pair< string, string > > getCustomKeys() {
|
||||
return { { "id", NUM_TYPE },
|
||||
{ "language", STRING_TYPE },
|
||||
{ "pattern", STRING_TYPE },
|
||||
{ "order", STRING_TYPE } };
|
||||
}
|
||||
|
||||
const string getName() {
|
||||
|
Loading…
Reference in New Issue
Block a user