Skip to content

Commit

Permalink
MYR-000: removed video converter (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
irmannmal authored Dec 18, 2021
1 parent c7be911 commit 07e5d36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 109 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"start:docker": "node ."
},
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@loopback/authentication": "^8.0.0",
"@loopback/authentication-jwt": "^0.10.0",
"@loopback/boot": "^4.0.0",
Expand All @@ -62,7 +61,6 @@
"bn.js": "^5.2.0",
"dotenv": "^10.0.0",
"firebase-admin": "^10.0.0",
"fluent-ffmpeg": "^2.1.2",
"isemail": "^3.2.0",
"loopback-connector-mongodb": "^6.1.0",
"loopback-connector-rest": "^4.0.1",
Expand All @@ -81,7 +79,6 @@
"@sentry/typescript": "^5.20.1",
"@types/bcryptjs": "^2.4.2",
"@types/express-serve-static-core": "^4.17.26",
"@types/fluent-ffmpeg": "^2.1.20",
"@types/multer": "^1.4.7",
"@types/node": "^10.17.60",
"@types/open-graph-scraper": "^4.8.1",
Expand Down
34 changes: 9 additions & 25 deletions src/services/fcs.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {BindingScope, injectable} from '@loopback/core';
import * as firebaseAdmin from 'firebase-admin';
import ffmpegInstaller from '@ffmpeg-installer/ffmpeg';
import ffmpeg from 'fluent-ffmpeg';
import fs from 'fs';
import os from 'os';
import path from 'path';
import sharp from 'sharp';
import {UploadType} from '../enums';

ffmpeg.setFfmpegPath(ffmpegInstaller.path);

