diff --git a/lib/api/token.js b/lib/api/token.js index 68d6982..09697de 100644 --- a/lib/api/token.js +++ b/lib/api/token.js @@ -20,8 +20,7 @@ module.exports = (repository) => { jwt.sign({ codeId: req.body.code, - codeUserId: code.userId, - codeExpirationTime: code.expirationDate !== null ? code.expirationDate.getTime() : null + codeUserId: code.userId }, config.jwtSecret, (err, token) => { if (err) diff --git a/lib/api/upload.js b/lib/api/upload.js index 330f7a1..5b80d14 100644 --- a/lib/api/upload.js +++ b/lib/api/upload.js @@ -57,7 +57,8 @@ module.exports = (repository, tusServer) => let info = { message: null, - expirationDate: code.expirationDate !== null ? code.expirationDate.getTime() : null + expirationDate: code.expirationDate, + expiration: code.expiration }; if (code.messageHTML) @@ -107,11 +108,13 @@ module.exports = (repository, tusServer) => return; } + let expirationDate = await repository.codes.getUploadExpirationDate(decoded.codeId); + var uploadId = await repository.uploads.insert({ userId: decoded.codeUserId, codeId: decoded.codeId, files: req.body.files, - expirationDate: decoded.codeExpirationTime !== null ? new Date(decoded.codeExpirationTime) : null + expirationDate: expirationDate }); await repository.notifications.insert({ diff --git a/lib/repository/code.js b/lib/repository/code.js index f06962e..c946cd4 100644 --- a/lib/repository/code.js +++ b/lib/repository/code.js @@ -15,6 +15,7 @@ class Code self.id = values.id || values._id || null; self.userId = values.userId || null; self.created = values.created || new Date(); + self.firstUpload = values.firstUpload || null; self.expiration = values.expiration || null; self.expirationDate = values.expirationDate || null; self.description = values.description || null; @@ -65,8 +66,9 @@ class CodeRepository _id: codeId, userId: code.userId, created: code.created || now, + firstUpload: code.firstUpload, expiration: code.expiration, - expirationDate: ExpirationUnits.apply(code.expiration, code.created), + expirationDate: code.expirationDate, description: code.description, message: code.message, messageHTML: self.getMessageHTML(code.message), @@ -95,7 +97,8 @@ class CodeRepository { self.store.update({ _id: code.id }, { $set: { expiration: code.expiration, - expirationDate: ExpirationUnits.apply(code.expiration, code.created), + firstUpload: code.firstUpload, + expirationDate: code.firstUpload != null && code.expiration != null ? ExpirationUnits.apply(code.expiration, code.firstUpload) : null, description: code.description, message: code.message, messageHTML: self.getMessageHTML(code.message) @@ -119,6 +122,57 @@ class CodeRepository } + getUploadExpirationDate(codeId) + { + var self = this; + + return new Promise((resolve, reject) => + { + self.store.findOne({ _id: codeId }, (err, doc) => + { + if (err) + { + reject(err); + return; + } + + if (doc !== null) + { + if (doc.firstUpload == null) + { + let now = new Date(); + let expirationDate = doc.expiration != null ? ExpirationUnits.apply(doc.expiration, now) : null; + + self.store.update({ _id: codeId }, { $set: { + firstUpload: now, + expirationDate: expirationDate + }}, + (err, numAffected) => + { + if (err) + { + reject(err); + return; + } + + if (numAffected == 0) + { + reject(); + } + + resolve(expirationDate); + }); + } + else + resolve(doc.expirationDate); + } + else + resolve(null); + }); + }); + } + + move(codeId, userId) { var self = this; diff --git a/public/src/locale/en.js b/public/src/locale/en.js index 542540d..51458c2 100644 --- a/public/src/locale/en.js +++ b/public/src/locale/en.js @@ -22,7 +22,8 @@ export default { uploadDisclaimer: '', expirationNotice: { never: '', - ever: 'Files uploaded for this invite code will be automatically deleted on {date} at {time}' + date: 'Files uploaded for this invite code will be automatically deleted on {date} at {time}', + timespan: 'Files uploaded for this invite code will be automatically deleted after {expiration}' }, expirationValues: { diff --git a/public/src/locale/nl.js b/public/src/locale/nl.js index 8fedc40..e797fde 100644 --- a/public/src/locale/nl.js +++ b/public/src/locale/nl.js @@ -22,7 +22,8 @@ export default { uploadDisclaimer: '', expirationNotice: { never: '', - ever: 'Bestanden die worden geupload voor deze code worden automatisch verwijderd op {date} om {time}' + date: 'Bestanden die worden geupload voor deze code worden automatisch verwijderd op {date} om {time}', + timespan: 'Bestanden die worden geupload voor deze code worden automatisch verwijderd na {expiration}' }, expirationValues: { diff --git a/public/src/route/Upload.vue b/public/src/route/Upload.vue index aaec57f..7f3633f 100644 --- a/public/src/route/Upload.vue +++ b/public/src/route/Upload.vue @@ -10,7 +10,7 @@