first commit
This commit is contained in:
56
src/immichclient.h
Normal file
56
src/immichclient.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef IMMICHCLIENT_H
|
||||
#define IMMICHCLIENT_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QVector>
|
||||
|
||||
#include "appconfig.h"
|
||||
|
||||
struct ImmichAsset {
|
||||
QString id;
|
||||
QString originalFileName;
|
||||
};
|
||||
|
||||
class ImmichClient {
|
||||
public:
|
||||
explicit ImmichClient(const ImmichConfig &config);
|
||||
QVector<ImmichAsset> fetchAssets();
|
||||
bool downloadAsset(const QString &assetId, QByteArray &data, QString &contentType);
|
||||
|
||||
private:
|
||||
QUrl apiUrl(const QString &path) const;
|
||||
QNetworkRequest makeRequest(const QUrl &url) const;
|
||||
QByteArray postJson(const QUrl &url, const QJsonObject &body, QString *contentType, int timeoutMs);
|
||||
QByteArray getBytes(const QUrl &url, QString *contentType, int timeoutMs);
|
||||
bool waitForReply(QNetworkReply *reply, QByteArray &data, QString *contentType, int timeoutMs);
|
||||
|
||||
ImmichConfig config;
|
||||
QNetworkAccessManager manager;
|
||||
};
|
||||
|
||||
class ImmichAssetCache {
|
||||
public:
|
||||
explicit ImmichAssetCache(const ImmichConfig &config);
|
||||
QString getCachedPath(const QString &assetId, const QString &assetName, ImmichClient &client);
|
||||
|
||||
private:
|
||||
QString resolveCachePath(const QString &rawPath) const;
|
||||
QString findExisting(const QString &assetId) const;
|
||||
QString sanitizeFileName(const QString &name) const;
|
||||
QString extensionForContentType(const QString &contentType) const;
|
||||
void ensureCacheDir() const;
|
||||
void enforceCacheLimit();
|
||||
qint64 calculateCacheSize() const;
|
||||
|
||||
QString cacheDirPath;
|
||||
qint64 cacheMaxBytes = 0;
|
||||
bool cacheSizeKnown = false;
|
||||
qint64 cacheSizeBytes = 0;
|
||||
};
|
||||
|
||||
#endif // IMMICHCLIENT_H
|
||||
Reference in New Issue
Block a user