@injectable({scope: BindingScope.TRANSIENT})
export class FCSService {
constructor() {}
Expand All @@ -22,6 +18,7 @@ export class FCSService {
const bucket = firebaseAdmin.storage().bucket();
const tempDir = os.tmpdir();
const baseName = path.parse(filePath).name;
const extension = path.parse(filePath).ext;
let format = 'jpg';
let mutations = [
{
Expand Down Expand Up @@ -59,29 +56,16 @@ export class FCSService {

let result = '';
for (const mutation of mutations) {
const formattedFilePath = `${tempDir}/${baseName}${mutation.suffix}_formatted.${format}`;
const uploadFilePath = `${targetDir}/${baseName}${mutation.suffix}.${format}`;
let formattedFilePath = `${tempDir}/${baseName}${extension}`;
let uploadFilePath = `${targetDir}/${baseName}${extension}`;

if (type === UploadType.IMAGE) {
formattedFilePath = `${tempDir}/${baseName}${mutation.suffix}_formatted.${format}`;
uploadFilePath = `${targetDir}/${baseName}${mutation.suffix}.${format}`;

if (mutation.type === 'origin') {
if (type === UploadType.IMAGE) {
if (mutation.type === 'origin') {
await sharp(filePath).toFormat('jpg').toFile(formattedFilePath);
} else {
await new Promise((resolve, reject) => {
ffmpeg(filePath)
.videoCodec('libx264')
.audioCodec('libmp3lame')
.format('mp4')
.on('error', err => {
reject(err);
})
.on('end', () => {
resolve(formattedFilePath);
})
.saveToFile(formattedFilePath);
});
}
} else {
if (type === UploadType.IMAGE) {
await sharp(filePath)
.resize({width: mutation.width})
.toFormat('jpg')
Expand All @@ -96,7 +80,7 @@ export class FCSService {
});
result = file.publicUrl();

fs.unlinkSync(formattedFilePath);
if (type === UploadType.IMAGE) fs.unlinkSync(formattedFilePath);
}

fs.unlinkSync(filePath);
Expand Down
81 changes: 0 additions & 81 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -249,60 +249,6 @@
resolved "https://registry.yarnpkg.com/@exodus/schemasafe/-/schemasafe-1.0.0-rc.3.tgz#dda2fbf3dafa5ad8c63dadff7e01d3fdf4736025"
integrity sha512-GoXw0U2Qaa33m3eUcxuHnHpNvHjNlLo0gtV091XBpaRINaB4X6FGCG5XKxSFNFiPpugUDqNruHzaqpTdDm4AOg==

"@ffmpeg-installer/[email protected]":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/darwin-arm64/-/darwin-arm64-4.1.5.tgz#b7b5c262dd96d1aea4807514e1cdcf6e11f82743"
integrity sha512-hYqTiP63mXz7wSQfuqfFwfLOfwwFChUedeCVKkBtl/cliaTM7/ePI9bVzfZ2c+dWu3TqCwLDRWNSJ5pqZl8otA==

"@ffmpeg-installer/[email protected]":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/darwin-x64/-/darwin-x64-4.1.0.tgz#48e1706c690e628148482bfb64acb67472089aaa"
integrity sha512-Z4EyG3cIFjdhlY8wI9aLUXuH8nVt7E9SlMVZtWvSPnm2sm37/yC2CwjUzyCQbJbySnef1tQwGG2Sx+uWhd9IAw==

"@ffmpeg-installer/ffmpeg@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/ffmpeg/-/ffmpeg-1.1.0.tgz#87fdb9e7d180e8d78f7903f9441e36f978938a90"
integrity sha512-Uq4rmwkdGxIa9A6Bd/VqqYbT7zqh1GrT5/rFwCwKM70b42W5gIjWeVETq6SdcL0zXqDtY081Ws/iJWhr1+xvQg==
optionalDependencies:
"@ffmpeg-installer/darwin-arm64" "4.1.5"
"@ffmpeg-installer/darwin-x64" "4.1.0"
"@ffmpeg-installer/linux-arm" "4.1.3"
"@ffmpeg-installer/linux-arm64" "4.1.4"
"@ffmpeg-installer/linux-ia32" "4.1.0"
"@ffmpeg-installer/linux-x64" "4.1.0"
"@ffmpeg-installer/win32-ia32" "4.1.0"
"@ffmpeg-installer/win32-x64" "4.1.0"

"@ffmpeg-installer/[email protected]":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/linux-arm64/-/linux-arm64-4.1.4.tgz#7219f3f901bb67f7926cb060b56b6974a6cad29f"
integrity sha512-dljEqAOD0oIM6O6DxBW9US/FkvqvQwgJ2lGHOwHDDwu/pX8+V0YsDL1xqHbj1DMX/+nP9rxw7G7gcUvGspSoKg==

"@ffmpeg-installer/[email protected]":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/linux-arm/-/linux-arm-4.1.3.tgz#c554f105ed5f10475ec25d7bec94926ce18db4c1"
integrity sha512-NDf5V6l8AfzZ8WzUGZ5mV8O/xMzRag2ETR6+TlGIsMHp81agx51cqpPItXPib/nAZYmo55Bl2L6/WOMI3A5YRg==

"@ffmpeg-installer/[email protected]":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/linux-ia32/-/linux-ia32-4.1.0.tgz#adad70b0d0d9d8d813983d6e683c5a338a75e442"
integrity sha512-0LWyFQnPf+Ij9GQGD034hS6A90URNu9HCtQ5cTqo5MxOEc7Rd8gLXrJvn++UmxhU0J5RyRE9KRYstdCVUjkNOQ==

"@ffmpeg-installer/[email protected]":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/linux-x64/-/linux-x64-4.1.0.tgz#b4a5d89c4e12e6d9306dbcdc573df716ec1c4323"
integrity sha512-Y5BWhGLU/WpQjOArNIgXD3z5mxxdV8c41C+U15nsE5yF8tVcdCGet5zPs5Zy3Ta6bU7haGpIzryutqCGQA/W8A==

"@ffmpeg-installer/[email protected]":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/win32-ia32/-/win32-ia32-4.1.0.tgz#6eac4fb691b64c02e7a116c1e2d167f3e9b40638"
integrity sha512-FV2D7RlaZv/lrtdhaQ4oETwoFUsUjlUiasiZLDxhEUPdNDWcH1OU9K1xTvqz+OXLdsmYelUDuBS/zkMOTtlUAw==

"@ffmpeg-installer/[email protected]":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@ffmpeg-installer/win32-x64/-/win32-x64-4.1.0.tgz#17e8699b5798d4c60e36e2d6326a8ebe5e95a2c5"
integrity sha512-Drt5u2vzDnIONf4ZEkKtFlbvwj6rI3kxw1Ck9fpudmtgaZIHD4ucsWB2lCZBXRxJgXR+2IMSti+4rtM4C4rXgg==

"@fimbul/bifrost@^0.21.0":
version "0.21.0"
resolved "https://registry.yarnpkg.com/@fimbul/bifrost/-/bifrost-0.21.0.tgz#d0fafa25938fda475657a6a1e407a21bbe02c74e"
Expand Down Expand Up @@ -1356,13 +1302,6 @@
"@types/qs" "*"
"@types/serve-static" "*"

"@types/fluent-ffmpeg@^2.1.20":
version "2.1.20"
resolved "https://registry.yarnpkg.com/@types/fluent-ffmpeg/-/fluent-ffmpeg-2.1.20.tgz#3b5f42fc8263761d58284fa46ee6759a64ce54ac"
integrity sha512-B+OvhCdJ3LgEq2PhvWNOiB/EfwnXLElfMCgc4Z1K5zXgSfo9I6uGKwR/lqmNPFQuebNnes7re3gqkV77SyypLg==
dependencies:
"@types/node" "*"

"@types/fs-extra@^9.0.13":
version "9.0.13"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45"
Expand Down Expand Up @@ -1894,11 +1833,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
integrity sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=

async@>=0.2.9:
version "3.2.2"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.2.tgz#2eb7671034bb2194d45d30e31e24ec7e7f9670cd"
integrity sha512-H0E+qZaDEfx/FY4t7iLRv1W2fFI6+pyCeTw1uN20AQPiwqwM6ojPxHxdLv4z8hi2DtnW9BOckSspLucW7pIE5g==

async@^3.1.0, async@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.0.tgz#b3a2685c5ebb641d3de02d161002c60fc9f85720"
Expand Down Expand Up @@ -3404,14 +3338,6 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561"
integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==

fluent-ffmpeg@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz#c952de2240f812ebda0aa8006d7776ee2acf7d74"
integrity sha1-yVLeIkD4EuvaCqgAbXd27irPfXQ=
dependencies:
async ">=0.2.9"
which "^1.1.1"

fluent-logger@^3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/fluent-logger/-/fluent-logger-3.4.1.tgz#288e8ad28f9fbfd5b5fabd7e24afd589b764878e"
Expand Down Expand Up @@ -6939,13 +6865,6 @@ [email protected], which@^2.0.1:
dependencies:
isexe "^2.0.0"

which@^1.1.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
dependencies:
isexe "^2.0.0"

wide-align@^1.1.0:
version "1.1.5"
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3"
Expand Down

0 comments on commit 07e5d36

Please sign in to comment.