filter out unsupported images [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <QSaveFile>
|
||||
#include <QTimer>
|
||||
#include <QUrlQuery>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace {
|
||||
const int kMetadataTimeoutMs = 15000;
|
||||
@@ -93,13 +94,27 @@ QByteArray ImmichClient::getBytes(const QUrl &url, QString *contentType, int tim
|
||||
|
||||
QVector<ImmichAsset> ImmichClient::fetchAssets()
|
||||
{
|
||||
QVector<ImmichAsset> assets;
|
||||
if (!config.enabled)
|
||||
{
|
||||
Log("Immich config is missing url or apiKey.");
|
||||
return assets;
|
||||
return QVector<ImmichAsset>();
|
||||
}
|
||||
|
||||
if (!config.userId.empty() && config.albumIds.empty() && config.personIds.empty())
|
||||
return fetchAssetsByUser();
|
||||
|
||||
if (!config.userId.empty() && (!config.albumIds.empty() || !config.personIds.empty()))
|
||||
{
|
||||
Log("Immich userId is set but album/person filters are also set; ignoring userId for search filters.");
|
||||
}
|
||||
|
||||
return fetchAssetsBySearch();
|
||||
}
|
||||
|
||||
QVector<ImmichAsset> ImmichClient::fetchAssetsBySearch()
|
||||
{
|
||||
QVector<ImmichAsset> assets;
|
||||
|
||||
int pageSize = config.pageSize > 0 ? config.pageSize : 200;
|
||||
int maxAssets = config.maxAssets;
|
||||
bool triedZero = false;
|
||||
@@ -110,7 +125,8 @@ QVector<ImmichAsset> ImmichClient::fetchAssets()
|
||||
Log("Immich search: size=", config.size, ", order=", config.order,
|
||||
", pageSize=", pageSize, ", maxAssets=", maxAssets,
|
||||
", albumIds=", config.albumIds.size(),
|
||||
", personIds=", config.personIds.size());
|
||||
", personIds=", config.personIds.size(),
|
||||
", allowedExtensions=", config.allowedExtensions.size());
|
||||
}
|
||||
|
||||
while (true)
|
||||
@@ -170,6 +186,11 @@ QVector<ImmichAsset> ImmichClient::fetchAssets()
|
||||
ImmichAsset asset;
|
||||
asset.id = id;
|
||||
asset.originalFileName = item["originalFileName"].toString();
|
||||
if (!extensionAllowed(asset.originalFileName))
|
||||
{
|
||||
Log("Immich skip by extension: ", asset.originalFileName.toStdString());
|
||||
continue;
|
||||
}
|
||||
assets.append(asset);
|
||||
if (maxAssets > 0 && assets.size() >= maxAssets)
|
||||
return assets;
|
||||
@@ -183,6 +204,88 @@ QVector<ImmichAsset> ImmichClient::fetchAssets()
|
||||
return assets;
|
||||
}
|
||||
|
||||
QVector<ImmichAsset> ImmichClient::fetchAssetsByUser()
|
||||
{
|
||||
QVector<ImmichAsset> assets;
|
||||
|
||||
int pageSize = config.pageSize > 0 ? config.pageSize : 200;
|
||||
int maxAssets = config.maxAssets;
|
||||
int skip = 0;
|
||||
|
||||
if (ShouldLog())
|
||||
{
|
||||
Log("Immich assets: userId=", config.userId,
|
||||
", pageSize=", pageSize,
|
||||
", maxAssets=", maxAssets,
|
||||
", includeArchived=", config.includeArchived);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
QUrl url = apiUrl("/assets");
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("take", QString::number(pageSize));
|
||||
query.addQueryItem("skip", QString::number(skip));
|
||||
query.addQueryItem("userId", QString::fromStdString(config.userId));
|
||||
if (!config.includeArchived)
|
||||
query.addQueryItem("isArchived", "false");
|
||||
url.setQuery(query);
|
||||
|
||||
QByteArray response = getBytes(url, nullptr, kMetadataTimeoutMs);
|
||||
if (response.isEmpty())
|
||||
break;
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(response);
|
||||
if (!doc.isArray())
|
||||
break;
|
||||
|
||||
QJsonArray items = doc.array();
|
||||
Log("Immich user assets skip ", skip, ": ", items.size(), " assets");
|
||||
if (items.isEmpty())
|
||||
break;
|
||||
|
||||
for (const auto &value : items)
|
||||
{
|
||||
QJsonObject item = value.toObject();
|
||||
QString id = item["id"].toString();
|
||||
if (id.isEmpty())
|
||||
continue;
|
||||
ImmichAsset asset;
|
||||
asset.id = id;
|
||||
asset.originalFileName = item["originalFileName"].toString();
|
||||
if (!extensionAllowed(asset.originalFileName))
|
||||
{
|
||||
Log("Immich skip by extension: ", asset.originalFileName.toStdString());
|
||||
continue;
|
||||
}
|
||||
assets.append(asset);
|
||||
if (maxAssets > 0 && assets.size() >= maxAssets)
|
||||
return assets;
|
||||
}
|
||||
|
||||
if (items.size() < pageSize)
|
||||
break;
|
||||
skip += pageSize;
|
||||
}
|
||||
|
||||
return assets;
|
||||
}
|
||||
|
||||
bool ImmichClient::extensionAllowed(const QString &filename) const
|
||||
{
|
||||
if (config.allowedExtensions.empty())
|
||||
return true;
|
||||
QString ext = QFileInfo(filename).suffix().toLower();
|
||||
if (ext.isEmpty())
|
||||
return false;
|
||||
for (const auto &allowed : config.allowedExtensions)
|
||||
{
|
||||
if (ext == QString::fromStdString(allowed))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImmichClient::downloadAsset(const QString &assetId, QByteArray &data, QString &contentType)
|
||||
{
|
||||
if (!config.enabled)
|
||||
|
||||
Reference in New Issue
Block a user