mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
second part of PR #578
Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
62
include/db/MetaTable.h
Normal file
62
include/db/MetaTable.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
// hyperion
|
||||
#include <db/DBManager.h>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
#include <QNetworkInterface>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
///
|
||||
/// @brief meta table specific database interface
|
||||
///
|
||||
class MetaTable : public DBManager
|
||||
{
|
||||
|
||||
public:
|
||||
/// construct wrapper with plugins table and columns
|
||||
MetaTable(QObject* parent = nullptr)
|
||||
: DBManager(parent)
|
||||
{
|
||||
setTable("meta");
|
||||
createTable(QStringList()<<"uuid TEXT"<<"created_at TEXT");
|
||||
};
|
||||
~MetaTable(){};
|
||||
|
||||
///
|
||||
/// @brief Get the uuid, if the uuid is not set it will be created
|
||||
/// @return The uuid
|
||||
///
|
||||
inline const QString getUUID()
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
getRecords(results, QStringList() << "uuid");
|
||||
|
||||
for(const auto & entry : results)
|
||||
{
|
||||
if(!entry["uuid"].toString().isEmpty())
|
||||
return entry["uuid"].toString();
|
||||
}
|
||||
|
||||
// create new uuidv5 based on net adapter MAC, save to db and return
|
||||
QString hash;
|
||||
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
|
||||
{
|
||||
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
|
||||
{
|
||||
hash = QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex();
|
||||
break;
|
||||
}
|
||||
}
|
||||
const QString newUuid = QUuid::createUuidV5(QUuid(), hash).toString().mid(1, 36);
|
||||
VectorPair cond;
|
||||
cond.append(CPair("uuid",newUuid));
|
||||
QVariantMap map;
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
createRecord(cond, map);
|
||||
|
||||
return newUuid;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user