diff --git a/packages/presentation/src/components/FilePreview.svelte b/packages/presentation/src/components/FilePreview.svelte
index 4397b1173c..00988014c5 100644
--- a/packages/presentation/src/components/FilePreview.svelte
+++ b/packages/presentation/src/components/FilePreview.svelte
@@ -13,18 +13,18 @@
// limitations under the License.
-->
diff --git a/packages/presentation/src/components/FilePreviewPopup.svelte b/packages/presentation/src/components/FilePreviewPopup.svelte
index ddcf2cad2b..5952686a1f 100644
--- a/packages/presentation/src/components/FilePreviewPopup.svelte
+++ b/packages/presentation/src/components/FilePreviewPopup.svelte
@@ -13,7 +13,7 @@
// limitations under the License.
-->
@@ -101,8 +94,8 @@
{/await}
- {#if blob !== undefined}
-
+ {#if file}
+
{/if}
diff --git a/packages/presentation/src/components/PDFViewer.svelte b/packages/presentation/src/components/PDFViewer.svelte
index b1570bd8ec..fcfe753c57 100644
--- a/packages/presentation/src/components/PDFViewer.svelte
+++ b/packages/presentation/src/components/PDFViewer.svelte
@@ -17,11 +17,11 @@
import type { Blob, Ref } from '@hcengineering/core'
import { Button, Dialog, Label, Spinner } from '@hcengineering/ui'
import { createEventDispatcher, onMount } from 'svelte'
- import presentation, { getBlobSrcFor } from '..'
+ import presentation, { getFileUrl } from '..'
import ActionContext from './ActionContext.svelte'
import Download from './icons/Download.svelte'
- export let file: Blob | Ref
| undefined
+ export let file: Ref | undefined
export let name: string
export let contentType: string | undefined
// export let popupOptions: PopupOptions
@@ -45,7 +45,7 @@
})
let download: HTMLAnchorElement
- $: srcRef = getBlobSrcFor(file, name)
+ $: srcRef = file !== undefined ? getFileUrl(file, name) : undefined
$: isImage = contentType !== undefined && contentType.startsWith('image/')
diff --git a/packages/presentation/src/preview.ts b/packages/presentation/src/preview.ts
index 4233c89a2e..2748b849d2 100644
--- a/packages/presentation/src/preview.ts
+++ b/packages/presentation/src/preview.ts
@@ -1,99 +1,36 @@
-import type { Blob, BlobLookup, Ref } from '@hcengineering/core'
-import core, { concatLink } from '@hcengineering/core'
+import type { Blob, Ref } from '@hcengineering/core'
+import { concatLink } from '@hcengineering/core'
import { getMetadata } from '@hcengineering/platform'
-import { getBlobHref, getClient, getCurrentWorkspaceUrl, getFileUrl } from '.'
+import { getCurrentWorkspaceUrl, getFileUrl } from '.'
import presentation from './plugin'
-export interface ProviderPreviewConfig {
- // Identifier of provider
- // If set to '' could be applied to any provider, for example to exclude some 'image/gif' etc from being processing with providers.
- providerId: string
- // Preview url
- // If '' preview is disabled for config.
- previewUrl: string
-
- // Content type markers, will check by containts, if passed, only allow to be used with matched content types.
- contentTypes?: string[]
-}
-
export interface PreviewConfig {
- default?: ProviderPreviewConfig
- previewers: Record
+ previewUrl: string
}
-const defaultPreview = (): ProviderPreviewConfig => ({
- providerId: '',
- previewUrl: `/files/${getCurrentWorkspaceUrl()}?file=:blobId&size=:size`
-})
+const defaultPreview = (): string => `/files/${getCurrentWorkspaceUrl()}?file=:blobId&size=:size`
/**
*
* PREVIEW_CONFIG env variable format.
- * A `;` separated list of triples, providerName|previewUrl|supportedFormats.
-
-- providerName - a provider name should be same as in Storage configuration.
- It coult be empty and it will match by content types.
-- previewUrl - an Url with :workspace, :blobId, :downloadFile, :size placeholders, they will be replaced in UI with an appropriate blob values.
-- supportedFormats - a `,` separated list of file extensions.
-- contentTypes - a ',' separated list of content type patterns.
-
+ * previewUrl - an Url with :workspace, :blobId, :downloadFile, :size placeholders, they will be replaced in UI with an appropriate blob values.
*/
export function parsePreviewConfig (config?: string): PreviewConfig | undefined {
if (config === undefined) {
return
}
- const result: PreviewConfig = { previewers: {} }
- const nolineData = config
- .split('\n')
- .map((it) => it.trim())
- .join(';')
- const configs = nolineData.split(';')
- for (const c of configs) {
- if (c === '') {
- continue // Skip empty lines
- }
- const [provider, url, contentTypes] = c.split('|').map((it) => it.trim())
- const p: ProviderPreviewConfig = {
- providerId: provider,
- previewUrl: url,
- // Allow preview only for images by default
- contentTypes:
- contentTypes !== undefined
- ? contentTypes
- .split(',')
- .map((it) => it.trim())
- .filter((it) => it !== '')
- : ['image/']
- }
-
- if (provider === '*') {
- result.default = p
- } else {
- result.previewers[provider] = [...(result.previewers[provider] ?? []), p]
- }
- }
- return result
+ return { previewUrl: config }
}
export function getPreviewConfig (): PreviewConfig {
return (
(getMetadata(presentation.metadata.PreviewConfig) as PreviewConfig) ?? {
- default: defaultPreview(),
- previewers: {
- '': [
- {
- providerId: '',
- contentTypes: ['image/gif', 'image/apng', 'image/svg'], // Disable gif and apng format preview.
- previewUrl: ''
- }
- ]
- }
+ previewUrl: defaultPreview()
}
)
}
export async function getBlobRef (
- blob: Blob | undefined,
file: Ref,
name?: string,
width?: number
@@ -101,74 +38,30 @@ export async function getBlobRef (
src: string
srcset: string
}> {
- let _blob = blob as BlobLookup
- if (_blob === undefined) {
- _blob = (await getClient().findOne(core.class.Blob, { _id: file })) as BlobLookup
- }
return {
- src: _blob?.downloadUrl ?? getFileUrl(file, name),
- srcset: _blob !== undefined ? getSrcSet(_blob, width) : ''
+ src: getFileUrl(file, name),
+ srcset: getSrcSet(file, width)
}
}
-export async function getBlobSrcSet (_blob: Blob | undefined, file: Ref, width?: number): Promise {
- if (_blob === undefined) {
- _blob = await getClient().findOne(core.class.Blob, { _id: file })
- }
- return _blob !== undefined ? getSrcSet(_blob, width) : ''
+export async function getBlobSrcSet (file: Ref, width?: number): Promise {
+ return getSrcSet(file, width)
}
-/**
- * Select content provider based on content type.
- */
-export function selectProvider (
- blob: Blob,
- providers: Array
-): ProviderPreviewConfig | undefined {
- const isMatched = (it: ProviderPreviewConfig): boolean =>
- it.contentTypes === undefined || it.contentTypes.some((e) => blob.contentType === e || blob.contentType.includes(e))
-
- let candidate: ProviderPreviewConfig | undefined
- for (const p of providers) {
- if (p !== undefined && isMatched(p)) {
- if (p.previewUrl === '') {
- // we found one disable config line, so return it.
- return p
- }
- candidate = p
- }
- }
-
- return candidate
+export function getSrcSet (_blob: Ref, width?: number): string {
+ return blobToSrcSet(getPreviewConfig(), _blob, width)
}
-export function getSrcSet (_blob: Blob, width?: number): string {
- const blob = _blob as BlobLookup
- const c = getPreviewConfig()
-
- // Select providers from
- const cfg = selectProvider(blob, [...(c.previewers[_blob.provider] ?? []), ...(c.previewers[''] ?? []), c.default])
- if (cfg === undefined || cfg.previewUrl === '') {
- return '' // No previewer is available for blob
- }
-
- return blobToSrcSet(cfg, blob, width)
-}
-
-function blobToSrcSet (
- cfg: ProviderPreviewConfig,
- blob: { _id: Ref, downloadUrl?: string },
- width: number | undefined
-): string {
+function blobToSrcSet (cfg: PreviewConfig, blob: Ref, width: number | undefined): string {
let url = cfg.previewUrl.replaceAll(':workspace', encodeURIComponent(getCurrentWorkspaceUrl()))
- const downloadUrl = blob.downloadUrl ?? getFileUrl(blob._id)
+ const downloadUrl = getFileUrl(blob)
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? window.location.origin
if (!url.includes('://')) {
url = concatLink(frontUrl ?? '', url)
}
url = url.replaceAll(':downloadFile', encodeURIComponent(downloadUrl))
- url = url.replaceAll(':blobId', encodeURIComponent(blob._id))
+ url = url.replaceAll(':blobId', encodeURIComponent(blob))
let result = ''
const fu = url
@@ -187,24 +80,9 @@ function blobToSrcSet (
return result
}
-export async function getBlobSrcFor (blob: Blob | Ref | undefined, name?: string): Promise {
- return blob === undefined
- ? ''
- : typeof blob === 'string'
- ? await getBlobHref(undefined, blob, name)
- : await getBlobHref(blob, blob._id)
-}
-
/***
* @deprecated, please use Blob direct operations.
*/
export function getFileSrcSet (_blob: Ref, width?: number): string {
- const cfg = getPreviewConfig()
- return blobToSrcSet(
- cfg.default ?? defaultPreview(),
- {
- _id: _blob
- },
- width
- )
+ return blobToSrcSet(getPreviewConfig(), _blob, width)
}
diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts
index 4ef6fb44a8..f036ef8e19 100644
--- a/packages/presentation/src/utils.ts
+++ b/packages/presentation/src/utils.ts
@@ -24,7 +24,6 @@ import core, {
type AnyAttribute,
type ArrOf,
type AttachedDoc,
- type BlobLookup,
type Class,
type Client,
type Collection,
@@ -450,18 +449,6 @@ export function createQuery (dontDestroy?: boolean): LiveQuery {
return new LiveQuery(dontDestroy)
}
-export async function getBlobHref (
- _blob: PlatformBlob | undefined,
- file: Ref,
- filename?: string
-): Promise {
- let blob = _blob as BlobLookup
- if (blob?.downloadUrl === undefined) {
- blob = (await getClient().findOne(core.class.Blob, { _id: file })) as BlobLookup
- }
- return blob?.downloadUrl ?? getFileUrl(file, filename)
-}
-
export function getCurrentWorkspaceUrl (): string {
const wsId = get(workspaceId)
if (wsId == null) {
diff --git a/packages/storage/src/index.ts b/packages/storage/src/index.ts
index 253a3c4014..3cadb1b176 100644
--- a/packages/storage/src/index.ts
+++ b/packages/storage/src/index.ts
@@ -13,17 +13,7 @@
// limitations under the License.
//
-import {
- type Blob,
- type Branding,
- type DocumentUpdate,
- type MeasureContext,
- type Ref,
- type StorageIterator,
- type WorkspaceId,
- type WorkspaceIdWithUrl
-} from '@hcengineering/core'
-import type { BlobLookup } from '@hcengineering/core/src/classes'
+import { type Blob, type MeasureContext, type StorageIterator, type WorkspaceId } from '@hcengineering/core'
import { type Readable } from 'stream'
export type ListBlobResult = Omit
@@ -38,11 +28,6 @@ export interface BlobStorageIterator {
close: () => Promise
}
-export interface BlobLookupResult {
- lookups: BlobLookup[]
- updates?: Map[, DocumentUpdate>
-}
-
export interface BucketInfo {
name: string
delete: () => Promise
@@ -50,11 +35,6 @@ export interface BucketInfo {
}
export interface StorageAdapter {
- // If specified will limit a blobs available to put into selected provider.
- // A set of content type patterns supported by this storage provider.
- // If not defined, will be suited for any other content types.
- contentTypes?: string[]
-
initialize: (ctx: MeasureContext, workspaceId: WorkspaceId) => Promise
close: () => Promise
@@ -84,14 +64,6 @@ export interface StorageAdapter {
offset: number,
length?: number
) => Promise
-
- // Lookup will extend Blob with lookup information.
- lookup: (
- ctx: MeasureContext,
- workspaceId: WorkspaceIdWithUrl,
- branding: Branding | null,
- docs: Blob[]
- ) => Promise
}
export interface StorageAdapterEx extends StorageAdapter {
@@ -189,15 +161,6 @@ export class DummyStorageAdapter implements StorageAdapter, StorageAdapterEx {
): Promise {
throw new Error('not implemented')
}
-
- async lookup (
- ctx: MeasureContext,
- workspaceId: WorkspaceIdWithUrl,
- branding: Branding | null,
- docs: Blob[]
- ): Promise {
- return { lookups: [] }
- }
}
export function createDummyStorageAdapter (): StorageAdapter {
diff --git a/plugins/attachment-resources/src/components/AttachmentActions.svelte b/plugins/attachment-resources/src/components/AttachmentActions.svelte
index 53002cfbe9..744fe2ccd2 100644
--- a/plugins/attachment-resources/src/components/AttachmentActions.svelte
+++ b/plugins/attachment-resources/src/components/AttachmentActions.svelte
@@ -18,7 +18,7 @@
import {
FilePreviewPopup,
canPreviewFile,
- getBlobHref,
+ getFileUrl,
getPreviewAlignment,
previewTypes
} from '@hcengineering/presentation'
@@ -71,7 +71,8 @@
showPopup(
FilePreviewPopup,
{
- file: attachment.$lookup?.file ?? attachment.file,
+ file: attachment.file,
+ contentType: attachment.type,
name: attachment.name,
metadata: attachment.metadata
},
@@ -130,32 +131,30 @@
diff --git a/plugins/attachment-resources/src/components/AttachmentDocList.svelte b/plugins/attachment-resources/src/components/AttachmentDocList.svelte
index 9e7d99cc3f..335893196f 100644
--- a/plugins/attachment-resources/src/components/AttachmentDocList.svelte
+++ b/plugins/attachment-resources/src/components/AttachmentDocList.svelte
@@ -48,11 +48,6 @@
},
(res) => {
resAttachments = res
- },
- {
- lookup: {
- file: core.class.Blob
- }
}
)
} else {
diff --git a/plugins/attachment-resources/src/components/AttachmentGalleryPresenter.svelte b/plugins/attachment-resources/src/components/AttachmentGalleryPresenter.svelte
index b866e28bef..07e83fc2db 100644
--- a/plugins/attachment-resources/src/components/AttachmentGalleryPresenter.svelte
+++ b/plugins/attachment-resources/src/components/AttachmentGalleryPresenter.svelte
@@ -15,7 +15,7 @@
]
- {#await getBlobHref(value.$lookup?.file, value.file, value.name) then src}
-
- {#if isImage(value.type)}
-
-
-
-
![{value.name}]()
-
- {:else}
-
- {/if}
-
-
+
+ {#if isImage(value.type)}
+
+
+
+
![{value.name}]()
+
+ {:else}
+
{#if isEmbedded(value.type)}
@@ -91,24 +77,38 @@
{extensionIconLabel(value.name)}
{/if}
-
- {#if isEmbedded(value.type)}
-
-
-
- {trimFilename(value.name)}
-
- {:else}
-
- {/if}
-
{filesize(value.size)}
-
-
+ {/if}
+
+
+ {#if isEmbedded(value.type)}
+
+
+
+ {extensionIconLabel(value.name)}
+
+ {:else}
+
+ {extensionIconLabel(value.name)}
+
+ {/if}
+
+ {#if isEmbedded(value.type)}
+
+
+
+ {trimFilename(value.name)}
+
+ {:else}
+
+ {/if}
+
{filesize(value.size)}
+
+
- {/await}
+