Skip to content
Merged
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
19 changes: 18 additions & 1 deletion pods/preview/src/providers/octet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,33 @@
//

import { type MeasureContext, type WorkspaceUuid } from '@hcengineering/core'
import { StorageAdapter } from '@hcengineering/server-core'

import { createWriteStream } from 'fs'
import { pipeline } from 'stream/promises'

import { TemporaryDir } from '../tempdir'
import { type PreviewFile, type PreviewMetadata, type PreviewProvider } from '../types'

export class OctetStreamProvider implements PreviewProvider {
constructor (
private readonly storage: StorageAdapter,
private readonly tempDir: TemporaryDir
) {}

supports (contentType: string): boolean {
return contentType === 'application/octet-stream'
}

async image (ctx: MeasureContext, workspace: WorkspaceUuid, name: string, contentType: string): Promise<PreviewFile> {
throw new Error('Cannot generate image preview for application/octet-stream')
const path = this.tempDir.tmpFile()

await ctx.with('blob-read', {}, async (ctx) => {
const stream = await this.storage.get(ctx, { uuid: workspace } as any, name)
await pipeline(stream, createWriteStream(path))
})

return { mimeType: contentType, filePath: path }
}

async metadata (
Expand Down
2 changes: 1 addition & 1 deletion pods/preview/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function createPreviewService (
new DocProvider(storage, tempDir),
new PdfProvider(storage, tempDir),
new VideoProvider(storage, tempDir),
new OctetStreamProvider(),
new OctetStreamProvider(storage, tempDir),
new FallbackProvider(imageProvider)
]
return new PreviewServiceImpl(storage, cache, tempDir, providers, concurrency)
Expand Down