server.js
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"use strict";
const express = require('express');
const multer = require('multer');
const bodyParser = require('body-parser');
const fs = require('fs');
const PORT = 8080;
const HOST = '0.0.0.0';
const app = express();
const dataFolder = './tensorflow/data';
const testFolder = './tensorflow/test';
app.set('view engine', 'pug');
app.set('views', './views');
app.locals.pretty = true
app.use(bodyParser.urlencoded({extended:false}));
// Redirect Root to Home
app.get('/', (req, res) => {
res.redirect('/home');
});
// Main Page
app.get('/home', (req, res) => {
fs.readdir(dataFolder, function(error, filelist){
if(error)
console.log(error);
res.render('home', {fileList:filelist});
});
});
// Directory existence checking
app.post('/directory_check', (req, res) => {
var dir = req.body.directoryName;
// Directory exists
if(fs.existsSync(dataFolder + '/' + dir))
{
// Go back page
res.render('error_directoryAdd');
}
// Directory doesn't exist
else
{
// Make directory
fs.mkdirSync(dataFolder + '/' + dir);
console.log('디렉토리: ' + dir + ' 생성 완료');
res.redirect('/home/' + dir);
}
});
// Basic Directory Page
app.get('/home/:directoryName', (req, res) => {
});
// Image Upload Directory Page
app.get('/home/:directoryName/upload', (req, res) => {
var upload_data = multer({ dest: 'tensorflow/data/' + directoryName });
upload_data.array('ImageData')
var imgFileArr = req.files;
});
// Delete Directory
app.get('/home/:directoryName/delete', (req, res) => {
// exist query.real
var directoryName = req.params.directoryName;
if (req.query.real) {
// Remove Directory and Files
var path = dataFolder + '/' + directoryName;
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
fs.unlinkSync(curPath);
});
fs.rmdirSync(path);
res.redirect('/');
}
else {
res.render('directoryDeleteCheck');
}
});
// Image Test Page
app.post('/test', (req, res) => {
var upload_test = multer({ dest: 'tensorflow/test/' });
upload_test.single('ImageTest')
var imgTest = req.file;
});
app.listen(PORT, HOST);
console.log('Running on http://${HOST}:${POST}');