|
@@ -2,6 +2,7 @@
|
|
|
const whiskers = require('whiskers');
|
|
const whiskers = require('whiskers');
|
|
|
const fs = require('fs');
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
+const OriginModel = require('../models/origin.js').OriginModel;
|
|
|
const ApiKeyModel = require('../models/apiKey.js').ApiKeyModel;
|
|
const ApiKeyModel = require('../models/apiKey.js').ApiKeyModel;
|
|
|
const PasteContent = require('../models/pasteContent.js').PasteContent;
|
|
const PasteContent = require('../models/pasteContent.js').PasteContent;
|
|
|
const AccessModel = require('../models/access.js').AccessModel;
|
|
const AccessModel = require('../models/access.js').AccessModel;
|
|
@@ -10,9 +11,9 @@ const Security = require('../src/security.js');
|
|
|
const CONFIG = require('../src/config.js');
|
|
const CONFIG = require('../src/config.js');
|
|
|
|
|
|
|
|
async function onAccessContent(app, req, entity) {
|
|
async function onAccessContent(app, req, entity) {
|
|
|
|
|
+ const rel = "" + (req.body.rel || req.body.r || "");
|
|
|
if (entity.privId !== req.params.id) {
|
|
if (entity.privId !== req.params.id) {
|
|
|
- //FIXME ?rel
|
|
|
|
|
- let accessEntry = new AccessModel(entity.privId, req.params.id, Security.getRequestIp(req));
|
|
|
|
|
|
|
+ let accessEntry = new AccessModel(entity.privId, rel, Security.getRequestIp(req));
|
|
|
await accessEntry.resolveIp();
|
|
await accessEntry.resolveIp();
|
|
|
await app.databaseHelper.insertOne(accessEntry);
|
|
await app.databaseHelper.insertOne(accessEntry);
|
|
|
}
|
|
}
|
|
@@ -51,14 +52,23 @@ async function _readAccess(app, entityId) {
|
|
|
.map(x => { delete x.ipAddress; delete x.privId; x.ipRegion = JSON.parse(x.ipRegion); return x; });
|
|
.map(x => { delete x.ipAddress; delete x.privId; x.ipRegion = JSON.parse(x.ipRegion); return x; });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function renderPrivatePage(app, res, entity) {
|
|
|
|
|
|
|
+async function renderPrivatePage(app, req, res, entity) {
|
|
|
let stat;
|
|
let stat;
|
|
|
try { stat = fs.statSync(app.dataDir+entity.privId); } catch (e) { stat = { error: e }; }
|
|
try { stat = fs.statSync(app.dataDir+entity.privId); } catch (e) { stat = { error: e }; }
|
|
|
const access = await _readAccess(app, entity.privId);
|
|
const access = await _readAccess(app, entity.privId);
|
|
|
|
|
+ const origins = await app.databaseHelper.fetch(OriginModel, { privId: entity.privId });
|
|
|
|
|
|
|
|
let context = app.routerUtils.commonRenderInfos();
|
|
let context = app.routerUtils.commonRenderInfos();
|
|
|
context.page_title += " - Pastit";
|
|
context.page_title += " - Pastit";
|
|
|
- res.end(whiskers.render(require('../templates/stats.js'), { ...context, ...{size: stat.size}, ...{ access: JSON.stringify(access) }}));
|
|
|
|
|
|
|
+ entity.createdTime = entity.created.getTime();
|
|
|
|
|
+ entity.expireTime = entity.expire?.getTime() || 0;
|
|
|
|
|
+ res.end(whiskers.render(require('../templates/stats.js'), {
|
|
|
|
|
+ ...context,
|
|
|
|
|
+ ...{size: stat.size || 0},
|
|
|
|
|
+ ...{ access: JSON.stringify(access)},
|
|
|
|
|
+ ...{entity: entity},
|
|
|
|
|
+ ...{origins: JSON.stringify(origins.map(i => i.name))}
|
|
|
|
|
+ }));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = { register: app => {
|
|
module.exports = { register: app => {
|
|
@@ -71,7 +81,7 @@ module.exports = { register: app => {
|
|
|
app.router.get("/x/:id", async (req, res) => {
|
|
app.router.get("/x/:id", async (req, res) => {
|
|
|
let entity = await app.databaseHelper.findOne(PasteContent, { privId: req.params.id, publicId: req.params.id }, " or ");
|
|
let entity = await app.databaseHelper.findOne(PasteContent, { privId: req.params.id, publicId: req.params.id }, " or ");
|
|
|
if (entity && entity.privId === req.params.id)
|
|
if (entity && entity.privId === req.params.id)
|
|
|
- return renderPrivatePage(app, res, entity);
|
|
|
|
|
|
|
+ return renderPrivatePage(app, req, res, entity);
|
|
|
if (entity && !entity.expired)
|
|
if (entity && !entity.expired)
|
|
|
return renderPublicPage(app, req, res, entity);
|
|
return renderPublicPage(app, req, res, entity);
|
|
|
app.routerUtils.onPageNotFound(res);
|
|
app.routerUtils.onPageNotFound(res);
|