From d89cd25bacb46cf4fe557a84540143a7178a72f3 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 9 Jul 2024 18:15:48 +0200 Subject: [PATCH] feat(NcRichText): Call public reference API when unauthenticated * Depends on nextcloud/server#46378 * Contributes to nextcloud/server#45978 Signed-off-by: Jonas --- src/components/NcRichText/NcReferenceList.vue | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/NcRichText/NcReferenceList.vue b/src/components/NcRichText/NcReferenceList.vue index e0e1df3b98..d58b70c95b 100644 --- a/src/components/NcRichText/NcReferenceList.vue +++ b/src/components/NcRichText/NcReferenceList.vue @@ -15,6 +15,7 @@ import NcReferenceWidget from './NcReferenceWidget.vue' import { URL_PATTERN } from './helpers.js' import axios from '@nextcloud/axios' +import { getCurrentUser } from '@nextcloud/auth' import { generateOcsUrl } from '@nextcloud/router' export default { @@ -118,15 +119,26 @@ export default { }, resolve() { const match = (new RegExp(URL_PATTERN).exec(this.text.trim())) + const isPublic = !getCurrentUser()?.uid + const sharingToken = document.getElementById('sharingToken')?.value || '' if (this.limit === 1 && match) { - return axios.get(generateOcsUrl('references/resolve', 2) + `?reference=${encodeURIComponent(match[0])}`) + return isPublic + ? axios.get(generateOcsUrl('references/resolvePublic', 2) + `?reference=${encodeURIComponent(match[0])}&sharingToken=${sharingToken}`) + : axios.get(generateOcsUrl('references/resolve', 2) + `?reference=${encodeURIComponent(match[0])}`) } - return axios.post(generateOcsUrl('references/extract', 2), { - text: this.text, - resolve: true, - limit: this.limit, - }) + return isPublic + ? axios.post(generateOcsUrl('references/extractPublic', 2), { + text: this.text, + resolve: true, + limit: this.limit, + sharingToken, + }) + : axios.post(generateOcsUrl('references/extract', 2), { + text: this.text, + resolve: true, + limit: this.limit, + }) }, }, }