-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
earliest777
committed
Dec 29, 2021
1 parent
358e485
commit 728ba8e
Showing
11 changed files
with
133 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,4 +104,5 @@ dist | |
.tern-port | ||
|
||
serviceAccountKey.json | ||
uploads/* | ||
uploads/* | ||
tools/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,33 @@ | ||
const multer = require('multer'); | ||
const fs = require('fs').promises; | ||
const path = require('path'); | ||
const config = require('../../config'); | ||
|
||
const storage = multer.diskStorage({ | ||
destination: async (req, file, cb) => { | ||
const filePath = path.join(__dirname, `../../uploads/${ Date.now() }`); | ||
|
||
/* Multer by default doesn't makes file if doesn't exisst, so use FS*/ | ||
await fs.mkdir(filePath, {recursive: true}); | ||
cb(null, filePath); | ||
}, | ||
|
||
filename: (req, file, cb) => { | ||
cb(null, `${file.originalname}`); | ||
} | ||
}); | ||
|
||
const upload = multer({ storage: storage }); | ||
|
||
const session = require('./session'); | ||
const {videoManager, multerUpload} = require('../../services/video-service'); | ||
const { response } = require('express'); | ||
const getVideoStatus = async (req, res) => { | ||
const videoId = req.params.videoId; | ||
res.send(videoId); | ||
}; | ||
|
||
const uploadVideo = async (req, res) => { | ||
const file = req.body.file; | ||
console.log(file); | ||
res.send("Ok File!"); | ||
const sessionObj = await session.restore(); | ||
console.log(sessionObj); | ||
}; | ||
|
||
const deleteVideo = async (req, res) => { | ||
const videoId = req.params.videoId; | ||
res.send(videoId); | ||
}; | ||
|
||
// const createSession = (req, res, next) => { | ||
const uploadVideo = async (req, res, next) => { | ||
|
||
// }; | ||
|
||
// app.post('/upload', upload.single('file'), (req, res) => { | ||
// console.log(req.file); | ||
// console.log(Math.floor(req.file.size/1024/1024) + "MB"); | ||
// res.send('This is Upload Video Route!'); | ||
// }); | ||
req.locals = await session.generate(); | ||
const response = await videoManager.uploadVideo(req, res); | ||
|
||
if(!response.status) { | ||
next(response.data); | ||
return; | ||
} | ||
|
||
res.status(response.status).send(response.data); | ||
}; | ||
|
||
// const _uploadVideo = (req, res, next) => { | ||
// // console.log(req.file.); | ||
// res.send('This is Upload Video Route!'); | ||
// }; | ||
const upload = [uploadVideo]; | ||
|
||
// const uploadVideo = [upload.single(('avatar')), _uploadVideo]; | ||
const deleteVideo = async (req, res) => { | ||
}; | ||
|
||
module.exports = { | ||
getVideoStatus, | ||
uploadVideo, | ||
upload, | ||
deleteVideo, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const genuuid = require('uuid').v4; | ||
|
||
async function generateSession() { | ||
|
||
const sessionObj = { | ||
id: genuuid(), | ||
time: Date.now(), | ||
} | ||
|
||
return sessionObj; | ||
} | ||
|
||
async function restoreSession() { | ||
|
||
} | ||
|
||
const session = { | ||
generate: generateSession, | ||
restore: restoreSession, | ||
} | ||
|
||
module.exports = session; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { exec } = require('child_process'); | ||
|
||
const ls = exec('dir', { cwd: '../../Tools/Bento4-SDK' }, function (error, stdout, stderr) { | ||
|
||
if(error) { | ||
console.log(error.stack); | ||
console.log('Error Code: ' + error.code); | ||
console.log('Signal received: ' + error.signal); | ||
} | ||
|
||
console.log('Child Process STDOUT: ' + stdout); | ||
console.log('Child Process STDERR: ' + stderr); | ||
}); | ||
|
||
ls.on('exit', function(code) { | ||
console.log('Child process exited with exit code ' + code); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,74 @@ | ||
const multer = require('multer'); | ||
const fs = require('fs').promises; | ||
const path = require('path'); | ||
const logger = require('../loaders/logger'); | ||
|
||
const storage = multer.diskStorage({ | ||
destination: async (req, file, cb) => { | ||
const filePath = path.join(__dirname, `../uploads/${ req.locals.id }`); | ||
|
||
/* Multer by default doesn't makes file if doesn't exisst, so use FS*/ | ||
await fs.mkdir(filePath, {recursive: true}); | ||
cb(null, filePath); | ||
}, | ||
|
||
filename: (req, file, cb) => { | ||
cb(null, `${ Date.now() + path.extname(file.originalname) }`); | ||
} | ||
}); | ||
|
||
const multerUpload = multer({ | ||
storage: storage, | ||
limits: { fileSize: 1 * 1024 * 1024 }, | ||
}).single('file'); | ||
|
||
class videoManager { | ||
|
||
// uploadVideo(); | ||
static async uploadVideo(req, res) { | ||
|
||
let response = { | ||
status: '', | ||
data: {}, | ||
} | ||
|
||
multerUpload(req, res, function (err) { | ||
|
||
if(err) { | ||
logger.error(err, {err}); | ||
|
||
if(err instanceof multer.MulterError) { | ||
response.status = 400; | ||
response.data = { | ||
error: err.message, | ||
} | ||
} | ||
|
||
videoManager.cleanUp(req); | ||
return; | ||
} | ||
//ye kaam asyc ho nahi raha phir bhi response khaali print ho rha hai | ||
|
||
response.status = 200; | ||
response.data = req.locals; | ||
}); | ||
|
||
console.log(response); | ||
return response; | ||
} | ||
|
||
static async cleanUp(req) { | ||
const filePath = path.join(__dirname, `../uploads/${ req.locals.id }`); | ||
await fs.rm(filePath, {recursive: true}); | ||
} | ||
|
||
// getVideoStatus(); | ||
// deleteVideo(); | ||
// scheduleDeleteJob(); | ||
// fileValidations(); | ||
// afterJob() | ||
} | ||
} | ||
|
||
module.exports = { | ||
videoManager, | ||
multerUpload, | ||
}; |