From 96456e2085dc3c9baa02960f996d378609a5962e Mon Sep 17 00:00:00 2001 From: Pierre Jeanjean Date: Tue, 17 Dec 2024 11:33:17 +0100 Subject: [PATCH] CRISTAL-371: Shows details about the last edition on pages * Add support for Nextcloud --- .../backend-nextcloud/src/nextcloudStorage.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/backends/backend-nextcloud/src/nextcloudStorage.ts b/core/backends/backend-nextcloud/src/nextcloudStorage.ts index 714cca1ee..a1fdee34a 100644 --- a/core/backends/backend-nextcloud/src/nextcloudStorage.ts +++ b/core/backends/backend-nextcloud/src/nextcloudStorage.ts @@ -71,6 +71,41 @@ export class NextcloudStorage extends AbstractStorage { ); if (response.status >= 200 && response.status < 300) { + let lastAuthor: string | undefined; + let lastModificationDate: Date | undefined; + const propResponse = await fetch( + `${this.getWikiConfig().baseRestURL}/${USERNAME}/.cristal/${page}/page.json`, + { + body: ` + + + + + + `, + method: "PROPFIND", + headers: { + ...this.getBaseHeaders(), + Accept: "application/json", + }, + }, + ); + if (propResponse.status >= 200 && propResponse.status < 300) { + const propText = await propResponse.text(); + const propData = new window.DOMParser().parseFromString( + propText, + "text/xml", + ); + + const modifiedProp = + propData.getElementsByTagName("d:getlastmodified")[0]?.innerHTML; + if (modifiedProp) { + lastModificationDate = new Date(Date.parse(modifiedProp)); + } + lastAuthor = propData.getElementsByTagName("oc:owner-display-name")[0] + ?.innerHTML; + } + const json = await response.json(); return { @@ -78,6 +113,8 @@ export class NextcloudStorage extends AbstractStorage { id: page, headline: json.name, headlineRaw: json.name, + lastAuthor: lastAuthor, + lastModificationDate: lastModificationDate, }; } else { return undefined;