-
Notifications
You must be signed in to change notification settings - Fork 179
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
Showing
14 changed files
with
169 additions
and
21 deletions.
There are no files selected for viewing
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
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
Binary file not shown.
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,7 @@ | ||
FROM --platform=$TARGETPLATFORM node:16-alpine3.15 | ||
EXPOSE 8088 | ||
RUN mkdir -p /data/api | ||
COPY app.js /data/api/app.js | ||
COPY package.json /data/api/package.json | ||
RUN npm install --prefix /data/api | ||
CMD ["node", "/data/api/app.js"] |
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,97 @@ | ||
const express = require('express'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const app = express(); | ||
|
||
const cors = require('cors'); | ||
app.use(cors()); | ||
|
||
const data_dir = path.join(__dirname, 'data'); | ||
// make dir if not exist | ||
if (!fs.existsSync(data_dir)) fs.mkdirSync(data_dir); | ||
|
||
var multer = require('multer'); | ||
var forms = multer({limits: { fieldSize: 100*1024*1024 }}); | ||
const bodyParser = require('body-parser') | ||
app.use(bodyParser.json()); | ||
app.use(forms.array()); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json({limit : 100*1024*1024 })); | ||
|
||
app.all(`/`, (req, res) => { | ||
res.send('Hello World!'); | ||
}); | ||
|
||
app.post(`/update`, (req, res) => { | ||
// {"encrypted":"123","uuid":String(short_uid.generate())} | ||
const { encrypted, uuid } = req.body; | ||
// none of the fields can be empty | ||
if (!encrypted || !uuid) { | ||
res.status(400).send('Bad Request'); | ||
return; | ||
} | ||
|
||
// save encrypted to uuid file | ||
const file_path = path.join(data_dir, path.basename(uuid)+'.json'); | ||
const content = JSON.stringify({"encrypted":encrypted}); | ||
fs.writeFileSync(file_path, content); | ||
if( fs.readFileSync(file_path) == content ) | ||
res.json({"action":"done"}); | ||
else | ||
res.json({"action":"error"}); | ||
}); | ||
|
||
app.all(`/get/:uuid`, (req, res) => { | ||
const { uuid } = req.params; | ||
// none of the fields can be empty | ||
if (!uuid) { | ||
res.status(400).send('Bad Request'); | ||
return; | ||
} | ||
// get encrypted from uuid file | ||
const file_path = path.join(data_dir, path.basename(uuid)+'.json'); | ||
if (!fs.existsSync(file_path)) { | ||
res.status(404).send('Not Found'); | ||
return; | ||
} | ||
const data = JSON.parse(fs.readFileSync(file_path)); | ||
if( !data ) | ||
{ | ||
res.status(500).send('Internal Serverless Error'); | ||
return; | ||
} | ||
else | ||
{ | ||
// 如果传递了password,则返回解密后的数据 | ||
if( req.body.password ) | ||
{ | ||
const parsed = cookie_decrypt( uuid, data.encrypted, req.body.password ); | ||
res.json(parsed); | ||
}else | ||
{ | ||
res.json(data); | ||
} | ||
} | ||
}); | ||
|
||
|
||
app.use(function (err, req, res, next) { | ||
console.error(err); | ||
res.status(500).send('Internal Serverless Error'); | ||
}); | ||
|
||
|
||
const port = 8088; | ||
app.listen(port, () => { | ||
console.log(`Server start on http://localhost:${port}`); | ||
}); | ||
|
||
function cookie_decrypt( uuid, encrypted, password ) | ||
{ | ||
const CryptoJS = require('crypto-js'); | ||
const the_key = CryptoJS.MD5(uuid+'-'+password).toString().substring(0,16); | ||
const decrypted = CryptoJS.AES.decrypt(encrypted, the_key).toString(CryptoJS.enc.Utf8); | ||
const parsed = JSON.parse(decrypted); | ||
return parsed; | ||
} | ||
|
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,14 @@ | ||
{ | ||
"dependencies": { | ||
"body-parser": "^1.20.1", | ||
"cors": "^2.8.5", | ||
"crypto-js": "^4.1.1", | ||
"express": "^4.18.2", | ||
"fs": "^0.0.1-security", | ||
"multer": "^1.4.5-lts.1", | ||
"path": "^0.12.7" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.20" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -75,4 +75,4 @@ chrome.alarms.onAlarm.addListener( async a => | |
|
||
|
||
} | ||
}); | ||
}); |
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
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