박선진

delete preview result files

1 const express = require('express'); 1 const express = require('express');
2 const fs = require('fs'); 2 const fs = require('fs');
3 const ffmpeg = require('ffmpeg'); 3 const ffmpeg = require('ffmpeg');
4 -const request = require('request') 4 +const request = require('request');
5 - 5 +const path = require('path');
6 const router = express.Router(); 6 const router = express.Router();
7 7
8 router.post('/videoResult', function (req, res) { 8 router.post('/videoResult', function (req, res) {
9 - 9 + delete_prevResult_image('./fire');
10 + delete_prevResult_image('./unknown');
10 try { 11 try {
11 let preview = req.body[0].preview; 12 let preview = req.body[0].preview;
12 13
...@@ -95,4 +96,16 @@ function save_Result_image(file, type, index){ ...@@ -95,4 +96,16 @@ function save_Result_image(file, type, index){
95 }); 96 });
96 } 97 }
97 98
99 +function delete_prevResult_image(filePath){
100 + fs.readdir(filePath, (err, files) => {
101 + if (err) throw err;
102 +
103 + for (const file of files) {
104 + fs.unlink(path.join(filePath, file), err => {
105 + if (err) throw err;
106 + });
107 + }
108 + });
109 +}
110 +
98 module.exports = router; 111 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
No preview for this file type
...@@ -12,5 +12,5 @@ app.use(bodyParser.urlencoded({limit: '100mb', extended: true})); ...@@ -12,5 +12,5 @@ app.use(bodyParser.urlencoded({limit: '100mb', extended: true}));
12 app.use(bodyParser()); 12 app.use(bodyParser());
13 app.use('/api', api); 13 app.use('/api', api);
14 14
15 -const port = 3004; 15 +const port = 3005;
16 app.listen(port, () => console.log(`노드서버 시작 : ${port}`)); 16 app.listen(port, () => console.log(`노드서버 시작 : ${port}`));
......
...@@ -37,7 +37,7 @@ class Subject extends PureComponent { ...@@ -37,7 +37,7 @@ class Subject extends PureComponent {
37 e.preventDefault(); 37 e.preventDefault();
38 console.log("save image"); 38 console.log("save image");
39 // post request 39 // post request
40 - fetch('http://localhost:3004/api/saveImage',{ 40 + fetch('http://localhost:3005/api/saveImage',{
41 method: 'POST', 41 method: 'POST',
42 mode: 'cors', 42 mode: 'cors',
43 cache: 'no-cache', 43 cache: 'no-cache',
...@@ -51,8 +51,6 @@ class Subject extends PureComponent { ...@@ -51,8 +51,6 @@ class Subject extends PureComponent {
51 }) 51 })
52 .then(res=>res.json()) 52 .then(res=>res.json())
53 .then(data=>this.setState({videoAnalysisResult:data})) 53 .then(data=>this.setState({videoAnalysisResult:data}))
54 -
55 - console.log(this.state.videoAnalysisResult);
56 } 54 }
57 55
58 render() { 56 render() {
......
...@@ -47,7 +47,7 @@ class Dashboard extends React.Component { ...@@ -47,7 +47,7 @@ class Dashboard extends React.Component {
47 e.preventDefault(); 47 e.preventDefault();
48 console.log("upload video"); 48 console.log("upload video");
49 // post request 49 // post request
50 - fetch('http://localhost:3004/api/videoResult',{ 50 + fetch('http://localhost:3005/api/videoResult',{
51 method: 'POST', 51 method: 'POST',
52 mode: 'cors', 52 mode: 'cors',
53 cache: 'no-cache', 53 cache: 'no-cache',
...@@ -61,8 +61,6 @@ class Dashboard extends React.Component { ...@@ -61,8 +61,6 @@ class Dashboard extends React.Component {
61 }) 61 })
62 .then(res=>res.json()) 62 .then(res=>res.json())
63 .then(data=>this.setState({videoAnalysisResult:data})) 63 .then(data=>this.setState({videoAnalysisResult:data}))
64 -
65 - console.log(this.state.videoAnalysisResult);
66 } 64 }
67 65
68 static propTypes = { 66 static propTypes = {
...@@ -76,7 +74,6 @@ class Dashboard extends React.Component { ...@@ -76,7 +74,6 @@ class Dashboard extends React.Component {
76 } 74 }
77 75
78 render() { 76 render() {
79 - console.log(this.state.videoAnalysisResult);
80 return ( 77 return (
81 <div> 78 <div>
82 <h1 className="page-title">Video Analysis <small><small>Performance</small></small></h1> 79 <h1 className="page-title">Video Analysis <small><small>Performance</small></small></h1>
......