diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/requests.ts | 12 | ||||
-rw-r--r-- | server/lib/activitypub/actor.ts | 9 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 10 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-import.ts | 10 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 5 |
5 files changed, 25 insertions, 21 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 51facc9e0..805930a9f 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -2,6 +2,7 @@ import * as Bluebird from 'bluebird' | |||
2 | import { createWriteStream } from 'fs-extra' | 2 | import { createWriteStream } from 'fs-extra' |
3 | import * as request from 'request' | 3 | import * as request from 'request' |
4 | import { ACTIVITY_PUB } from '../initializers' | 4 | import { ACTIVITY_PUB } from '../initializers' |
5 | import { processImage } from './image-utils' | ||
5 | 6 | ||
6 | function doRequest <T> ( | 7 | function doRequest <T> ( |
7 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } | 8 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } |
@@ -27,9 +28,18 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U | |||
27 | }) | 28 | }) |
28 | } | 29 | } |
29 | 30 | ||
31 | async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) { | ||
32 | const tmpPath = destPath + '.tmp' | ||
33 | |||
34 | await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath) | ||
35 | |||
36 | await processImage({ path: tmpPath }, destPath, size) | ||
37 | } | ||
38 | |||
30 | // --------------------------------------------------------------------------- | 39 | // --------------------------------------------------------------------------- |
31 | 40 | ||
32 | export { | 41 | export { |
33 | doRequest, | 42 | doRequest, |
34 | doRequestAndSaveToFile | 43 | doRequestAndSaveToFile, |
44 | downloadImage | ||
35 | } | 45 | } |
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index b16a00669..218dbc6a7 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -11,9 +11,9 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp | |||
11 | import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' | 11 | import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' |
12 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
13 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' | 13 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' |
14 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | 14 | import { doRequest, doRequestAndSaveToFile, downloadImage } from '../../helpers/requests' |
15 | import { getUrlFromWebfinger } from '../../helpers/webfinger' | 15 | import { getUrlFromWebfinger } from '../../helpers/webfinger' |
16 | import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' | 16 | import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, PREVIEWS_SIZE, sequelizeTypescript } from '../../initializers' |
17 | import { AccountModel } from '../../models/account/account' | 17 | import { AccountModel } from '../../models/account/account' |
18 | import { ActorModel } from '../../models/activitypub/actor' | 18 | import { ActorModel } from '../../models/activitypub/actor' |
19 | import { AvatarModel } from '../../models/avatar/avatar' | 19 | import { AvatarModel } from '../../models/avatar/avatar' |
@@ -180,10 +180,7 @@ async function fetchAvatarIfExists (actorJSON: ActivityPubActor) { | |||
180 | const avatarName = uuidv4() + extension | 180 | const avatarName = uuidv4() + extension |
181 | const destPath = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) | 181 | const destPath = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) |
182 | 182 | ||
183 | await doRequestAndSaveToFile({ | 183 | await downloadImage(actorJSON.icon.url, destPath, AVATARS_SIZE) |
184 | method: 'GET', | ||
185 | uri: actorJSON.icon.url | ||
186 | }, destPath) | ||
187 | 184 | ||
188 | return avatarName | 185 | return avatarName |
189 | } | 186 | } |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 5bd03c8c6..80de92f24 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -10,8 +10,8 @@ import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validat | |||
10 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' | 10 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' |
11 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' | 11 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' |
12 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
13 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | 13 | import { doRequest, downloadImage } from '../../helpers/requests' |
14 | import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers' | 14 | import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_MIMETYPE_EXT } from '../../initializers' |
15 | import { ActorModel } from '../../models/activitypub/actor' | 15 | import { ActorModel } from '../../models/activitypub/actor' |
16 | import { TagModel } from '../../models/video/tag' | 16 | import { TagModel } from '../../models/video/tag' |
17 | import { VideoModel } from '../../models/video/video' | 17 | import { VideoModel } from '../../models/video/video' |
@@ -97,11 +97,7 @@ function generateThumbnailFromUrl (video: VideoModel, icon: ActivityIconObject) | |||
97 | const thumbnailName = video.getThumbnailName() | 97 | const thumbnailName = video.getThumbnailName() |
98 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) | 98 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) |
99 | 99 | ||
100 | const options = { | 100 | return downloadImage(icon.url, thumbnailPath, THUMBNAILS_SIZE) |
101 | method: 'GET', | ||
102 | uri: icon.url | ||
103 | } | ||
104 | return doRequestAndSaveToFile(options, thumbnailPath) | ||
105 | } | 101 | } |
106 | 102 | ||
107 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) { | 103 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) { |
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index e3f2a276c..4de901c0c 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts | |||
@@ -6,8 +6,8 @@ import { VideoImportState } from '../../../../shared/models/videos' | |||
6 | import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 6 | import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
7 | import { extname, join } from 'path' | 7 | import { extname, join } from 'path' |
8 | import { VideoFileModel } from '../../../models/video/video-file' | 8 | import { VideoFileModel } from '../../../models/video/video-file' |
9 | import { CONFIG, sequelizeTypescript, VIDEO_IMPORT_TIMEOUT } from '../../../initializers' | 9 | import { CONFIG, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers' |
10 | import { doRequestAndSaveToFile } from '../../../helpers/requests' | 10 | import { doRequestAndSaveToFile, downloadImage } from '../../../helpers/requests' |
11 | import { VideoState } from '../../../../shared' | 11 | import { VideoState } from '../../../../shared' |
12 | import { JobQueue } from '../index' | 12 | import { JobQueue } from '../index' |
13 | import { federateVideoIfNeeded } from '../../activitypub' | 13 | import { federateVideoIfNeeded } from '../../activitypub' |
@@ -133,7 +133,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide | |||
133 | videoId: videoImport.videoId | 133 | videoId: videoImport.videoId |
134 | } | 134 | } |
135 | videoFile = new VideoFileModel(videoFileData) | 135 | videoFile = new VideoFileModel(videoFileData) |
136 | // Import if the import fails, to clean files | 136 | // To clean files if the import fails |
137 | videoImport.Video.VideoFiles = [ videoFile ] | 137 | videoImport.Video.VideoFiles = [ videoFile ] |
138 | 138 | ||
139 | // Move file | 139 | // Move file |
@@ -145,7 +145,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide | |||
145 | if (options.downloadThumbnail) { | 145 | if (options.downloadThumbnail) { |
146 | if (options.thumbnailUrl) { | 146 | if (options.thumbnailUrl) { |
147 | const destThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoImport.Video.getThumbnailName()) | 147 | const destThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoImport.Video.getThumbnailName()) |
148 | await doRequestAndSaveToFile({ method: 'GET', uri: options.thumbnailUrl }, destThumbnailPath) | 148 | await downloadImage(options.thumbnailUrl, destThumbnailPath, THUMBNAILS_SIZE) |
149 | } else { | 149 | } else { |
150 | await videoImport.Video.createThumbnail(videoFile) | 150 | await videoImport.Video.createThumbnail(videoFile) |
151 | } | 151 | } |
@@ -157,7 +157,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide | |||
157 | if (options.downloadPreview) { | 157 | if (options.downloadPreview) { |
158 | if (options.thumbnailUrl) { | 158 | if (options.thumbnailUrl) { |
159 | const destPreviewPath = join(CONFIG.STORAGE.PREVIEWS_DIR, videoImport.Video.getPreviewName()) | 159 | const destPreviewPath = join(CONFIG.STORAGE.PREVIEWS_DIR, videoImport.Video.getPreviewName()) |
160 | await doRequestAndSaveToFile({ method: 'GET', uri: options.thumbnailUrl }, destPreviewPath) | 160 | await downloadImage(options.thumbnailUrl, destPreviewPath, PREVIEWS_SIZE) |
161 | } else { | 161 | } else { |
162 | await videoImport.Video.createPreview(videoFile) | 162 | await videoImport.Video.createPreview(videoFile) |
163 | } | 163 | } |
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 47f4e59fc..a8a2f305f 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | viewVideo, | 17 | viewVideo, |
18 | wait, | 18 | wait, |
19 | waitUntilLog, | 19 | waitUntilLog, |
20 | checkVideoFilesWereRemoved, removeVideo | 20 | checkVideoFilesWereRemoved, removeVideo, getVideoWithToken |
21 | } from '../../utils' | 21 | } from '../../utils' |
22 | import { waitJobs } from '../../utils/server/jobs' | 22 | import { waitJobs } from '../../utils/server/jobs' |
23 | import * as magnetUtil from 'magnet-uri' | 23 | import * as magnetUtil from 'magnet-uri' |
@@ -93,7 +93,8 @@ async function check1WebSeed (strategy: VideoRedundancyStrategy, videoUUID?: str | |||
93 | 93 | ||
94 | for (const server of servers) { | 94 | for (const server of servers) { |
95 | { | 95 | { |
96 | const res = await getVideo(server.url, videoUUID) | 96 | // With token to avoid issues with video follow constraints |
97 | const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) | ||
97 | 98 | ||
98 | const video: VideoDetails = res.body | 99 | const video: VideoDetails = res.body |
99 | for (const f of video.files) { | 100 | for (const f of video.files) { |