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

Thumbnail: Allow a thumbnail record to be created for failures

parent 1dcc35c5
......@@ -319,6 +319,8 @@ const std::string& Media::thumbnail() const
return Thumbnail::EmptyMrl;
m_thumbnail = std::move( thumbnail );
}
if ( m_thumbnail->isValid() == false )
return Thumbnail::EmptyMrl;
return m_thumbnail->mrl();
}
......@@ -398,7 +400,15 @@ bool Media::setThumbnail( const std::string& thumbnailMrl, Thumbnail::Origin ori
std::unique_ptr<sqlite::Transaction> t;
if ( sqlite::Transaction::transactionInProgress() == false )
t = m_ml->getConn()->newTransaction();
auto thumbnail = Thumbnail::create( m_ml, thumbnailMrl, origin, isGenerated );
std::shared_ptr<Thumbnail> thumbnail;
if ( thumbnailMrl.empty() )
{
assert( origin == Thumbnail::Origin::Media );
assert( isGenerated == true );
thumbnail = Thumbnail::createForFailure( m_ml );
}
else
thumbnail = Thumbnail::create( m_ml, thumbnailMrl, origin, isGenerated );
if ( thumbnail == nullptr )
return false;
......
......@@ -61,6 +61,14 @@ Thumbnail::Thumbnail( MediaLibraryPtr ml, std::string mrl,
m_mrl = m_ml->thumbnailPath() + m_mrl;
}
Thumbnail::Thumbnail( MediaLibraryPtr ml )
: m_ml( ml )
, m_id( 0 )
, m_origin( Origin::Media )
, m_isGenerated( true )
{
}
int64_t Thumbnail::id() const
{
return m_id;
......@@ -68,6 +76,7 @@ int64_t Thumbnail::id() const
const std::string& Thumbnail::mrl() const
{
assert( isValid() == true );
return m_mrl;
}
......@@ -84,6 +93,11 @@ bool Thumbnail::update( std::string mrl, Origin origin )
return true;
}
bool Thumbnail::isValid() const
{
return m_mrl.empty() == false;
}
Thumbnail::Origin Thumbnail::origin() const
{
return m_origin;
......@@ -111,7 +125,7 @@ void Thumbnail::createTable( sqlite::Connection* dbConnection )
const std::string req = "CREATE TABLE IF NOT EXISTS " + Thumbnail::Table::Name +
"("
"id_thumbnail INTEGER PRIMARY KEY AUTOINCREMENT,"
"mrl TEXT NOT NULL,"
"mrl TEXT,"
"origin INTEGER NOT NULL,"
"is_generated BOOLEAN NOT NULL"
")";
......@@ -131,5 +145,15 @@ std::shared_ptr<Thumbnail> Thumbnail::create( MediaLibraryPtr ml, std::string mr
return self;
}
std::shared_ptr<Thumbnail> Thumbnail::createForFailure( MediaLibraryPtr ml )
{
static const std::string req = "INSERT INTO " + Thumbnail::Table::Name +
"(mrl, origin, is_generated) VALUES(?,?,?)";
auto self = std::make_shared<Thumbnail>( ml );
if ( insert( ml, self, req, nullptr, Origin::Media, true ) == false )
return nullptr;
return self;
}
}
......@@ -50,10 +50,20 @@ public:
Thumbnail( MediaLibraryPtr ml, sqlite::Row& row );
Thumbnail( MediaLibraryPtr ml, std::string mrl, Origin origin, bool isGenerated );
/**
* @brief Thumbnail Constructor for a failure record
*/
Thumbnail( MediaLibraryPtr ml );
int64_t id() const;
const std::string& mrl() const;
bool update( std::string mrl, Origin origin );
/**
* @brief isValid Returns true if the thumbnail was correctly generated
*
* This only only relevent for thumbnail that are generated by the medialibrary
*/
bool isValid() const;
Origin origin() const;
/**
......@@ -71,6 +81,15 @@ public:
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Thumbnail> create( MediaLibraryPtr ml, std::string mrl,
Origin origin, bool isGenerated );
/**
* @brief createForFailure Creates a thumbnail record that denotes a failure
* @param ml A medialibrary instance pointer
*
* This creates a record in the thumbnail table that denotes that a thumbnail
* generation failed. A valid thumbnail will be generated, and can be updated
* if required, or the record can be removed at a later time to force the regeneration
*/
static std::shared_ptr<Thumbnail> createForFailure( MediaLibraryPtr ml );
static const std::string EmptyMrl;
......
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