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- committed Jul 9, 2024
1 parent b9a2df7 commit 61f75c2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 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 @@ -118,15 +119,25 @@ export default {
},
resolve() {
const match = (new RegExp(URL_PATTERN).exec(this.text.trim()))
const isPublic = !getCurrentUser()?.uid
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])}&origin=${encodeURIComponent(window.location.href)}`)
: 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,
origin: window.location.href,
})
: axios.post(generateOcsUrl('references/extract', 2), {
text: this.text,
resolve: true,
limit: this.limit,
})
},
},
}
Expand Down

0 comments on commit 61f75c2

Please sign in to comment.