threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FileTransferPlugin.ts 994B

123456789101112131415161718192021222324252627
  1. import {AViewerPluginSync} from '../../viewer'
  2. import {downloadBlob} from 'ts-browser-helpers'
  3. export class FileTransferPlugin extends AViewerPluginSync<'transferFile'> {
  4. enabled = true
  5. static readonly PluginType = 'FileTransferPlugin'
  6. toJSON: any = undefined
  7. async exportFile(file: File|Blob, name?: string) {
  8. name = name || (file as File).name || 'file_export'
  9. this.dispatchEvent({type: 'transferFile', path: name, state: 'exporting'})
  10. await this.actions.exportFile(file, name, ({state, progress})=>{
  11. this.dispatchEvent({type: 'transferFile', path: name, state: state ?? 'exporting', progress})
  12. })
  13. this.dispatchEvent({type: 'transferFile', path: name, state: 'done'})
  14. }
  15. readonly defaultActions = {
  16. exportFile: async(blob: Blob, name: string, _onProgress?: (d: {state?: string, progress?: number})=>void)=>{
  17. downloadBlob(blob, name)
  18. },
  19. }
  20. actions = {...this.defaultActions}
  21. }