From 98f9c33fb29285a60bd535ae401266030d8c6b8b Mon Sep 17 00:00:00 2001 From: cballevre Date: Thu, 18 Jul 2024 09:57:26 +0200 Subject: [PATCH] feat(nextcloud): Add deletePermanently method --- .../src/NextcloudFilesCollection.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/cozy-stack-client/src/NextcloudFilesCollection.js b/packages/cozy-stack-client/src/NextcloudFilesCollection.js index 963bbcbb9..bae99f5f9 100644 --- a/packages/cozy-stack-client/src/NextcloudFilesCollection.js +++ b/packages/cozy-stack-client/src/NextcloudFilesCollection.js @@ -207,6 +207,25 @@ class NextcloudFilesCollection extends DocumentCollection { throw new FetchError(resp, resp.json()) } + /** + * Deletes a file permanently from the Nextcloud server. + * + * @param {Object} file - The file object to be deleted. + * @returns {Promise} - A promise that resolves to the response from the server. + * @throws {FetchError} - If the server returns an error response. + */ + async deletePermanently(file) { + const resp = await this.stackClient.fetch( + 'DELETE', + `/remote/nextcloud/${file.cozyMetadata.sourceAccount}${encodePath( + file.path + )}` + ) + if (resp.status === 204) { + return resp + } + throw new FetchError(resp, resp.json()) + } } export { NextcloudFilesCollection, NEXTCLOUD_FILES_DOCTYPE }