Skip to content

Commit

Permalink
Merge pull request #5800 from nextcloud-libraries/feat/public_reference
Browse files Browse the repository at this point in the history
feat(NcRichText): Call public reference API when unauthenticated
  • Loading branch information
mejo- authored Jul 22, 2024
2 parents 2c8d7a4 + d39b28a commit f57e30d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@nextcloud/l10n": "^3.0.1",
"@nextcloud/logger": "^3.0.1",
"@nextcloud/router": "^3.0.0",
"@nextcloud/sharing": "^0.2.2",
"@nextcloud/timezones": "^0.1.1",
"@nextcloud/vue-select": "^3.25.0",
"@vueuse/components": "^10.9.0",
Expand Down
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,8 @@ import NcReferenceWidget from './NcReferenceWidget.vue'
import { URL_PATTERN } from './helpers.js'

import axios from '@nextcloud/axios'
import { getSharingToken } from '@nextcloud/sharing/public'
import { getCurrentUser } from '@nextcloud/auth'
import { generateOcsUrl } from '@nextcloud/router'

export default {
Expand Down Expand Up @@ -118,15 +120,25 @@ export default {
},
resolve() {
const match = (new RegExp(URL_PATTERN).exec(this.text.trim()))
const isPublic = getCurrentUser() === null
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=${getSharingToken()}`)
: 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: getSharingToken(),
})
: axios.post(generateOcsUrl('references/extract'), {
text: this.text,
resolve: true,
limit: this.limit,
})
},
},
}
Expand Down

0 comments on commit f57e30d

Please sign in to comment.