feat: allow s3 file download/preview from inside apps (#5004)

* feat: allow s3 file download/preview from inside apps

* improve security + handle image preview

* fix build

* fix build
This commit is contained in:
HugoCasa
2025-01-04 01:47:57 +01:00
committed by GitHub
parent e8fcea28ab
commit 0c19171f57
7 changed files with 210 additions and 11 deletions
@@ -47,6 +47,7 @@
export let drawerOpen = false
export let nodeId: string | undefined = undefined
export let language: string | undefined = undefined
export let appPath: string | undefined = undefined
const IMG_MAX_SIZE = 10000000
const TABLE_MAX_SIZE = 5000000
@@ -645,7 +646,7 @@
>
</button>
{:else if !result?.disable_download}
<FileDownload {workspaceId} s3object={result} />
<FileDownload {workspaceId} s3object={result} {appPath} />
<button
class="text-secondary underline text-2xs whitespace-nowrap"
on:click={() => {
@@ -662,7 +663,7 @@
{/if}
</div>
{#if typeof result?.s3 === 'string'}
{#if result?.s3?.endsWith('.parquet') || result?.s3?.endsWith('.csv')}
{#if !appPath && (result?.s3?.endsWith('.parquet') || result?.s3?.endsWith('.csv'))}
{#key result.s3}
<ParqetTableRenderer
disable_download={result?.disable_download}
@@ -676,7 +677,7 @@
<img
alt="preview rendered"
class="w-auto h-full"
src={`/api/w/${workspaceId}/job_helpers/load_image_preview?file_key=${result.s3}` +
src={`/api/w/${workspaceId}/${appPath ? 'apps_u/load_image_preview/' + appPath : 'job_helpers/load_image_preview'}?file_key=${result.s3}` +
(result.storage ? `&storage=${result.storage}` : '')}
/>
</div>
@@ -684,7 +685,7 @@
<div class="h-96 mt-2 border">
<PdfViewer
allowFullscreen
source={`/api/w/${workspaceId}/job_helpers/load_image_preview?file_key=${result.s3}` +
source={`/api/w/${workspaceId}/${appPath ? 'apps_u/load_image_preview/' + appPath : 'job_helpers/load_image_preview'}?file_key=${result.s3}` +
(result.storage ? `&storage=${result.storage}` : '')}
/>
</div>
@@ -24,7 +24,7 @@
export let configuration: RichConfigurations
const requireHtmlApproval = getContext<boolean | undefined>(IS_APP_PUBLIC_CONTEXT_KEY)
const { app, worldStore, componentControl, workspace } =
const { app, worldStore, componentControl, workspace, appPath } =
getContext<AppViewerContext>('AppViewerContext')
let result: any = undefined
@@ -96,6 +96,7 @@
{result}
{requireHtmlApproval}
disableExpand={resolvedConfig?.hideDetails}
appPath={$appPath}
/>
</div>
</div>
@@ -5,6 +5,7 @@
export let s3object: any
export let workspaceId: string | undefined = undefined
export let appPath: string | undefined = undefined
</script>
<a
@@ -12,9 +13,9 @@
border border-dashed border-gray-400 hover:border-blue-500
focus-within:border-blue-500 hover:bg-blue-50 dark:hover:bg-frost-900 focus-within:bg-blue-50
duration-200 rounded-lg p-1 gap-2"
href={`${base}/api/w/${workspaceId ?? $workspaceStore}/job_helpers/download_s3_file?file_key=${
s3object?.s3
}${s3object?.storage ? `&storage=${s3object.storage}` : ''}`}
href={`${base}/api/w/${workspaceId ?? $workspaceStore}${
appPath ? `/apps_u/download_s3_file/${appPath}` : '/job_helpers/download_s3_file'
}?file_key=${s3object?.s3}${s3object?.storage ? `&storage=${s3object.storage}` : ''}`}
download={s3object?.s3.split('/').pop() ?? 'unnamed_download.file'}
>
<Download />