aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-20 13:52:49 +0200
committerChocobozzz <me@florianbigard.com>2019-08-20 14:53:42 +0200
commit0283eaac2a8e73006c66df3cf5bb9012e37450e5 (patch)
tree1fb73aeef57f984a77f47828ade23c6365ce8eb0 /server/lib/job-queue/handlers
parent96ca24f00e5ae5471dee9ee596489fe50af2b46f (diff)
downloadPeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.tar.gz
PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.tar.zst
PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.zip
Cleanup model types
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts17
-rw-r--r--server/lib/job-queue/handlers/video-import.ts22
2 files changed, 24 insertions, 15 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index 741b1ffde..5cb55cad6 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -10,7 +10,7 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
10import { ActorModel } from '../../../models/activitypub/actor' 10import { ActorModel } from '../../../models/activitypub/actor'
11import { Notifier } from '../../notifier' 11import { Notifier } from '../../notifier'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { MActorFollowFull, MActorFull } from '../../../typings/models' 13import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models'
14 14
15export type ActivitypubFollowPayload = { 15export type ActivitypubFollowPayload = {
16 followerActorId: number 16 followerActorId: number
@@ -45,7 +45,7 @@ export {
45 45
46// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
47 47
48async function follow (fromActor: MActorFull, targetActor: MActorFull) { 48async function follow (fromActor: MActor, targetActor: MActorFull) {
49 if (fromActor.id === targetActor.id) { 49 if (fromActor.id === targetActor.id) {
50 throw new Error('Follower is the same than target actor.') 50 throw new Error('Follower is the same than target actor.')
51 } 51 }
@@ -54,7 +54,7 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) {
54 const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending' 54 const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'
55 55
56 const actorFollow = await sequelizeTypescript.transaction(async t => { 56 const actorFollow = await sequelizeTypescript.transaction(async t => {
57 const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowFull>({ 57 const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({
58 where: { 58 where: {
59 actorId: fromActor.id, 59 actorId: fromActor.id,
60 targetActorId: targetActor.id 60 targetActorId: targetActor.id
@@ -75,5 +75,14 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) {
75 return actorFollow 75 return actorFollow
76 }) 76 })
77 77
78 if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollow) 78 if (actorFollow.state === 'accepted') {
79 const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount })
80
81 const actorFollowFull = Object.assign(actorFollow, {
82 ActorFollowing: targetActor,
83 ActorFollower: followerFull
84 })
85
86 Notifier.Instance.notifyOfNewUserFollow(actorFollowFull)
87 }
79} 88}
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index f9dda79f8..ff8c93328 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -111,13 +111,11 @@ type ProcessFileOptions = {
111 generateThumbnail: boolean 111 generateThumbnail: boolean
112 generatePreview: boolean 112 generatePreview: boolean
113} 113}
114async function processFile (downloader: () => Promise<string>, videoImportArg: MVideoImportDefault, options: ProcessFileOptions) { 114async function processFile (downloader: () => Promise<string>, videoImport: MVideoImportDefault, options: ProcessFileOptions) {
115 let tempVideoPath: string 115 let tempVideoPath: string
116 let videoDestFile: string 116 let videoDestFile: string
117 let videoFile: VideoFileModel 117 let videoFile: VideoFileModel
118 118
119 const videoImport = videoImportArg as MVideoImportDefaultFiles
120
121 try { 119 try {
122 // Download video from youtubeDL 120 // Download video from youtubeDL
123 tempVideoPath = await downloader() 121 tempVideoPath = await downloader()
@@ -142,35 +140,37 @@ async function processFile (downloader: () => Promise<string>, videoImportArg: M
142 videoId: videoImport.videoId 140 videoId: videoImport.videoId
143 } 141 }
144 videoFile = new VideoFileModel(videoFileData) 142 videoFile = new VideoFileModel(videoFileData)
143
144 const videoWithFiles = Object.assign(videoImport.Video, { VideoFiles: [ videoFile ] })
145 // To clean files if the import fails 145 // To clean files if the import fails
146 videoImport.Video.VideoFiles = [ videoFile ] 146 const videoImportWithFiles: MVideoImportDefaultFiles = Object.assign(videoImport, { Video: videoWithFiles })
147 147
148 // Move file 148 // Move file
149 videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile)) 149 videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImportWithFiles.Video.getVideoFilename(videoFile))
150 await move(tempVideoPath, videoDestFile) 150 await move(tempVideoPath, videoDestFile)
151 tempVideoPath = null // This path is not used anymore 151 tempVideoPath = null // This path is not used anymore
152 152
153 // Process thumbnail 153 // Process thumbnail
154 let thumbnailModel: MThumbnail 154 let thumbnailModel: MThumbnail
155 if (options.downloadThumbnail && options.thumbnailUrl) { 155 if (options.downloadThumbnail && options.thumbnailUrl) {
156 thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.MINIATURE) 156 thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.MINIATURE)
157 } else if (options.generateThumbnail || options.downloadThumbnail) { 157 } else if (options.generateThumbnail || options.downloadThumbnail) {
158 thumbnailModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.MINIATURE) 158 thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE)
159 } 159 }
160 160
161 // Process preview 161 // Process preview
162 let previewModel: MThumbnail 162 let previewModel: MThumbnail
163 if (options.downloadPreview && options.thumbnailUrl) { 163 if (options.downloadPreview && options.thumbnailUrl) {
164 previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.PREVIEW) 164 previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.PREVIEW)
165 } else if (options.generatePreview || options.downloadPreview) { 165 } else if (options.generatePreview || options.downloadPreview) {
166 previewModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.PREVIEW) 166 previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW)
167 } 167 }
168 168
169 // Create torrent 169 // Create torrent
170 await videoImport.Video.createTorrentAndSetInfoHash(videoFile) 170 await videoImportWithFiles.Video.createTorrentAndSetInfoHash(videoFile)
171 171
172 const { videoImportUpdated, video } = await sequelizeTypescript.transaction(async t => { 172 const { videoImportUpdated, video } = await sequelizeTypescript.transaction(async t => {
173 const videoImportToUpdate = videoImport as MVideoImportVideo 173 const videoImportToUpdate = videoImportWithFiles as MVideoImportVideo
174 174
175 // Refresh video 175 // Refresh video
176 const video = await VideoModel.load(videoImportToUpdate.videoId, t) 176 const video = await VideoModel.load(videoImportToUpdate.videoId, t)