import 'multer'
import * as sharp from 'sharp'
-import { move, remove } from 'fs-extra'
+import { readFile, remove } from 'fs-extra'
+import { logger } from './logger'
async function processImage (
physicalFile: { path: string },
throw new Error('Sharp needs an input path different that the output path.')
}
- const sharpInstance = sharp(physicalFile.path)
- const metadata = await sharpInstance.metadata()
+ logger.debug('Processing image %s to %s.', physicalFile.path, destination)
- // No need to resize
- if (metadata.width === newSize.width && metadata.height === newSize.height) {
- await move(physicalFile.path, destination, { overwrite: true })
- return
- }
+ // Avoid sharp cache
+ const buf = await readFile(physicalFile.path)
+ const sharpInstance = sharp(buf)
await remove(destination)
import * as request from 'request'
import { ACTIVITY_PUB } from '../initializers'
import { processImage } from './image-utils'
+import { extname } from 'path'
function doRequest <T> (
requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }
}
async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) {
- const tmpPath = destPath + '.tmp'
-
+ const tmpPath = destPath + '.tmp' + extname(destPath)
await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath)
await processImage({ path: tmpPath }, destPath, size)
return undefined
}
- const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoObject.id })
+ const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoObject.id, allowRefresh: false })
const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
const updateOptions = {
async function getOrCreateVideoAndAccountAndChannel (options: {
videoObject: VideoTorrentObject | string,
syncParam?: SyncParam,
- fetchType?: VideoFetchByUrlType
+ fetchType?: VideoFetchByUrlType,
+ allowRefresh?: boolean // true by default
}) {
// Default params
const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false }
const fetchType = options.fetchType || 'all'
+ const allowRefresh = options.allowRefresh !== false
// Get video url
const videoUrl = getAPUrl(options.videoObject)
let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
if (videoFromDatabase) {
- const refreshOptions = {
- video: videoFromDatabase,
- fetchedType: fetchType,
- syncParam
- }
- if (syncParam.refreshVideo === true) videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
- else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoFromDatabase.url } })
+ if (allowRefresh === true) {
+ const refreshOptions = {
+ video: videoFromDatabase,
+ fetchedType: fetchType,
+ syncParam
+ }
+
+ if (syncParam.refreshVideo === true) videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
+ else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoFromDatabase.url } })
+ }
return { video: videoFromDatabase }
}
async function refreshAPObject (job: Bull.Job) {
const payload = job.data as RefreshPayload
- logger.info('Processing AP refresher in job %d.', job.id)
+
+ logger.info('Processing AP refresher in job %d for video %s.', job.id, payload.videoUrl)
if (payload.type === 'video') return refreshAPVideo(payload.videoUrl)
}
// Order of the tests we want to execute
import './create-import-video-file-job'
import './create-transcoding-job'
+import './optimize-old-videos'
import './peertube'
import './reset-password'
import './update-host'