Fix images size when downloading them
This commit is contained in:
parent
babecc3c09
commit
58d515e32f
|
@ -2,6 +2,7 @@ import * as Bluebird from 'bluebird'
|
||||||
import { createWriteStream } from 'fs-extra'
|
import { createWriteStream } from 'fs-extra'
|
||||||
import * as request from 'request'
|
import * as request from 'request'
|
||||||
import { ACTIVITY_PUB } from '../initializers'
|
import { ACTIVITY_PUB } from '../initializers'
|
||||||
|
import { processImage } from './image-utils'
|
||||||
|
|
||||||
function doRequest <T> (
|
function doRequest <T> (
|
||||||
requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }
|
requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }
|
||||||
|
@ -27,9 +28,18 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) {
|
||||||
|
const tmpPath = destPath + '.tmp'
|
||||||
|
|
||||||
|
await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath)
|
||||||
|
|
||||||
|
await processImage({ path: tmpPath }, destPath, size)
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
doRequest,
|
doRequest,
|
||||||
doRequestAndSaveToFile
|
doRequestAndSaveToFile,
|
||||||
|
downloadImage
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp
|
||||||
import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils'
|
import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
|
import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
|
||||||
import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
|
import { doRequest, doRequestAndSaveToFile, downloadImage } from '../../helpers/requests'
|
||||||
import { getUrlFromWebfinger } from '../../helpers/webfinger'
|
import { getUrlFromWebfinger } from '../../helpers/webfinger'
|
||||||
import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
|
import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, PREVIEWS_SIZE, sequelizeTypescript } from '../../initializers'
|
||||||
import { AccountModel } from '../../models/account/account'
|
import { AccountModel } from '../../models/account/account'
|
||||||
import { ActorModel } from '../../models/activitypub/actor'
|
import { ActorModel } from '../../models/activitypub/actor'
|
||||||
import { AvatarModel } from '../../models/avatar/avatar'
|
import { AvatarModel } from '../../models/avatar/avatar'
|
||||||
|
@ -180,10 +180,7 @@ async function fetchAvatarIfExists (actorJSON: ActivityPubActor) {
|
||||||
const avatarName = uuidv4() + extension
|
const avatarName = uuidv4() + extension
|
||||||
const destPath = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
|
const destPath = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
|
||||||
|
|
||||||
await doRequestAndSaveToFile({
|
await downloadImage(actorJSON.icon.url, destPath, AVATARS_SIZE)
|
||||||
method: 'GET',
|
|
||||||
uri: actorJSON.icon.url
|
|
||||||
}, destPath)
|
|
||||||
|
|
||||||
return avatarName
|
return avatarName
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validat
|
||||||
import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
|
import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
|
||||||
import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils'
|
import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
|
import { doRequest, downloadImage } from '../../helpers/requests'
|
||||||
import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers'
|
import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_MIMETYPE_EXT } from '../../initializers'
|
||||||
import { ActorModel } from '../../models/activitypub/actor'
|
import { ActorModel } from '../../models/activitypub/actor'
|
||||||
import { TagModel } from '../../models/video/tag'
|
import { TagModel } from '../../models/video/tag'
|
||||||
import { VideoModel } from '../../models/video/video'
|
import { VideoModel } from '../../models/video/video'
|
||||||
|
@ -97,11 +97,7 @@ function generateThumbnailFromUrl (video: VideoModel, icon: ActivityIconObject)
|
||||||
const thumbnailName = video.getThumbnailName()
|
const thumbnailName = video.getThumbnailName()
|
||||||
const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
|
const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
|
||||||
|
|
||||||
const options = {
|
return downloadImage(icon.url, thumbnailPath, THUMBNAILS_SIZE)
|
||||||
method: 'GET',
|
|
||||||
uri: icon.url
|
|
||||||
}
|
|
||||||
return doRequestAndSaveToFile(options, thumbnailPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) {
|
function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) {
|
||||||
|
|
|
@ -6,8 +6,8 @@ import { VideoImportState } from '../../../../shared/models/videos'
|
||||||
import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
|
import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
|
||||||
import { extname, join } from 'path'
|
import { extname, join } from 'path'
|
||||||
import { VideoFileModel } from '../../../models/video/video-file'
|
import { VideoFileModel } from '../../../models/video/video-file'
|
||||||
import { CONFIG, sequelizeTypescript, VIDEO_IMPORT_TIMEOUT } from '../../../initializers'
|
import { CONFIG, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers'
|
||||||
import { doRequestAndSaveToFile } from '../../../helpers/requests'
|
import { doRequestAndSaveToFile, downloadImage } from '../../../helpers/requests'
|
||||||
import { VideoState } from '../../../../shared'
|
import { VideoState } from '../../../../shared'
|
||||||
import { JobQueue } from '../index'
|
import { JobQueue } from '../index'
|
||||||
import { federateVideoIfNeeded } from '../../activitypub'
|
import { federateVideoIfNeeded } from '../../activitypub'
|
||||||
|
@ -133,7 +133,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
|
||||||
videoId: videoImport.videoId
|
videoId: videoImport.videoId
|
||||||
}
|
}
|
||||||
videoFile = new VideoFileModel(videoFileData)
|
videoFile = new VideoFileModel(videoFileData)
|
||||||
// Import if the import fails, to clean files
|
// To clean files if the import fails
|
||||||
videoImport.Video.VideoFiles = [ videoFile ]
|
videoImport.Video.VideoFiles = [ videoFile ]
|
||||||
|
|
||||||
// Move file
|
// Move file
|
||||||
|
@ -145,7 +145,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
|
||||||
if (options.downloadThumbnail) {
|
if (options.downloadThumbnail) {
|
||||||
if (options.thumbnailUrl) {
|
if (options.thumbnailUrl) {
|
||||||
const destThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoImport.Video.getThumbnailName())
|
const destThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoImport.Video.getThumbnailName())
|
||||||
await doRequestAndSaveToFile({ method: 'GET', uri: options.thumbnailUrl }, destThumbnailPath)
|
await downloadImage(options.thumbnailUrl, destThumbnailPath, THUMBNAILS_SIZE)
|
||||||
} else {
|
} else {
|
||||||
await videoImport.Video.createThumbnail(videoFile)
|
await videoImport.Video.createThumbnail(videoFile)
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
|
||||||
if (options.downloadPreview) {
|
if (options.downloadPreview) {
|
||||||
if (options.thumbnailUrl) {
|
if (options.thumbnailUrl) {
|
||||||
const destPreviewPath = join(CONFIG.STORAGE.PREVIEWS_DIR, videoImport.Video.getPreviewName())
|
const destPreviewPath = join(CONFIG.STORAGE.PREVIEWS_DIR, videoImport.Video.getPreviewName())
|
||||||
await doRequestAndSaveToFile({ method: 'GET', uri: options.thumbnailUrl }, destPreviewPath)
|
await downloadImage(options.thumbnailUrl, destPreviewPath, PREVIEWS_SIZE)
|
||||||
} else {
|
} else {
|
||||||
await videoImport.Video.createPreview(videoFile)
|
await videoImport.Video.createPreview(videoFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
viewVideo,
|
viewVideo,
|
||||||
wait,
|
wait,
|
||||||
waitUntilLog,
|
waitUntilLog,
|
||||||
checkVideoFilesWereRemoved, removeVideo
|
checkVideoFilesWereRemoved, removeVideo, getVideoWithToken
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { waitJobs } from '../../utils/server/jobs'
|
import { waitJobs } from '../../utils/server/jobs'
|
||||||
import * as magnetUtil from 'magnet-uri'
|
import * as magnetUtil from 'magnet-uri'
|
||||||
|
@ -93,7 +93,8 @@ async function check1WebSeed (strategy: VideoRedundancyStrategy, videoUUID?: str
|
||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
{
|
{
|
||||||
const res = await getVideo(server.url, videoUUID)
|
// With token to avoid issues with video follow constraints
|
||||||
|
const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
|
||||||
|
|
||||||
const video: VideoDetails = res.body
|
const video: VideoDetails = res.body
|
||||||
for (const f of video.files) {
|
for (const f of video.files) {
|
||||||
|
|
Loading…
Reference in New Issue