-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
302 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,22 +156,25 @@ | |
"@reforged/maker-appimage/@electron-forge/maker-base": "7.5.0", | ||
"macos-alias": "npm:@napi-rs/[email protected]", | ||
"fs-xattr": "npm:@napi-rs/xattr@latest", | ||
"@blocksuite/affine": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/all", | ||
"@blocksuite/affine-block-embed": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-embed", | ||
"@blocksuite/affine-block-list": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-list", | ||
"@blocksuite/affine-block-paragraph": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-paragraph", | ||
"@blocksuite/affine-block-surface": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/block-surface", | ||
"@blocksuite/affine-components": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/components", | ||
"@blocksuite/data-view": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/data-view", | ||
"@blocksuite/affine-model": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/model", | ||
"@blocksuite/affine-shared": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/shared", | ||
"@blocksuite/affine-widget-scroll-anchoring": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/affine/widget-scroll-anchoring", | ||
"@blocksuite/blocks": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/blocks", | ||
"@blocksuite/block-std": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/block-std", | ||
"@blocksuite/global": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/global", | ||
"@blocksuite/inline": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/inline", | ||
"@blocksuite/store": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/store", | ||
"@blocksuite/sync": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/framework/sync", | ||
"@blocksuite/presets": "portal:/C:/Users/xp/Documents/GitHub/blocksuite/packages/presets" | ||
"@blocksuite/affine": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/all", | ||
"@blocksuite/affine-block-embed": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-embed", | ||
"@blocksuite/affine-block-list": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-list", | ||
"@blocksuite/affine-block-paragraph": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-paragraph", | ||
"@blocksuite/affine-block-surface": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/block-surface", | ||
"@blocksuite/affine-components": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/components", | ||
"@blocksuite/data-view": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/data-view", | ||
"@blocksuite/affine-model": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/model", | ||
"@blocksuite/affine-shared": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/shared", | ||
"@blocksuite/affine-widget-scroll-anchoring": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/affine/widget-scroll-anchoring", | ||
"@blocksuite/blocks": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/blocks", | ||
"@blocksuite/block-std": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/block-std", | ||
"@blocksuite/global": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/global", | ||
"@blocksuite/inline": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/inline", | ||
"@blocksuite/store": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/store", | ||
"@blocksuite/sync": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/framework/sync", | ||
"@blocksuite/presets": "portal:/Users/fundon/dev/toeverything/blocksuite/packages/presets", | ||
"@toeverything/pdf-viewer": "portal:/Users/fundon/dev/toeverything/pdfium-builder/packages/pdf-viewer", | ||
"@toeverything/pdf-viewer-types": "portal:/Users/fundon/dev/toeverything/pdfium-builder/packages/types", | ||
"@toeverything/pdfium": "portal:/Users/fundon/dev/toeverything/pdfium-builder/packages/pdfium" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 21 additions & 13 deletions
34
packages/frontend/component/src/components/attachment-viewer/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import { type ReactElement, useState } from 'react'; | ||
import { humanFileSize } from '@blocksuite/affine-shared/utils'; | ||
import type { AttachmentBlockModel } from '@blocksuite/blocks'; | ||
import { type ReactElement, useMemo } from 'react'; | ||
|
||
import { Error } from './error'; | ||
import * as styles from './styles.css'; | ||
import { Titlebar } from './titlebar'; | ||
import { Viewer } from './viewer'; | ||
|
||
export const AttachmentViewer = (): ReactElement => { | ||
const [isPDF] = useState(true); | ||
export type AttachmentViewerProps = { | ||
model: AttachmentBlockModel; | ||
}; | ||
|
||
export const AttachmentViewer = ({ | ||
model, | ||
}: AttachmentViewerProps): ReactElement => { | ||
const attachment = useMemo(() => { | ||
const pieces = model.name.split('.'); | ||
const ext = pieces.pop() || ''; | ||
const name = pieces.join('.'); | ||
const isPDF = ext === 'pdf'; | ||
const filesize = humanFileSize(model.size); | ||
|
||
return { model, name, ext, filesize, isPDF }; | ||
}, [model]); | ||
|
||
return ( | ||
<div className={styles.viewerContainer}> | ||
<Titlebar | ||
id={'0'} | ||
name={'AFFiNE'} | ||
size={10} | ||
unit={'MB'} | ||
ext=".pdf" | ||
zoom={100} | ||
isPDF={isPDF} | ||
/> | ||
{isPDF ? <Viewer /> : <Error isPDF />} | ||
<Titlebar {...attachment} /> | ||
{attachment.isPDF ? <Viewer /> : <Error {...attachment} />} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/frontend/component/src/components/attachment-viewer/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fileTypeFromBuffer } from 'file-type'; | ||
|
||
async function _saveBufferToFile(url: string, filename: string) { | ||
// given input url may not have correct mime type | ||
const blob = await attachmentUrlToBlob(url); | ||
if (!blob) { | ||
return; | ||
} | ||
|
||
const blobUrl = URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = blobUrl; | ||
a.download = filename; | ||
document.body.append(a); | ||
a.click(); | ||
a.remove(); | ||
URL.revokeObjectURL(blobUrl); | ||
} | ||
|
||
async function attachmentUrlToBlob(url: string): Promise<Blob | undefined> { | ||
const buffer = await fetch(url).then(response => { | ||
return response.arrayBuffer(); | ||
}); | ||
|
||
if (!buffer) { | ||
console.warn('Could not get blob'); | ||
return; | ||
} | ||
try { | ||
const type = await fileTypeFromBuffer(buffer); | ||
if (!type) { | ||
return; | ||
} | ||
const blob = new Blob([buffer], { type: type.mime }); | ||
return blob; | ||
} catch (error) { | ||
console.error('Error converting attachment to blob', error); | ||
} | ||
return; | ||
} |
71 changes: 66 additions & 5 deletions
71
packages/frontend/core/src/desktop/pages/workspace/attachment/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.