video-captions.ts 827 B

1234567891011121314151617181920212223242526
  1. import { moveAndProcessCaptionFile } from '@server/helpers/captions-utils.js'
  2. import { sequelizeTypescript } from '@server/initializers/database.js'
  3. import { VideoCaptionModel } from '@server/models/video/video-caption.js'
  4. import { MVideo, MVideoCaption } from '@server/types/models/index.js'
  5. export async function createLocalCaption (options: {
  6. video: MVideo
  7. path: string
  8. language: string
  9. }) {
  10. const { language, path, video } = options
  11. const videoCaption = new VideoCaptionModel({
  12. videoId: video.id,
  13. filename: VideoCaptionModel.generateCaptionName(language),
  14. language
  15. }) as MVideoCaption
  16. await moveAndProcessCaptionFile({ path }, videoCaption)
  17. await sequelizeTypescript.transaction(async t => {
  18. await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t)
  19. })
  20. return videoCaption
  21. }