-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (25 loc) · 666 Bytes
/
index.js
File metadata and controls
28 lines (25 loc) · 666 Bytes
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
const Datastore = require('@google-cloud/datastore');
const datastore = new Datastore({
projectId: 'YOUR_PROJECT_ID',
keyFilename: 'YOUR_DATASTORE_CREDENTIAL_FILE_NAME.json'
});
const kindName = 'user-log';
exports.savelog = (req, res) => {
let uid = req.query.uid || req.body.uid || 0;
let log = req.query.log || req.body.log || '';
datastore
.save({
key: datastore.key(kindName),
data: {
log: log,
uid: datastore.int(uid),
time_create: datastore.int(Math.floor(new Date().getTime()/1000))
}
})
.catch(err => {
console.error('ERROR:', err);
res.status(200).send(err);
return;
});
res.status(200).send(log);
};