-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
124 lines (110 loc) · 4 KB
/
App.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const express = require('express')
const app = express()
const path = require('path')
const PORT = process.env.PORT || 54555
const fs = require('fs')
// const http = require('http')
const ExifTool = require('exiftool-vendored').ExifTool
const exiftool = new ExifTool({ taskTimeoutMillis: 8000 })
const https = require('https')
const key = fs.readFileSync('/var/local/ssl/selfsigned.key','utf8')
const cert = fs.readFileSync('/var/local/ssl/selfsigned.crt','utf8')
const serverOptions = ({
key: key,
cert: cert
})
const server = https.createServer(serverOptions, app)
// const server = http.createServer(app)
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.get('/', (req, res) => {
res.sendFile('index.html')
})
// app.get('/validator', (req, res) => {
// res.sendFile('validator.html')
// })
app.post('/meta-data', (req, res) => {
let locationString = (req.body.urlToFile).replaceAll("%20", " ").substr(46, (req.body.urlToFile).length)
exiftool
.write(`/home1/designhub/dh_url_generator/production/dh-url-generator${locationString}`, {Copyright: req.body.copyright, CopyrightNotice: req.body.copyright, Author: req.body.author, XPAuthor: req.body.author, XPComment: req.body.comments })
.catch((err) => {
console.error("Something terrible happened: ", err)
res.write('<h1>Error</h1><p>Sorry, something went wrong. Please <a href="/express/metadatagen/">try again</a> or contact admin for help.</p>')
res.end()
})
.finally(() => exiftool.end())
let response = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./index.css">
<title>Design Hub Meta-Data Generator</title>
</head>
<body>
<div class="container">
<h1>Meta Data Success</h1>
<h2>Content</h2>
<ol>
<li> Copyright: ${req.body.copyright}</li>
<li> Author: ${req.body.author}</li>
<li> Comments: ${req.body.comments}</li>
</ol>
<div class="success-message">
<a href='/express/metadatagen/'>Add Data to another file</a>
<a href='/express/metadatagen/validator.html'>Check meta-data</a>
</div>
</div>
</body>
</html>
`
return res.send(response)
})
app.post('/meta-read', (req, res) => {
let locationString = (req.body.urlToFile).replaceAll("%20", " ").substr(46, (req.body.urlToFile).length)
exiftool
.read(`/home1/designhub/dh_url_generator/production/dh-url-generator${locationString}`)
.then((tags) => {
const arr = Object.entries(tags)
res.write(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./index.css">
<title>Design Hub Meta-Data Generator</title>
</head>
<body>
<div class="container">
<h1>Meta Data Success</h1>
<div class="success-message">
<a href='express/metadatagen/validator.html'>Check another file</a>
</div>
<h2 class="meta-data-title">Data</h2>
<ul class="meta-data-results">
`)
arr.forEach((tag) => {
res.write(`
<p><b>${tag[0]}:</b> ${tag[1]}</p>
`)
})
res.write(`
</ul>
</div>
</body>
</html>
`)
res.end()
})
.catch((err) => {
console.error(`Oops, something went horribly wrong: ${err}`)
res.write('<h1>Error</h1><p>Sorry, something went wrong. Please <a href="/express/metadatagen/validator.html">try again</a> or contact admin for help.</p>')
res.end()
})
.finally(()=> exiftool.end())
})
server.listen(PORT, () => console.log(`Listening on https://localhost:${PORT}`))