delete image working

This commit is contained in:
gitea
2025-11-06 23:52:41 +01:00
parent 2c5f0eaefc
commit 84f1712916
4 changed files with 315 additions and 54 deletions
+79
View File
@@ -550,6 +550,85 @@ class ImmichService {
};
}
/// Deletes assets from Immich.
///
/// [assetIds] - List of asset UUIDs to delete.
///
/// Throws [ImmichException] if deletion fails.
Future<void> deleteAssets(List<String> assetIds) async {
if (assetIds.isEmpty) {
throw ImmichException('No asset IDs provided for deletion');
}
try {
debugPrint('=== Immich Delete Assets ===');
debugPrint('Asset IDs to delete: $assetIds');
debugPrint('Count: ${assetIds.length}');
// DELETE /api/assets with ids in request body
// According to Immich API: DELETE /api/assets with body: {"ids": ["uuid1", "uuid2", ...]}
final requestBody = {
'ids': assetIds,
};
debugPrint('Request body: $requestBody');
final response = await _dio.delete(
'/api/assets',
data: requestBody,
options: Options(
headers: {
'x-api-key': _apiKey,
'Content-Type': 'application/json',
},
),
);
debugPrint('=== Immich Delete Response ===');
debugPrint('Status Code: ${response.statusCode}');
debugPrint('Response Data: ${response.data}');
if (response.statusCode != 200 && response.statusCode != 204) {
final errorMessage = response.data is Map
? (response.data as Map)['message']?.toString() ??
response.statusMessage
: response.statusMessage;
throw ImmichException(
'Delete failed: $errorMessage',
response.statusCode,
);
}
// Remove deleted assets from local cache
for (final assetId in assetIds) {
try {
await _localStorage.deleteItem('immich_$assetId');
} catch (e) {
debugPrint('Warning: Failed to remove asset $assetId from cache: $e');
}
}
debugPrint('Successfully deleted ${assetIds.length} asset(s)');
} on DioException catch (e) {
final statusCode = e.response?.statusCode;
final errorData = e.response?.data;
String errorMessage;
if (errorData is Map) {
errorMessage = errorData['message']?.toString() ?? errorData.toString();
} else {
errorMessage = errorData?.toString() ?? e.message ?? 'Unknown error';
}
throw ImmichException(
'Delete failed: $errorMessage',
statusCode,
);
} catch (e) {
throw ImmichException('Delete failed: $e');
}
}
/// Tests the connection to Immich server by calling the /api/server/about endpoint.
///
/// Returns server information including version and status.