delete image working
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user