import * as Bluebird from 'bluebird'
import { computeResolutionsToTranscode, logger } from '../../../helpers'
-
-import { database as db } from '../../../initializers/database'
-import { VideoInstance } from '../../../models'
-import { sendAddVideo } from '../../activitypub/send-request'
+import { sequelizeTypescript } from '../../../initializers'
+import { VideoModel } from '../../../models/video/video'
+import { shareVideoByServer } from '../../activitypub'
+import { sendCreateVideo } from '../../activitypub/send'
import { JobScheduler } from '../job-scheduler'
import { TranscodingJobPayload } from './transcoding-job-scheduler'
async function process (data: TranscodingJobPayload, jobId: number) {
- const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
+ const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
// No video, maybe deleted?
if (!video) {
logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
return Promise.resolve()
}
-async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: JobScheduler<TranscodingJobPayload, VideoInstance>) {
+async function onSuccess (jobId: number, video: VideoModel, jobScheduler: JobScheduler<TranscodingJobPayload, VideoModel>) {
if (video === undefined) return undefined
logger.info('Job %d is a success.', jobId)
// Maybe the video changed in database, refresh it
- const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
+ const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
// Video does not exist anymore
if (!videoDatabase) return undefined
// Now we'll add the video's meta data to our followers
- await sendAddVideo(video, undefined)
+ await sendCreateVideo(video, undefined)
+ // TODO: share by channel
+ await shareVideoByServer(video, undefined)
const originalFileHeight = await videoDatabase.getOriginalFileHeight()
if (resolutionsEnabled.length !== 0) {
try {
- await db.sequelize.transaction(async t => {
+ await sequelizeTypescript.transaction(async t => {
const tasks: Bluebird<any>[] = []
for (const resolution of resolutionsEnabled) {