박선진

delete preview result files

const express = require('express');
const fs = require('fs');
const ffmpeg = require('ffmpeg');
const request = require('request')
const request = require('request');
const path = require('path');
const router = express.Router();
router.post('/videoResult', function (req, res) {
delete_prevResult_image('./fire');
delete_prevResult_image('./unknown');
try {
let preview = req.body[0].preview;
......@@ -95,4 +96,16 @@ function save_Result_image(file, type, index){
});
}
function delete_prevResult_image(filePath){
fs.readdir(filePath, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(filePath, file), err => {
if (err) throw err;
});
}
});
}
module.exports = router;
\ No newline at end of file
......
No preview for this file type
......@@ -12,5 +12,5 @@ app.use(bodyParser.urlencoded({limit: '100mb', extended: true}));
app.use(bodyParser());
app.use('/api', api);
const port = 3004;
const port = 3005;
app.listen(port, () => console.log(`노드서버 시작 : ${port}`));
......
......@@ -37,7 +37,7 @@ class Subject extends PureComponent {
e.preventDefault();
console.log("save image");
// post request
fetch('http://localhost:3004/api/saveImage',{
fetch('http://localhost:3005/api/saveImage',{
method: 'POST',
mode: 'cors',
cache: 'no-cache',
......@@ -51,8 +51,6 @@ class Subject extends PureComponent {
})
.then(res=>res.json())
.then(data=>this.setState({videoAnalysisResult:data}))
console.log(this.state.videoAnalysisResult);
}
render() {
......
......@@ -47,7 +47,7 @@ class Dashboard extends React.Component {
e.preventDefault();
console.log("upload video");
// post request
fetch('http://localhost:3004/api/videoResult',{
fetch('http://localhost:3005/api/videoResult',{
method: 'POST',
mode: 'cors',
cache: 'no-cache',
......@@ -61,8 +61,6 @@ class Dashboard extends React.Component {
})
.then(res=>res.json())
.then(data=>this.setState({videoAnalysisResult:data}))
console.log(this.state.videoAnalysisResult);
}
static propTypes = {
......@@ -76,7 +74,6 @@ class Dashboard extends React.Component {
}
render() {
console.log(this.state.videoAnalysisResult);
return (
<div>
<h1 className="page-title">Video Analysis <small><small>Performance</small></small></h1>
......