aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-edit/shared/video-edit-utils.ts
blob: 3a7dbed36ef4d9d1d85b54b638293466dc962a5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { FormGroup } from '@angular/forms'
import { VideoEdit } from '@app/shared/shared-main'

function hydrateFormFromVideo (formGroup: FormGroup, video: VideoEdit, thumbnailFiles: boolean) {
  formGroup.patchValue(video.toFormPatch())

  if (thumbnailFiles === false) return

  const objects = [
    {
      url: 'thumbnailUrl',
      name: 'thumbnailfile'
    },
    {
      url: 'previewUrl',
      name: 'previewfile'
    }
  ]

  for (const obj of objects) {
    if (!video[obj.url]) continue

    fetch(video[obj.url])
      .then(response => response.blob())
      .then(data => {
        formGroup.patchValue({
          [ obj.name ]: data
        })
      })
  }
}

export {
  hydrateFormFromVideo
}