log + auth
This commit is contained in:
parent
da2da30493
commit
0e136b62c8
1 changed files with 15 additions and 12 deletions
27
index.js
27
index.js
|
@ -29,9 +29,11 @@ app.listen(client.config.port,
|
|||
app.use(express.static('public'));
|
||||
app.use(cors());
|
||||
|
||||
async function authenticate(token) {
|
||||
async function authenticate(token, what) {
|
||||
if (!client.config.auth.includes(token)) {
|
||||
return;
|
||||
response.send('ERROR - Not auth')
|
||||
} else {
|
||||
console.log(token + ' do '+ what)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +43,7 @@ app.get('/api/:auth/database', alldata);
|
|||
|
||||
function alldata(request, response) {
|
||||
var token = request.params.auth;
|
||||
authenticate(token)
|
||||
authenticate(token, 'alldata')
|
||||
response.send(elements);
|
||||
}
|
||||
|
||||
|
@ -51,16 +53,16 @@ app.get('/api/:auth/database/:element/', searchElement);
|
|||
|
||||
async function searchElement(request, response) {
|
||||
var token = request.params.auth;
|
||||
authenticate(token)
|
||||
|
||||
var word = request.params.element;
|
||||
|
||||
search = 'search '+ word
|
||||
authenticate(token, search)
|
||||
|
||||
var elements = await db.get(word)
|
||||
|
||||
if(elements) {
|
||||
var reply = elements;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var reply = {
|
||||
status:"Not Found"
|
||||
}
|
||||
|
@ -75,20 +77,21 @@ app.get('/api/:auth/database/:element/set/:data', set);
|
|||
|
||||
async function set(request, response) {
|
||||
var token = request.params.auth;
|
||||
authenticate(token)
|
||||
|
||||
var element = request.params.element;
|
||||
var data = request.params.data;
|
||||
|
||||
set = 'set '+element+' to '+data
|
||||
authenticate(token, set)
|
||||
|
||||
await db.set(element, data)
|
||||
const res = await db.get(element)
|
||||
if(res) {
|
||||
var reply = res;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var reply = {
|
||||
status:"Not Found"
|
||||
}
|
||||
}
|
||||
|
||||
response.send(reply);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue