60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
#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:
|
|
QVector<ImmichAsset> fetchAssetsBySearch();
|
|
QVector<ImmichAsset> fetchAssetsByUser();
|
|
bool extensionAllowed(const QString &filename) const;
|
|
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
|