Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/files_pdfviewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-main.js.map

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions src/services/uploadPdfFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import { getRequestToken } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import { encodePath } from '@nextcloud/paths'
import { getSharingToken } from '@nextcloud/sharing/public'
import { getRootPath } from '../utils/davUtils.js'
import { getRootPath, isPublic } from '../utils/davUtils.js'

/**
* Upload the given contents of a PDF file to the given filename.
Expand All @@ -32,18 +31,11 @@ export default async function(filename, data) {
const requestConfig = {
headers: {
'Content-Type': 'application/pdf',
// Not needed for public pages, although there is no problem if it
// is set.
requesttoken: getRequestToken(),
// requesttoken is only needed for authenticated users (CSRF protection).
// Public shares authenticate via the token in the DAV URL path.
...(!isPublic() && { requesttoken: getRequestToken() }),
},
}
if (getSharingToken()) {
requestConfig.auth = {
// Password is not needed due to "public_link_authenticated" being
// set in the session when the share was loaded.
username: getSharingToken(),
}
}

// Uploading file with nextcloud axios. This will create a new file version
// if versions app is installed.
Expand Down
21 changes: 5 additions & 16 deletions src/utils/davUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,19 @@
*/
import { getCurrentUser } from '@nextcloud/auth'
import { generateRemoteUrl } from '@nextcloud/router'
import { getSharingToken } from '@nextcloud/sharing/public'

/**
* Get the current dav root path
* e.g /remote.php/dav/files/USERID
* or /public.php/webdav for public shares
* or /public.php/dav/files/SHARING_TOKEN for public shares
*/
export function getRootPath() {
if (!isPublic()) {
return generateRemoteUrl(`dav${getUserRoot()}`)
} else {
return generateRemoteUrl('webdav').replace('/remote.php', '/public.php')
}
}

/**
* Get the user root path relative to
* the dav service endpoint
*/
export function getUserRoot() {
const davUrl = generateRemoteUrl('dav')
if (isPublic()) {
throw new Error('No user logged in')
return davUrl.replace('/remote.php', '/public.php') + `/files/${getSharingToken()}`
}

return `/files/${getCurrentUser()?.uid}`
return davUrl + `/files/${getCurrentUser().uid}`
}

/**
Expand Down
Loading