Skip to content

Commit

Permalink
feat(NcRichText): Call public reference API when unauthenticated
Browse files Browse the repository at this point in the history
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- authored and backportbot[bot] committed Jul 22, 2024
1 parent 2817ebd commit 2c6bb9e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/NcRichText/NcReferenceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -119,15 +120,26 @@ export default {
},
resolve() {
const match = (new RegExp(URL_PATTERN).exec(this.text.trim()))
const isPublic = getCurrentUser() === null
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') + `?reference=${encodeURIComponent(match[0])}&sharingToken=${sharingToken}`)
: axios.get(generateOcsUrl('references/resolve') + `?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'), {
text: this.text,
resolve: true,
limit: this.limit,
sharingToken,
})
: axios.post(generateOcsUrl('references/extract'), {
text: this.text,
resolve: true,
limit: this.limit,
})
},
},
}
Expand Down

0 comments on commit 2c6bb9e

Please sign in to comment.