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
3 changes: 3 additions & 0 deletions packages/web-app-epub-reader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default defineWebApplication({
applicationId: appId,
fileContentOptions: {
responseType: 'blob'
},
urlForResourceOptions: {
intent: 'preview'
}
})
},
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-pdf-viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const routes = [
component: AppWrapperRoute(PdfViewer, {
applicationId: 'pdf-viewer',
urlForResourceOptions: {
disposition: 'inline'
disposition: 'inline',
intent: 'preview'
}
}),
name: 'pdf-viewer',
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-preview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default defineWebApplication({
component: AppWrapperRoute(App, {
applicationId: appId,
urlForResourceOptions: {
disposition: 'inline'
disposition: 'inline',
intent: 'preview'
}
}),
name: 'media',
Expand Down
5 changes: 4 additions & 1 deletion packages/web-app-text-editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export default defineWebApplication({
{
path: '/:driveAliasAndItem(.*)?',
component: AppWrapperRoute(TextEditor, {
applicationId: appId
applicationId: appId,
fileContentOptions: {
intent: 'preview'
}
}),
name: 'text-editor',
meta: {
Expand Down
23 changes: 21 additions & 2 deletions packages/web-client/src/webdav/getFileUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ import { ocs } from '../ocs'
import { GetFileInfoFactory } from './getFileInfo'
import { DavProperty } from './constants'

/**
* Add intent query parameter to URL for audit logging
* @param url The original URL
* @param intent The access intent ('preview' or 'download')
* @returns URL with intent parameter added
*/
const addIntentToUrl = (url: string, intent: 'preview' | 'download'): string => {
if (!url) return url
const urlObj = new URL(url, window.location.origin)
urlObj.searchParams.set('intent', intent)
return urlObj.toString()
}

export const GetFileUrlFactory = (
dav: DAV,
getFileContentsFactory: ReturnType<typeof GetFileContentsFactory>,
Expand All @@ -21,11 +34,13 @@ export const GetFileUrlFactory = (
disposition = 'attachment',
version = null,
username = '',
intent = 'download',
...opts
}: {
disposition?: 'inline' | 'attachment'
version?: string
username?: string
intent?: 'preview' | 'download'
} & DAVRequestOptions
): Promise<string> {
// FIXME: re-introduce query parameters
Expand All @@ -40,6 +55,10 @@ export const GetFileUrlFactory = (
if (disposition === 'inline') {
const response = await getFileContentsFactory.getFileContents(space, resource, {
responseType: 'blob',
headers: {
'X-OC-Intent': intent,
...opts.headers
},
...opts
})
return URL.createObjectURL(response.body)
Expand All @@ -56,13 +75,13 @@ export const GetFileUrlFactory = (
}

if (resource.downloadURL) {
return resource.downloadURL
return addIntentToUrl(resource.downloadURL, intent)
}

const { downloadURL } = await getFileInfoFactory.getFileInfo(space, resource, {
davProperties: [DavProperty.DownloadURL]
})
return downloadURL
return addIntentToUrl(downloadURL, intent)
},
revokeUrl: (url: string) => {
if (url && url.startsWith('blob:')) {
Expand Down
3 changes: 2 additions & 1 deletion packages/web-pkg/src/composables/download/useDownloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const useDownloadFile = (options?: DownloadFileOptions) => {
}
const url = await clientService.webdav.getFileUrl(space, file, {
version,
username: userStore.user?.onPremisesSamAccountName
username: userStore.user?.onPremisesSamAccountName,
intent: 'download'
})
triggerDownloadWithFilename(url, file.name)
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions packages/web-pkg/src/services/preview/previewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class PreviewService {
scalingup: options.scalingup || 0,
preview: Object.hasOwnProperty.call(options, 'preview') ? options.preview : 1,
a: Object.hasOwnProperty.call(options, 'a') ? options.a : 1,
intent: 'preview',
...(options.processor && { processor: options.processor }),
...(options.etag && { c: options.etag.replaceAll('"', '') }),
...(options.dimensions && options.dimensions[0] && { x: options.dimensions[0] }),
Expand Down