Custom keys now say what type they are

This commit is contained in:
zv0n 2022-03-06 15:03:06 +01:00
parent 7cb55f1fdf
commit 2b47f2c825
7 changed files with 33 additions and 17 deletions

View File

@ -34,7 +34,7 @@ std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::strin
result.push_back( rl ); result.push_back( rl );
goto dlsymerror; goto dlsymerror;
} }
rl.getCustomKeys = ( std::vector< std::string >( * )() )dlsym( rl.getCustomKeys = ( std::vector< std::pair< std::string, std::string > >( * )() )dlsym(
libhndl, "getCustomKeys" ); libhndl, "getCustomKeys" );
if ( !rl.getCustomKeys ) { if ( !rl.getCustomKeys ) {
result.push_back( rl ); result.push_back( rl );

View File

@ -15,11 +15,17 @@ using string = std::string;
#endif #endif
#define STRING_TYPE "string"
#define NUM_TYPE "number"
#define YEAR_TYPE "year"
#define DATE_TYPE "date"
#define BOOL_TYPE "bool"
extern "C" { extern "C" {
bool init(const string &configuration); bool init(const string &configuration);
std::vector< RenameObject > getOptions( const RenameObject &search ); std::vector< RenameObject > getOptions( const RenameObject &search );
bool renamePath( const string &path, const RenameObject &renamer ); bool renamePath( const string &path, const RenameObject &renamer );
std::vector< string > getCustomKeys(); std::vector< std::pair<string, string> > getCustomKeys();
const string getName(); const string getName();
const bool canRenameMultipleFiles(); const bool canRenameMultipleFiles();
} }

View File

@ -138,7 +138,7 @@ void getOptionsRest( const std::shared_ptr< restbed::Session > &session, rapidjs
sendResponse(getOptionsJson(search), 200, session); 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()) { if(library_id >= libraries.size()) {
return {}; return {};
} }
@ -148,16 +148,16 @@ std::vector< std::string > getCustomKeys(size_t library_id) {
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";
auto custom_keys = getCustomKeys(library_id); auto custom_keys = getCustomKeys(library_id);
if(!custom_keys.empty()) { if(!custom_keys.empty()) {
for(auto &key : custom_keys) { 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.seekp( -2, std::ios_base::end );
res << "\n"; res << "\n";
} }
res << " ]\n}"; res << " }\n}";
return res.str(); return res.str();
} }

View File

@ -8,7 +8,7 @@ struct RenameLibrary {
bool ( *init )( const std::string & ); bool ( *init )( const std::string & );
std::vector< RenameObject > ( *getOptions )( const RenameObject & ); std::vector< RenameObject > ( *getOptions )( const RenameObject & );
bool ( *renamePath )( const std::string &, 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 std::string ( *getName )();
const bool ( *canRenameMultipleFiles )(); const bool ( *canRenameMultipleFiles )();
void *libhndl; void *libhndl;

View File

@ -22,11 +22,11 @@ constexpr const char_t *_tv_rename_dir_divider = "/";
#endif #endif
bool init(const string &config_path) { bool init( const string &config_path ) {
return true; return true;
} }
std::vector< RenameObject > getOptions( const RenameObject &/*UNUSED*/ ) { std::vector< RenameObject > getOptions( const RenameObject & /*UNUSED*/ ) {
return {}; return {};
} }
@ -40,14 +40,17 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
return false; 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 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() { std::vector< std::pair< string, string > > getCustomKeys() {
return { "new_name" }; return { { "new_name", STRING_TYPE } };
} }
const string getName() { const string getName() {

View File

@ -277,8 +277,12 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
year ); year );
} }
std::vector< string > getCustomKeys() { std::vector< std::pair< string, string > > getCustomKeys() {
return { "id", "language", "year", "original_title", "use_original" }; return { { "id", NUM_TYPE },
{ "language", STRING_TYPE },
{ "year", YEAR_TYPE },
{ "original_title", STRING_TYPE },
{ "use_original", BOOL_TYPE } };
} }
const string getName() { const string getName() {

View File

@ -401,8 +401,11 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
return true; return true;
} }
std::vector< string > getCustomKeys() { std::vector< std::pair< string, string > > getCustomKeys() {
return { "id", "language", "pattern", "order" }; return { { "id", NUM_TYPE },
{ "language", STRING_TYPE },
{ "pattern", STRING_TYPE },
{ "order", STRING_TYPE } };
} }
const string getName() { const string getName() {