Fix tests
authorChocobozzz <me@florianbigard.com>
Tue, 20 Aug 2019 08:22:05 +0000 (10:22 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 20 Aug 2019 08:22:05 +0000 (10:22 +0200)
server/controllers/api/videos/import.ts
server/controllers/api/videos/index.ts
server/lib/activitypub/videos.ts
server/models/video/tag.ts

index adc2f9aa2a625b6a9d1ee84338c244e39bcb0efd..a058b37efa60d8d02b0e73af860d899266b0aaf5 100644 (file)
@@ -28,6 +28,7 @@ import {
   MChannelActorAccountDefault,
   MThumbnail,
   MUser,
+  MVideoTag,
   MVideoThumbnailAccountDefault,
   MVideoWithBlacklistLight
 } from '@server/typings/models'
@@ -244,7 +245,7 @@ function insertIntoDB (parameters: {
     const sequelizeOptions = { transaction: t }
 
     // Save video object in database
-    const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight)
+    const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight & MVideoTag)
     videoCreated.VideoChannel = videoChannel
 
     if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
@@ -264,6 +265,9 @@ function insertIntoDB (parameters: {
       const tagInstances = await TagModel.findOrCreateTags(tags, t)
 
       await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
+      videoCreated.Tags = tagInstances
+    } else {
+      videoCreated.Tags = []
     }
 
     // Create video import object in database
index 9af71d276430bd959d7b87575c40b4defb1d1bdb..b4f6565751b89caaa8e128fb82908d65a7156ab2 100644 (file)
@@ -63,7 +63,7 @@ import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../
 import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
 import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding'
 import { Hooks } from '../../../lib/plugins/hooks'
-import { MVideoFullLight } from '@server/typings/models'
+import { MVideoDetails, MVideoFullLight } from '@server/typings/models'
 
 const auditLogger = auditLoggerFactory('videos')
 const videosRouter = express.Router()
@@ -198,7 +198,7 @@ async function addVideo (req: express.Request, res: express.Response) {
     originallyPublishedAt: videoInfo.originallyPublishedAt
   }
 
-  const video = new VideoModel(videoData)
+  const video = new VideoModel(videoData) as MVideoDetails
   video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
 
   const videoFile = new VideoFileModel({
index 5c10f976468451af0044d3dedf8c62aaf736c616..035994da835a5d48ec77e1013248b619df490d46 100644 (file)
@@ -65,9 +65,7 @@ import {
   MVideoFile,
   MVideoFullLight,
   MVideoId,
-  MVideoTag,
-  MVideoThumbnail,
-  MVideoWithAllFiles
+  MVideoThumbnail
 } from '../../typings/models'
 import { MThumbnail } from '../../typings/models/video/thumbnail'
 
index 0fc3cfd4cfae9f8bac8c09c81a899c73ea965401..b110f2a436e55dc8044c19de1feb547867d1ec6a 100644 (file)
@@ -6,6 +6,7 @@ import { throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { VideoTagModel } from './video-tag'
 import { VideoPrivacy, VideoState } from '../../../shared/models/videos'
+import { MTag } from '@server/typings/models'
 
 @Table({
   tableName: 'tag',
@@ -37,10 +38,10 @@ export class TagModel extends Model<TagModel> {
   })
   Videos: VideoModel[]
 
-  static findOrCreateTags (tags: string[], transaction: Transaction) {
-    if (tags === null) return []
+  static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> {
+    if (tags === null) return Promise.resolve([])
 
-    const tasks: Bluebird<TagModel>[] = []
+    const tasks: Bluebird<MTag>[] = []
     tags.forEach(tag => {
       const query = {
         where: {
@@ -52,7 +53,7 @@ export class TagModel extends Model<TagModel> {
         transaction
       }
 
-      const promise = TagModel.findOrCreate(query)
+      const promise = TagModel.findOrCreate<MTag>(query)
         .then(([ tagInstance ]) => tagInstance)
       tasks.push(promise)
     })