Skip to content
Open
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
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actually needed for public pages now? At least in a quick test it seems to be working fine even if requesttoken is not passed 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your domain knowledge is better here than mine, I would have to dive back into the code and refresh myself 😬

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really... I asked because I do not really know and I did not want to dive into the server code myself 😅

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need to test this again to see

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@susnux do you want the getRootPath change in this PR but with a separate commit? (I presume for CL)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@susnux I made that change. I tested:

auth'd user needs the token
public not

previously it was sent for both, I changed it so it is only sent for auth'd users

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