Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(downloads): simplify video controls and download linked files (#8661)

gbirman336787d6fee2
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 8c1a9baac7..eb46854451 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -419,10 +419,12 @@ instance proxy retains `/cognition`, `/scheduled-action`, and `/preview`.
## File downloads
-Channel videos and Drive video/image/code/canvas/unknown previews share
+Channel videos, linked video previews, and Drive video/image/code/canvas/unknown previews share
`createFileDownload` and `FileDownloadButton`. Keep menu and visible controls
bound to the same controller. Download hands off directly to browser downloads
-or the native save picker; keep Share separate and do not add a custom
+or the native save picker. Show channel Download on hover or keyboard focus,
+always on touch, without a footer. Keep system Share inside the touch Download
+menu; desktop Share belongs to Macro permissions. Do not add a custom
confirmation sheet. Snapshot file/version before loading, cancel on disposal or
selection change, and preserve original filenames from static-file metadata.
Native Android and iOS use bounded byte exports. Older iOS binaries use Web
@@ -430,6 +432,7 @@ Share until the optional file-export bridge ships. If browser activation expires
while preparing a share, retain the bytes and let the same action's next tap
open the system sheet synchronously. Browser success means handoff, not confirmed
disk completion. See the native bridge's `tauri/file_export_plugin/AGENTS.md`.
+Keep download confirmations title-only.
The backend-free browser regression downloads real fixture bytes from channel
cards, the expanded viewer, and the shared Drive/standalone header on desktop,
diff --git a/apps/web/src/features/channel/Media/MediaGrid.tsx b/apps/web/src/features/channel/Media/MediaGrid.tsx
index 73dabfa8d4..bdfca78540 100644
--- a/apps/web/src/features/channel/Media/MediaGrid.tsx
+++ b/apps/web/src/features/channel/Media/MediaGrid.tsx
@@ -93,7 +93,7 @@ function MessageVideoTile(props: { item: MediaItem; onOpen: () => void }) {
return (
<div class="flex min-w-0 max-w-120 flex-col overflow-hidden rounded-2xl border border-edge bg-surface">
- <div class="group relative flex min-h-20 max-h-120 min-w-0 overflow-hidden">
+ <div class="group/video relative flex min-h-20 max-h-120 min-w-0 overflow-hidden">
<Show
when={isInlinePlaying()}
fallback={
@@ -135,7 +135,13 @@ function MessageVideoTile(props: { item: MediaItem; onOpen: () => void }) {
height={videoHeight()}
/>
</Show>
- <div class="absolute right-2 top-2 z-10">
+ <div
+ class={cn(
+ 'absolute right-2 top-2 z-10 flex items-center rounded-full bg-surface/90 opacity-0 transition-opacity group-hover/video:opacity-100 group-focus-within/video:opacity-100 touch:opacity-100',
+ download.phase() !== 'idle' && 'opacity-100'
+ )}
+ >
+ <FileDownloadButton download={download} iconOnly />
<Button
variant="ghost"
size="icon-md"
@@ -149,17 +155,6 @@ function MessageVideoTile(props: { item: MediaItem; onOpen: () => void }) {
</Button>
</div>
</div>
- <div class="flex items-center justify-between gap-2 border-t border-edge px-3 py-2">
- <span
- class="min-w-0 truncate text-sm text-ink-muted"
- title={download.name() || 'Video'}
- >
- {download.name() || 'Video'}
- </span>
- <div class="flex shrink-0 items-center">
- <FileDownloadButton download={download} />
- </div>
- </div>
</div>
);
}
diff --git a/apps/web/src/features/drive-view/queries/file-document.ts b/apps/web/src/features/drive-view/queries/file-document.ts
deleted file mode 100644
index 2fae9cce2e..0000000000
--- a/apps/web/src/features/drive-view/queries/file-document.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import { throwOnErr } from '@core/util/result';
-import { storageServiceClient } from '@service-storage/client';
-import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel';
-import type { DocumentMetadata } from '@service-storage/generated/schemas/documentMetadata';
-import {
- type FetchProgress,
- fetchPresigned,
- fetchPresignedBlobWithProgress,
-} from '@service-storage/util/fetchPresigned';
-import { getPresignedUrl } from '@service-storage/util/presignedUrl';
-
-export type FileDocumentData = {
- documentMetadata: DocumentMetadata;
- userAccessLevel: AccessLevel;
-};
-
-export type GetFileBlobOptions = {
- signal?: AbortSignal;
- onProgress?: (progress: FetchProgress) => void;
-};
-
-export async function loadFileDocumentData(
- documentId: string
-): Promise<FileDocumentData> {
- return throwOnErr(() =>
- storageServiceClient.getDocumentMetadata({ documentId })
- );
-}
-
-export function getFileDocumentUrl(data: {
- documentId: string;
- documentVersionId: number;
-}): Promise<string> {
- return getPresignedUrl({
- documentId: data.documentId,
- versionId: data.documentVersionId,
- });
-}
-
-export async function getFileDocumentBlob(
- data: {
- documentId: string;
- documentVersionId: number;
- },
- options?: GetFileBlobOptions
-): Promise<Blob> {
- const url = await getFileDocumentUrl(data);
- options?.signal?.throwIfAborted();
- return throwOnErr(() =>
- options?.onProgress
- ? fetchPresignedBlobWithProgress(url, options.onProgress, {
- signal: options.signal,
- })
- : fetchPresigned(url, 'blob', { signal: options?.signal })
- );
-}
diff --git a/apps/web/src/features/drive-view/queries/unknown-document.ts b/apps/web/src/features/drive-view/queries/unknown-document.ts
index 73695eb57f..01fdaaa458 100644
--- a/apps/web/src/features/drive-view/queries/unknown-document.ts
+++ b/apps/web/src/features/drive-view/queries/unknown-document.ts
@@ -1,4 +1,7 @@
-import { type FileDocumentData, loadFileDocumentData } from './file-document';
+import {
+ type FileDocumentData,
+ loadFileDocumentData,
+} from '@queries/storage/file-document';
export type UnknownDocumentData = FileDocumentData;
diff --git a/apps/web/src/features/drive-view/queries/video-document.ts b/apps/web/src/features/drive-view/queries/video-document.ts
index 7aef0ca532..31a5b27c0f 100644
--- a/apps/web/src/features/drive-view/queries/video-document.ts
+++ b/apps/web/src/features/drive-view/queries/video-document.ts
@@ -3,7 +3,7 @@ import {
type FileDocumentData,
getFileDocumentUrl,
loadFileDocumentData,
-} from './file-document';
+} from '@queries/storage/file-document';
export type VideoDocumentData = FileDocumentData & {
videoUrl?: string;
diff --git a/apps/web/src/features/drive-view/views/UnknownDetail.tsx b/apps/web/src/features/drive-view/views/UnknownDetail.tsx
index 5da797df1c..45034be113 100644
--- a/apps/web/src/features/drive-view/views/UnknownDetail.tsx
+++ b/apps/web/src/features/drive-view/views/UnknownDetail.tsx
@@ -4,10 +4,10 @@ import { useShareModal } from '@core/component/TopBar/shareModal';
import { createFileDownload } from '@core/util/createFileDownload';
import { fireAndForget } from '@core/util/fireAndForget';
import { catchToResult } from '@core/util/result';
+import { getFileDocumentBlob } from '@queries/storage/file-document';
import type { JSX } from 'solid-js';
import { FileDetailLayout, FileDetailLoadGate } from '../components/FileDetail';
import { downloadFileOperation } from '../components/file-detail-operations';
-import { getFileDocumentBlob } from '../queries/file-document';
import {
loadUnknownDocument,
type UnknownDocumentData,
diff --git a/apps/web/src/features/drive-view/views/VideoDetail.tsx b/apps/web/src/features/drive-view/views/VideoDetail.tsx
index 1faa8445d6..56c714e5e2 100644
--- a/apps/web/src/features/drive-view/views/VideoDetail.tsx
+++ b/apps/web/src/features/drive-view/views/VideoDetail.tsx
@@ -2,10 +2,10 @@ import { VideoContent } from '@block-video/component/VideoContent';
import { createFileDownload } from '@core/util/createFileDownload';
import { fireAndForget } from '@core/util/fireAndForget';
import { catchToResult } from '@core/util/result';
+import { getFileDocumentBlob } from '@queries/storage/file-document';
import type { JSX } from 'solid-js';
import { FileDetailLayout, FileDetailLoadGate } from '../components/FileDetail';
import { downloadFileOperation } from '../components/file-detail-operations';
-import { getFileDocumentBlob } from '../queries/file-document';
import {
loadVideoDocument,
type VideoDocumentData,
diff --git a/apps/web/src/lib/core/component/DocumentDownloadButton.tsx b/apps/web/src/lib/core/component/DocumentDownloadButton.tsx
new file mode 100644
index 0000000000..058d6a7a78
--- /dev/null
+++ b/apps/web/src/lib/core/component/DocumentDownloadButton.tsx
@@ -0,0 +1,42 @@
+import { createFileDownload } from '@core/util/createFileDownload';
+import { catchToResult } from '@core/util/result';
+import {
+ getFileDocumentBlob,
+ loadFileDocumentData,
+} from '@queries/storage/file-document';
+import { formatDocumentName } from '@service-storage/util/filename';
+import { FileDownloadButton } from './FileDownload';
+
+/** Downloads a linked file without opening its viewer or loading it on hover. */
+export function DocumentDownloadButton(props: { documentId: string }) {
+ const download = createFileDownload(() => {
+ const documentId = props.documentId;
+ return {
+ id: documentId,
+ name: 'download',
+ load: (options) =>
+ catchToResult(async () => {
+ const { documentMetadata } = await loadFileDocumentData(
+ documentId,
+ options
+ );
+ options.signal.throwIfAborted();
+ return {
+ blob: await getFileDocumentBlob(
+ {
+ documentId,
+ documentVersionId: documentMetadata.documentVersionId,
+ },
+ options
+ ),
+ name: formatDocumentName(
+ documentMetadata.documentName || 'download',
+ documentMetadata.fileType,
+ { caseInsensitiveSuffix: true }
+ ),
+ };
+ }),
+ };
+ });
+ return <FileDownloadButton download={download} iconOnly />;
+}
diff --git a/apps/web/src/lib/core/component/DocumentPreview.tsx b/apps/web/src/lib/core/component/DocumentPreview.tsx
index b5fd4dd3b1..5a81383f7c 100644
--- a/apps/web/src/lib/core/component/DocumentPreview.tsx
+++ b/apps/web/src/lib/core/component/DocumentPreview.tsx
@@ -83,6 +83,7 @@ import { Dynamic } from 'solid-js/web';
import { formatDate } from '../util/date';
import NotFound from './AccessErrorViews/NotFound';
import Unauthorized from './AccessErrorViews/Unauthorized';
+import { DocumentDownloadButton } from './DocumentDownloadButton';
import {
DocumentPreviewIconSkeleton,
DocumentPreviewSkeleton,
@@ -749,12 +750,15 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {
const renderActionButtons = () => (
<Item.Actions
- class="col-start-3 row-start-1 h-5"
+ class="col-start-3 row-start-1"
onClick={(event) => event.stopPropagation()}
>
+ <Show when={targetBlockType() === 'video'}>
+ <DocumentDownloadButton documentId={props.documentInfo.id} />
+ </Show>
<Dropdown open={menuOpen()} onOpenChange={setMenuOpen}>
<Dropdown.Trigger
- size="icon-sm"
+ size="icon-md"
variant="ghost"
aria-label="Reference actions"
>
diff --git a/apps/web/src/lib/core/component/FileDownload.tsx b/apps/web/src/lib/core/component/FileDownload.tsx
index b230077230..d7401520d6 100644
--- a/apps/web/src/lib/core/component/FileDownload.tsx
+++ b/apps/web/src/lib/core/component/FileDownload.tsx
@@ -1,72 +1,116 @@
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import type { FileDownloadController } from '@core/util/createFileDownload';
import { fireAndForget } from '@core/util/fireAndForget';
import DownloadIcon from '@phosphor/download-simple.svg';
import ShareIcon from '@phosphor/export.svg';
import SpinnerIcon from '@phosphor/spinner.svg';
-import { Button } from '@ui';
-import { Show } from 'solid-js';
+import XIcon from '@phosphor/x.svg';
+import { Button, Dropdown } from '@ui';
+import { createSignal, Show } from 'solid-js';
+import { useHoldParentHoverCardOpen } from './HoverCard';
export function FileDownloadButton(props: {
download: FileDownloadController;
+ iconOnly?: boolean;
}) {
+ const [menuOpen, setMenuOpen] = createSignal(false);
+ useHoldParentHoverCardOpen(() => menuOpen() || props.download.busy());
const preparing = () => {
const { loaded, total } = props.download.progress();
return total > 0
? `Preparing ${Math.min(100, Math.round((loaded / total) * 100))}%`
: 'Preparing…';
};
- const saveBusy = () =>
- props.download.busy() && props.download.action() === 'save';
- const shareBusy = () =>
- props.download.busy() && props.download.action() === 'share';
+ const saveLabel = () =>
+ props.download.phase() === 'error'
+ ? 'Retry download'
+ : props.download.phase() === 'ready' && props.download.action() === 'save'
+ ? 'Save file'
+ : 'Download';
+ const label = () => (props.download.busy() ? preparing() : saveLabel());
+ const start = async (action: 'save' | 'share' = 'save') => {
+ await props.download.start(action);
+ if (props.download.phase() === 'idle') setMenuOpen(false);
+ };
+ const save = () => fireAndForget(start(), 'file-download');
+ const icon = () => (
+ <Show when={props.download.busy()} fallback={<DownloadIcon />}>
+ <SpinnerIcon class="animate-spin" />
+ </Show>
+ );
+
return (
- <>
- <Show when={!props.download.busy() || props.download.action() === 'save'}>
- <Button
- variant="ghost"
- size="md"
- disabled={props.download.busy()}
- onClick={() => fireAndForget(props.download.start(), 'file-download')}
- >
- <Show when={saveBusy()} fallback={<DownloadIcon />}>
- <SpinnerIcon class="animate-spin" />
+ <Show
+ when={isTouchDevice() && props.download.canOfferShare()}
+ fallback={
+ <>
+ <Button
+ variant="ghost"
+ size={props.iconOnly ? 'icon-md' : 'md'}
+ label={label()}
+ disabled={props.download.busy()}
+ onClick={save}
+ >
+ {icon()}
+ <Show when={!props.iconOnly}>{label()}</Show>
+ </Button>
+ <Show when={props.download.busy()}>
+ <Button
+ variant="ghost"
+ size={props.iconOnly ? 'icon-md' : 'md'}
+ label="Cancel download"
+ onClick={props.download.cancel}
+ >
+ <Show when={props.iconOnly} fallback="Cancel">
+ <XIcon />
+ </Show>
+ </Button>
</Show>
- {saveBusy()
- ? preparing()
- : props.download.phase() === 'error' &&
- props.download.action() === 'save'
- ? 'Retry download'
- : props.download.phase() === 'ready' &&
- props.download.action() === 'save'
- ? 'Save file'
- : 'Download'}
- </Button>
- </Show>
- <Show
- when={
- props.download.canOfferShare() &&
- (!props.download.busy() || props.download.action() === 'share')
- }
- >
- <Button
+ </>
+ }
+ >
+ <Dropdown open={menuOpen()} onOpenChange={setMenuOpen}>
+ <Dropdown.Trigger
variant="ghost"
- size="md"
- disabled={props.download.busy()}
- onClick={() =>
- fireAndForget(props.download.start('share'), 'file-download')
- }
+ size={props.iconOnly ? 'icon-md' : 'md'}
+ label={label()}
>
- <Show when={shareBusy()} fallback={<ShareIcon />}>
- <SpinnerIcon class="animate-spin" />
+ {icon()}
+ <Show when={!props.iconOnly}>{label()}</Show>
+ </Dropdown.Trigger>
+ <Dropdown.Content blockingBackdrop>
+ <Dropdown.Item
+ class="touch:min-h-11"
+ closeOnSelect={false}
+ disabled={props.download.busy()}
+ onSelect={save}
+ >
+ <DownloadIcon class="size-4" />
+ {props.download.busy() && props.download.action() === 'save'
+ ? preparing()
+ : saveLabel()}
+ </Dropdown.Item>
+ <Dropdown.Item
+ class="touch:min-h-11"
+ closeOnSelect={false}
+ disabled={props.download.busy()}
+ onSelect={() => fireAndForget(start('share'), 'file-download')}
+ >
+ <ShareIcon class="size-4" />
+ {props.download.busy() && props.download.action() === 'share'
+ ? preparing()
+ : 'Share'}
+ </Dropdown.Item>
+ <Show when={props.download.busy()}>
+ <Dropdown.Item
+ class="touch:min-h-11"
+ onSelect={props.download.cancel}
+ >
+ Cancel
+ </Dropdown.Item>
</Show>
- {shareBusy() ? preparing() : 'Share'}
- </Button>
- </Show>
- <Show when={props.download.busy()}>
- <Button variant="ghost" size="md" onClick={props.download.cancel}>
- Cancel
- </Button>
- </Show>
- </>
+ </Dropdown.Content>
+ </Dropdown>
+ </Show>
);
}
diff --git a/apps/web/src/lib/core/component/FileDownload/browser-test/download.browser.e2e.ts b/apps/web/src/lib/core/component/FileDownload/browser-test/download.browser.e2e.ts
index b2e4915a82..4e0bb0f21b 100644
--- a/apps/web/src/lib/core/component/FileDownload/browser-test/download.browser.e2e.ts
+++ b/apps/web/src/lib/core/component/FileDownload/browser-test/download.browser.e2e.ts
@@ -114,9 +114,53 @@ test('the shared Drive and standalone header downloads through its visible actio
);
});
-test('shares from a separate action after a transfer outlives browser activation', async ({
+test('downloads a linked video using its current version and original extension', async ({
page,
}) => {
+ const video = await readFile(videoPath);
+ await page.route('**/documents/linked-video', (route) =>
+ route.fulfill({
+ json: {
+ data: {
+ documentMetadata: {
+ documentId: 'linked-video',
+ documentVersionId: 42,
+ documentName: 'birds folder',
+ fileType: 'webm',
+ },
+ userAccessLevel: 'view',
+ },
+ },
+ })
+ );
+ await page.route('**/documents/linked-video/location_v3?*', (route) => {
+ expect(
+ new URL(route.request().url()).searchParams.get('document_version_id')
+ ).toBe('42');
+ return route.fulfill({
+ json: {
+ type: 'presignedUrl',
+ presignedUrl: new URL('/original-video', page.url()).href,
+ content: { state: 'ready' },
+ },
+ });
+ });
+ await page.route('**/original-video', (route) =>
+ route.fulfill({ body: video, contentType: 'video/webm' })
+ );
+ await page.goto('/?document');
+ const saved = page.waitForEvent('download');
+ await page.getByRole('button', { name: 'Download', exact: true }).click();
+ const file = await saved;
+ expect(file.suggestedFilename()).toBe('birds folder.webm');
+ expect(await readFile((await file.path())!)).toEqual(video);
+});
+
+test('shares from the mobile Download menu after a transfer outlives browser activation', async ({
+ page,
+ isMobile,
+}) => {
+ test.skip(!isMobile, 'System sharing is inside the touch Download menu');
await page.addInitScript(() => {
Object.defineProperty(navigator, 'canShare', { value: () => true });
Object.defineProperty(navigator, 'userActivation', {
@@ -132,7 +176,9 @@ test('shares from a separate action after a transfer outlives browser activation
});
});
await page.reload();
- const share = page.getByRole('button', { name: 'Share', exact: true });
+ const trigger = page.getByRole('button', { name: 'Download', exact: true });
+ await trigger.click();
+ const share = page.getByRole('menuitem', { name: 'Share', exact: true });
await share.click();
await expect(
page.getByText('File ready — tap Share', { exact: true })
@@ -142,10 +188,14 @@ test('shares from a separate action after a transfer outlives browser activation
).toBeUndefined();
await expect(page.getByRole('dialog')).toHaveCount(0);
const saving = page.waitForEvent('download');
- const download = page.getByRole('button', { name: 'Download', exact: true });
+ const download = page.getByRole('menuitem', {
+ name: 'Download',
+ exact: true,
+ });
await download.click();
expect((await saving).suggestedFilename()).toBe('Team demo.webm');
- await expect(download).toBeFocused();
+ await expect(trigger).toBeFocused();
+ await trigger.click();
await share.click();
await expect(
page.getByText('File ready — tap Share', { exact: true })
@@ -154,7 +204,7 @@ test('shares from a separate action after a transfer outlives browser activation
await expect
.poll(() => page.evaluate(() => Reflect.get(window, 'sharedFileName')))
.toBe('Team demo.webm');
- await expect(share).toBeFocused();
+ await expect(trigger).toBeFocused();
await expect(page.locator('body')).toHaveJSProperty(
'scrollWidth',
await page.locator('body').evaluate((body) => body.clientWidth)
diff --git a/apps/web/src/lib/core/component/FileDownload/browser-test/main.tsx b/apps/web/src/lib/core/component/FileDownload/browser-test/main.tsx
index d575f7dcd1..51126e6ae7 100644
--- a/apps/web/src/lib/core/component/FileDownload/browser-test/main.tsx
+++ b/apps/web/src/lib/core/component/FileDownload/browser-test/main.tsx
@@ -2,6 +2,7 @@ import { MediaPreview } from '@channel/Message/MediaPreview';
import { mediaDownloadSource } from '@channel/queries/static-media-download';
import { FileDownloadHeader } from '@components/app/FileDownloadHeader';
import { SidePanel } from '@components/app/side-panel/SidePanel';
+import { DocumentDownloadButton } from '@core/component/DocumentDownloadButton';
import { ToastRegion } from '@core/component/Toast/ToastRegion';
import { staticFileIdEndpoint } from '@core/constant/servers';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
@@ -40,18 +41,28 @@ render(
<Show
when={location.search.includes('header')}
fallback={
- <MediaPreview
- items={[
- {
- id: 'download-video',
- kind: 'video',
- width: 480,
- height: 270,
- src: staticFileIdEndpoint('download-video'),
- fullSrc: staticFileIdEndpoint('download-video'),
- },
- ]}
- />
+ <Show
+ when={location.search.includes('document')}
+ fallback={
+ <MediaPreview
+ items={[
+ {
+ id: 'download-video',
+ kind: 'video',
+ width: 480,
+ height: 270,
+ src: staticFileIdEndpoint('download-video'),
+ fullSrc: staticFileIdEndpoint('download-video'),
+ },
+ ]}
+ />
+ }
+ >
+ <div class="flex items-center gap-2">
+ <span>birds folder</span>
+ <DocumentDownloadButton documentId="linked-video" />
+ </div>
+ </Show>
}
>
<HeaderFixture />
diff --git a/apps/web/src/lib/core/component/FileDownload/browser-test/vite.config.ts b/apps/web/src/lib/core/component/FileDownload/browser-test/vite.config.ts
index b588f734db..f8ef8672cf 100644
--- a/apps/web/src/lib/core/component/FileDownload/browser-test/vite.config.ts
+++ b/apps/web/src/lib/core/component/FileDownload/browser-test/vite.config.ts
@@ -11,6 +11,7 @@ const webDirectory = fileURLToPath(
);
export default defineConfig({
root: directory,
+ cacheDir: `${directory}/.vite`,
plugins: [
tailwindcss(),
solid(),
diff --git a/apps/web/src/lib/core/util/createFileDownload.ts b/apps/web/src/lib/core/util/createFileDownload.ts
index 35087eccf7..13880c185b 100644
--- a/apps/web/src/lib/core/util/createFileDownload.ts
+++ b/apps/web/src/lib/core/util/createFileDownload.ts
@@ -22,6 +22,7 @@ export type DownloadSource = {
load: (options: {
signal: AbortSignal;
onProgress: (progress: FetchProgress) => void;
+ span: Span;
}) => Promise<Result<{ blob: Blob; name?: string }, ResultError<string>[]>>;
};
@@ -143,13 +144,7 @@ export function createFileDownload(
toast.success(
isPlatform('android') || nativeIos
? 'File saved'
- : 'Download started',
- {
- subtext:
- isPlatform('android') || nativeIos
- ? ready.name
- : `${ready.name} — check your browser or device downloads.`,
- }
+ : 'Download started'
);
}
finishTrace('handed_off');
@@ -241,6 +236,7 @@ export function createFileDownload(
try {
const result = await snapshot.load({
signal: request.signal,
+ span,
onProgress: (next) => {
if (controller === request) setProgress(next);
},
diff --git a/apps/web/src/lib/queries/storage/file-document.ts b/apps/web/src/lib/queries/storage/file-document.ts
new file mode 100644
index 0000000000..68d4bf8c8d
--- /dev/null
+++ b/apps/web/src/lib/queries/storage/file-document.ts
@@ -0,0 +1,93 @@
+import { throwOnErr } from '@core/util/result';
+import { type Span, Telemetry } from '@macro-inc/observability';
+import { storageServiceClient } from '@service-storage/client';
+import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel';
+import type { DocumentMetadata } from '@service-storage/generated/schemas/documentMetadata';
+import {
+ type FetchProgress,
+ fetchPresigned,
+ fetchPresignedBlobWithProgress,
+} from '@service-storage/util/fetchPresigned';
+import { getPresignedUrl } from '@service-storage/util/presignedUrl';
+
+export type FileDocumentData = {
+ documentMetadata: DocumentMetadata;
+ userAccessLevel: AccessLevel;
+};
+
+export type GetFileBlobOptions = {
+ signal?: AbortSignal;
+ onProgress?: (progress: FetchProgress) => void;
+ span?: Span;
+};
+
+export async function loadFileDocumentData(
+ documentId: string,
+ options?: GetFileBlobOptions
+): Promise<FileDocumentData> {
+ return (options?.span ?? Telemetry).span('file.metadata', async (span) => {
+ span.setAttr('document.id', documentId);
+ try {
+ return await throwOnErr(() =>
+ storageServiceClient.getDocumentMetadata({
+ documentId,
+ init: { signal: options?.signal },
+ })
+ );
+ } catch (error) {
+ if (!options?.signal?.aborted) span.error(error);
+ throw error;
+ }
+ });
+}
+
+export function getFileDocumentUrl(
+ data: {
+ documentId: string;
+ documentVersionId: number;
+ },
+ parentSpan?: Span
+): Promise<string> {
+ return (parentSpan ?? Telemetry).span('file.location', async (span) => {
+ span.setAttr('document.id', data.documentId);
+ span.setAttr('document.version_id', data.documentVersionId);
+ try {
+ return await getPresignedUrl({
+ documentId: data.documentId,
+ versionId: data.documentVersionId,
+ });
+ } catch (error) {
+ span.error(error);
+ throw error;
+ }
+ });
+}
+
+export async function getFileDocumentBlob(
+ data: {
+ documentId: string;
+ documentVersionId: number;
+ },
+ options?: GetFileBlobOptions
+): Promise<Blob> {
+ const url = await getFileDocumentUrl(data, options?.span);
+ options?.signal?.throwIfAborted();
+ return (options?.span ?? Telemetry).span('file.transfer', async (span) => {
+ span.setAttr('document.id', data.documentId);
+ span.setAttr('document.version_id', data.documentVersionId);
+ try {
+ const blob = await throwOnErr(() =>
+ options?.onProgress
+ ? fetchPresignedBlobWithProgress(url, options.onProgress, {
+ signal: options.signal,
+ })
+ : fetchPresigned(url, 'blob', { signal: options?.signal })
+ );
+ span.setAttr('file.size', blob.size);
+ return blob;
+ } catch (error) {
+ if (!options?.signal?.aborted) span.error(error);
+ throw error;
+ }
+ });
+}
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 93b8d38c5c..eb9d36554c 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -1343,8 +1343,11 @@ When Databases is enabled, type `/query` in a channel message or thread reply an
## Downloading channel videos
-Video messages show **Download** below the player on desktop and touch devices. The expanded viewer has the same action. These retrieve the
-original bytes and filename from static-file metadata; they do not record or
-transcode playback. If the metadata is unavailable, the fallback extension comes
-from the response MIME type. See [Downloading files](files.md#downloading-files)
+Video messages show **Download** over the player on hover or keyboard focus;
+the control stays visible on touch devices. There is no footer below the video.
+The expanded viewer has the same action. These retrieve the original bytes and
+filename from static-file metadata; they do not record or transcode playback.
+If the metadata is unavailable, the fallback extension comes from the response
+MIME type. Linked video preview cards also offer Download, using the document's
+current version, name, and file type. See [Downloading files](files.md#downloading-files)
for progress, cancellation, retries, and mobile save/share verification.
diff --git a/docs/agent-guide/files.md b/docs/agent-guide/files.md
index 0786289e69..f93a2ddbbd 100644
--- a/docs/agent-guide/files.md
+++ b/docs/agent-guide/files.md
@@ -162,8 +162,9 @@ returning from an opened file.
Open a video, image, code file, canvas, or other uploaded file in Drive. Its
header exposes **Download** on desktop, phone, and tablet. The file menu uses
the same action. Video routes also expose it in their header; channel videos
-expose it below the player and in the expanded viewer. Playing, downloading,
-and sharing a video are separate actions.
+expose it over the player on hover or keyboard focus (always visible on touch)
+and in the expanded viewer. Linked video cards also offer Download in their
+preview header without opening the file.
- Click Download once. The control shows preparation progress when the server
provides a length, disables repeat clicks, and offers Cancel. Browser users
@@ -172,9 +173,11 @@ and sharing a video are separate actions.
- **Download started** means the browser accepted the file; check its downloads
UI for the location and final completion. **File saved** is reserved for a
completed native save. Retry download remains available after a fetch failure.
-- **Share**, where supported, opens the system share sheet. If a browser's
+- On phones and tablets that support system sharing, **Download** opens a menu
+ with **Download** and **Share**. Share opens the system share sheet; desktop
+ headers keep only Macro's existing Share control for access and links. If a browser's
user gesture expires during loading, a ready notice asks for another tap on
- Share; that tap uses the prepared bytes without another network request.
+ Share in the open menu; that tap uses the prepared bytes without another network request.
No Macro download dialog appears. Cancelling a chooser keeps the file ready
for another attempt and does not report success.
- Installed iOS binaries without the optional file-export bridge use the system