Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Optimize image resizing

Chocobozzza8a63227781c
diff --git a/client/src/app/+verify-account/verify-account-email/verify-account-email.component.ts b/client/src/app/+verify-account/verify-account-email/verify-account-email.component.ts
index 26b3bf4b1d..e4a5522c8e 100644
--- a/client/src/app/+verify-account/verify-account-email/verify-account-email.component.ts
+++ b/client/src/app/+verify-account/verify-account-email/verify-account-email.component.ts
@@ -25,7 +25,6 @@ export class VerifyAccountEmailComponent implements OnInit {
}
ngOnInit () {
-
this.userId = this.route.snapshot.queryParams['userId']
this.verificationString = this.route.snapshot.queryParams['verificationString']
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index 3eaa674ed9..da3285b13d 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -1,13 +1,28 @@
import 'multer'
import * as sharp from 'sharp'
-import { remove } from 'fs-extra'
+import { move, remove } from 'fs-extra'
async function processImage (
physicalFile: { path: string },
destination: string,
newSize: { width: number, height: number }
) {
- await sharp(physicalFile.path)
+ if (physicalFile.path === destination) {
+ throw new Error('Sharp needs an input path different that the output path.')
+ }
+
+ const sharpInstance = sharp(physicalFile.path)
+ const metadata = await sharpInstance.metadata()
+
+ // No need to resize
+ if (metadata.width === newSize.width && metadata.height === newSize.height) {
+ await move(physicalFile.path, destination, { overwrite: true })
+ return
+ }
+
+ await remove(destination)
+
+ await sharpInstance
.resize(newSize.width, newSize.height)
.toFile(destination)
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 80de92f244..6ff9baefe3 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -242,10 +242,6 @@ async function updateVideoFromAP (options: {
if (options.updateViews === true) options.video.set('views', videoData.views)
await options.video.save(sequelizeOptions)
- // Don't block on request
- generateThumbnailFromUrl(options.video, options.videoObject.icon)
- .catch(err => logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err }))
-
{
const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject)
const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a))
@@ -293,6 +289,12 @@ async function updateVideoFromAP (options: {
logger.debug('Cannot update the remote video.', { err })
throw err
}
+
+ try {
+ await generateThumbnailFromUrl(options.video, options.videoObject.icon)
+ } catch (err) {
+ logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err })
+ }
}
export {