Skip to content

Commit

Permalink
CRISTAL-371: Shows details about the last edition on pages
Browse files Browse the repository at this point in the history
* Add support for Nextcloud
  • Loading branch information
pjeanjean committed Dec 17, 2024
1 parent 4e43565 commit 96456e2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core/backends/backend-nextcloud/src/nextcloudStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,50 @@ 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: `<?xml version="1.0" encoding="UTF-8"?>
<d:propfind xmlns:d="DAV:">
<d:prop xmlns:oc="http://owncloud.org/ns">
<d:getlastmodified />
<oc:owner-display-name />
</d:prop>
</d:propfind>`,
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 {
...json,
id: page,
headline: json.name,
headlineRaw: json.name,
lastAuthor: lastAuthor,
lastModificationDate: lastModificationDate,
};
} else {
return undefined;
Expand Down

0 comments on commit 96456e2

Please sign in to comment.