mirror of
https://github.com/luxfi/pics.git
synced 2026-07-27 05:11:31 +00:00
Close #470 ability to renew an existing bypass, which is slightly useful if you allow long living bypasses
This commit is contained in:
+7
-2
@@ -29,10 +29,15 @@ module.exports = {
|
||||
'anonymizer': anonymizer,
|
||||
'expireAt': new Date(Date.now() + blockBypass.expireAfterTime)
|
||||
};
|
||||
if (anonymizer === true && id !== null) {
|
||||
if (id !== null) {
|
||||
newBypass._id = Mongo.ObjectId(id);
|
||||
return db.replaceOne({
|
||||
_id: newBypass._id
|
||||
}, newBypass, {
|
||||
upsert: true,
|
||||
});
|
||||
}
|
||||
return db.insertOne(newBypass);
|
||||
return db.insertOne(newBypass);
|
||||
},
|
||||
|
||||
deleteAll: () => {
|
||||
|
||||
@@ -8,8 +8,9 @@ const { Bypass } = require(__dirname+'/../../db/')
|
||||
module.exports = async (req, res) => {
|
||||
|
||||
const { secureCookies, blockBypass } = config.get;
|
||||
const bypass = await Bypass.getBypass(res.locals.anonymizer, res.locals.pseudoIp, blockBypass.expireAfterUses);
|
||||
const bypassId = bypass.insertedId;
|
||||
const existingBypassId = req.signedCookies.bypassid || res.locals.pseudoIp;
|
||||
const bypass = await Bypass.getBypass(res.locals.anonymizer, existingBypassId, blockBypass.expireAfterUses);
|
||||
const bypassId = bypass.insertedId || existingBypassId; // if upserted, insertedId will be null, and will be the existingId
|
||||
res.locals.blockBypass = true;
|
||||
|
||||
res.cookie('bypassid', bypassId.toString(), {
|
||||
|
||||
Reference in New Issue
Block a user