mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-11-23 20:36:21 +03:00
Compare commits
2 commits
0c4a9928fa
...
55ee067141
Author | SHA1 | Date | |
---|---|---|---|
55ee067141 | |||
31e2b7346f |
4 changed files with 35 additions and 14 deletions
|
@ -1,3 +1,4 @@
|
||||||
PORT=80 # port to listen on
|
PORT=80 # port to listen on
|
||||||
MONGO_URI="your mongo uri" # "mongodb+srv://xxxx:yyyy@domain/zzzz?retryWrites=true&w=majority"
|
MONGO_URI="your mongo uri" # "mongodb+srv://xxxx:yyyy@domain/zzzz?retryWrites=true&w=majority"
|
||||||
MONGO_DB="anopaper" # database name
|
MONGO_DB="anopaper" # database name
|
||||||
|
ENC_KEY="test" # encryption key
|
|
@ -28,7 +28,7 @@
|
||||||
- [x] Migration notes storage to mongodb (#3)
|
- [x] Migration notes storage to mongodb (#3)
|
||||||
- [ ] Settings for publish notes, such as: delete after reading, number of reads before deleting, adding your own data (name, picture, status in the settings) to the note.
|
- [ ] Settings for publish notes, such as: delete after reading, number of reads before deleting, adding your own data (name, picture, status in the settings) to the note.
|
||||||
- [x] Maintaining statistics on sent notes, the number of notes received, number of deleted notes (#8)
|
- [x] Maintaining statistics on sent notes, the number of notes received, number of deleted notes (#8)
|
||||||
- [ ] Encrypting notes in the database
|
- [x] Encrypting notes in the database (#26)
|
||||||
- [x] Local notes ids is ~~incremental~~ `Date.now()` instead of uuidv4 (238af9ad6957f72439a1a39f32662145dd2bdce8)
|
- [x] Local notes ids is ~~incremental~~ `Date.now()` instead of uuidv4 (238af9ad6957f72439a1a39f32662145dd2bdce8)
|
||||||
|
|
||||||
# AnoPaper v1.0.0
|
# AnoPaper v1.0.0
|
||||||
|
|
20
core.js
20
core.js
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
const mongoClient = require("mongodb").MongoClient;
|
const mongoClient = require("mongodb").MongoClient;
|
||||||
const sha3 = require("js-sha3").sha3_512;
|
const sha3 = require("js-sha3").sha3_512;
|
||||||
|
const AES = require("crypto-js/aes");
|
||||||
|
const cryptojs = require("crypto-js");
|
||||||
|
|
||||||
class NotesCore {
|
class NotesCore {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
@ -33,6 +35,7 @@ class NotesCore {
|
||||||
try {
|
try {
|
||||||
let note = await this.notes.findOne({ _id });
|
let note = await this.notes.findOne({ _id });
|
||||||
if (note !== null) await this.incStats("receivedNotes");
|
if (note !== null) await this.incStats("receivedNotes");
|
||||||
|
note = await this.decryptNote(note);
|
||||||
return note;
|
return note;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
|
@ -61,6 +64,7 @@ class NotesCore {
|
||||||
note._id = sha3(JSON.stringify(note));
|
note._id = sha3(JSON.stringify(note));
|
||||||
note.time = Date.now();
|
note.time = Date.now();
|
||||||
note.pub = true;
|
note.pub = true;
|
||||||
|
note = await this.encryptNote(note);
|
||||||
await this.notes.updateOne(
|
await this.notes.updateOne(
|
||||||
{ _id: note._id },
|
{ _id: note._id },
|
||||||
{ $set: note },
|
{ $set: note },
|
||||||
|
@ -73,6 +77,22 @@ class NotesCore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async encryptNote(note) {
|
||||||
|
note.name = AES.encrypt(note.name, process.env.ENC_KEY).toString();
|
||||||
|
note.text = AES.encrypt(note.text, process.env.ENC_KEY).toString();
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
async decryptNote(note) {
|
||||||
|
note.name = AES.decrypt(note.name, process.env.ENC_KEY).toString(
|
||||||
|
cryptojs.enc.Utf8
|
||||||
|
);
|
||||||
|
note.text = AES.decrypt(note.text, process.env.ENC_KEY).toString(
|
||||||
|
cryptojs.enc.Utf8
|
||||||
|
);
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
async incStats(_id) {
|
async incStats(_id) {
|
||||||
await this.stats.updateOne(
|
await this.stats.updateOne(
|
||||||
{ _id },
|
{ _id },
|
||||||
|
|
24
package-lock.json
generated
24
package-lock.json
generated
|
@ -2031,9 +2031,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/engine.io": {
|
"node_modules/engine.io": {
|
||||||
"version": "6.4.1",
|
"version": "6.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.4.2.tgz",
|
||||||
"integrity": "sha512-JFYQurD/nbsA5BSPmbaOSLa3tSVj8L6o4srSwXXY3NqE+gGUNmmPTbhn8tjzcCtSqhFgIeqef81ngny8JM25hw==",
|
"integrity": "sha512-FKn/3oMiJjrOEOeUub2WCox6JhxBXq/Zn3fZOMCBxKnNYtsdKjxhl7yR3fZhM9PV+rdE75SU5SYMc+2PGzo+Tg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/cookie": "^0.4.1",
|
"@types/cookie": "^0.4.1",
|
||||||
"@types/cors": "^2.8.12",
|
"@types/cors": "^2.8.12",
|
||||||
|
@ -6586,9 +6586,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/socket.io-parser": {
|
"node_modules/socket.io-parser": {
|
||||||
"version": "4.2.2",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.3.tgz",
|
||||||
"integrity": "sha512-DJtziuKypFkMMHCm2uIshOYC7QaylbtzQwiMYDuCKy3OPkjLzu4B2vAhTlqipRHHzrI0NJeBAizTK7X+6m1jVw==",
|
"integrity": "sha512-JMafRntWVO2DCJimKsRTh/wnqVvO4hrfwOqtO7f+uzwsQMuxO6VwImtYxaQ+ieoyshWOTJyV0fA21lccEXRPpQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@socket.io/component-emitter": "~3.1.0",
|
"@socket.io/component-emitter": "~3.1.0",
|
||||||
"debug": "~4.3.1"
|
"debug": "~4.3.1"
|
||||||
|
@ -8973,9 +8973,9 @@
|
||||||
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w=="
|
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w=="
|
||||||
},
|
},
|
||||||
"engine.io": {
|
"engine.io": {
|
||||||
"version": "6.4.1",
|
"version": "6.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.4.2.tgz",
|
||||||
"integrity": "sha512-JFYQurD/nbsA5BSPmbaOSLa3tSVj8L6o4srSwXXY3NqE+gGUNmmPTbhn8tjzcCtSqhFgIeqef81ngny8JM25hw==",
|
"integrity": "sha512-FKn/3oMiJjrOEOeUub2WCox6JhxBXq/Zn3fZOMCBxKnNYtsdKjxhl7yR3fZhM9PV+rdE75SU5SYMc+2PGzo+Tg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/cookie": "^0.4.1",
|
"@types/cookie": "^0.4.1",
|
||||||
"@types/cors": "^2.8.12",
|
"@types/cors": "^2.8.12",
|
||||||
|
@ -12121,9 +12121,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"socket.io-parser": {
|
"socket.io-parser": {
|
||||||
"version": "4.2.2",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.3.tgz",
|
||||||
"integrity": "sha512-DJtziuKypFkMMHCm2uIshOYC7QaylbtzQwiMYDuCKy3OPkjLzu4B2vAhTlqipRHHzrI0NJeBAizTK7X+6m1jVw==",
|
"integrity": "sha512-JMafRntWVO2DCJimKsRTh/wnqVvO4hrfwOqtO7f+uzwsQMuxO6VwImtYxaQ+ieoyshWOTJyV0fA21lccEXRPpQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@socket.io/component-emitter": "~3.1.0",
|
"@socket.io/component-emitter": "~3.1.0",
|
||||||
"debug": "~4.3.1"
|
"debug": "~4.3.1"
|
||||||
|
|
Loading…
Add table
Reference in a new issue