Commit 65806637 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Split extension check in a separate method

parent 3a833d56
......@@ -393,14 +393,19 @@ std::vector<MediaPtr> MediaLibrary::videoFiles( SortingCriteria sort, bool desc
return Media::listAll( this, IMedia::Type::Video, sort, desc );
}
bool MediaLibrary::isExtensionSupported( const char* ext )
{
return std::binary_search( std::begin( supportedExtensions ),
std::end( supportedExtensions ), ext, [](const char* l, const char* r) {
return strcasecmp( l, r ) < 0;
});
}
std::shared_ptr<Media> MediaLibrary::addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs )
{
if ( std::binary_search( std::begin( supportedExtensions ), std::end( supportedExtensions ),
fileFs->extension().c_str(),
[](const char* l, const char* r) { return strcasecmp( l, r ) < 0; }
) == false )
if ( isExtensionSupported( fileFs->extension().c_str() ) == false )
{
LOG_INFO( "Rejecting file ", fileFs->mrl(), " due to its extension" );
return nullptr;
......
......@@ -144,6 +144,8 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
void refreshDevices(factory::IFileSystem& fsFactory);
static bool isExtensionSupported( const char* ext );
protected:
// Allow access to unit test MediaLibrary implementations
static const char* const supportedExtensions[];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment