Fixed #1: Start expiration only after first upload

This commit is contained in:
Mark van Renswoude 2018-08-16 15:18:02 +02:00
parent b2ab541fa6
commit fbf6e6a96f
7 changed files with 103 additions and 26 deletions

View File

@ -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)

View File

@ -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({

View File

@ -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;

View File

@ -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: {

View File

@ -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: {

View File

@ -10,7 +10,7 @@
</div>
<div class="expirationDate" v-if="showExpirationNotice()">
{{ expirationDate === null ? $t('expirationNotice.never') : $t('expirationNotice.ever', getExpirationNoticeDateTime()) }}
{{ getExpirationNotice() }}
</div>
@ -40,7 +40,8 @@ export default {
return {
uploadToken: shared.uploadToken,
message: null,
expirationDate: null
expirationDate: null,
expiration: null
}
},
@ -64,6 +65,7 @@ export default {
{
self.message = response.data.message;
self.expirationDate = response.data.expirationDate !== null ? new Date(response.data.expirationDate) : null;
self.expiration = response.data.expiration;
});
},
@ -138,21 +140,34 @@ export default {
{
var self = this;
if (self.expirationDate === null)
return self.$i18n.t('expirationNotice.never') != '';
else
return self.$i18n.t('expirationNotice.ever') != '';
if (self.expirationDate != null)
return self.$i18n.t('expirationNotice.date') != '';
if (self.expiration != null)
return self.$i18n.t('expirationNotice.timespan') != '';
return self.$i18n.t('expirationNotice.never') != '';
},
getExpirationNoticeDateTime()
getExpirationNotice()
{
var self = this;
return {
date: self.$options.filters.formatDate(self.expirationDate),
time: self.$options.filters.formatTime(self.expirationDate)
};
if (self.expirationDate != null)
return self.$i18n.t('expirationNotice.date', {
date: self.$options.filters.formatDate(self.expirationDate),
time: self.$options.filters.formatTime(self.expirationDate)
});
if (self.expiration != null)
return self.$i18n.t('expirationNotice.timespan', {
expiration: self.$tc('expirationValues.' + self.expiration.units,
self.expiration.value,
{ count: self.expiration.value })
});
return self.$i18n.t('expirationNotice.never');
}
}
}

View File

@ -44,10 +44,14 @@
</select>
<input v-if="!code.id" id="expiration" type="number" v-model="code.expiration.value" :disabled="!code.expiration.units" min="1" class="pure-input-1-3">
<input v-if="code.id" id="expiration" type="text" readonly :value="code.expirationDate | formatDateTime" class="pure-input-2-3">
<input v-if="code.id" id="expiration" type="text" readonly :value="getExpirationValueUnits(code.expiration)" class="pure-input-2-3">
</div>
<div v-if="code.id" class="pure-control-group">
<label for="expirationDate"></label>
<input id="expirationDate" type="text" readonly :value="code.expirationDate | formatDateTime" class="pure-input-2-3">
</div>
<div class="pure-form-description" v-if="!code.id && maxExpiration !== null">
{{ $t('admin.codes.detail.expirationHint', { valueUnits: getExpirationValueUnits() }) }}
{{ $t('admin.codes.detail.expirationHint', { valueUnits: getExpirationValueUnits(maxExpiration) }) }}
</div>
<div class="pure-control-group">
@ -210,16 +214,16 @@ export default {
},
getExpirationValueUnits()
getExpirationValueUnits(expiration)
{
var self = this;
if (self.maxExpiration === null)
if (expiration === null)
return '';
return self.$tc('expirationValues.' + self.maxExpiration.units,
self.maxExpiration.value,
{ count: self.maxExpiration.value });
return self.$tc('expirationValues.' + expiration.units,
expiration.value,
{ count: expiration.value });
}
}
}