Fixed #1: Start expiration only after first upload
This commit is contained in:
parent
b2ab541fa6
commit
fbf6e6a96f
|
@ -20,8 +20,7 @@ module.exports = (repository) =>
|
||||||
{
|
{
|
||||||
jwt.sign({
|
jwt.sign({
|
||||||
codeId: req.body.code,
|
codeId: req.body.code,
|
||||||
codeUserId: code.userId,
|
codeUserId: code.userId
|
||||||
codeExpirationTime: code.expirationDate !== null ? code.expirationDate.getTime() : null
|
|
||||||
}, config.jwtSecret, (err, token) =>
|
}, config.jwtSecret, (err, token) =>
|
||||||
{
|
{
|
||||||
if (err)
|
if (err)
|
||||||
|
|
|
@ -57,7 +57,8 @@ module.exports = (repository, tusServer) =>
|
||||||
|
|
||||||
let info = {
|
let info = {
|
||||||
message: null,
|
message: null,
|
||||||
expirationDate: code.expirationDate !== null ? code.expirationDate.getTime() : null
|
expirationDate: code.expirationDate,
|
||||||
|
expiration: code.expiration
|
||||||
};
|
};
|
||||||
|
|
||||||
if (code.messageHTML)
|
if (code.messageHTML)
|
||||||
|
@ -107,11 +108,13 @@ module.exports = (repository, tusServer) =>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let expirationDate = await repository.codes.getUploadExpirationDate(decoded.codeId);
|
||||||
|
|
||||||
var uploadId = await repository.uploads.insert({
|
var uploadId = await repository.uploads.insert({
|
||||||
userId: decoded.codeUserId,
|
userId: decoded.codeUserId,
|
||||||
codeId: decoded.codeId,
|
codeId: decoded.codeId,
|
||||||
files: req.body.files,
|
files: req.body.files,
|
||||||
expirationDate: decoded.codeExpirationTime !== null ? new Date(decoded.codeExpirationTime) : null
|
expirationDate: expirationDate
|
||||||
});
|
});
|
||||||
|
|
||||||
await repository.notifications.insert({
|
await repository.notifications.insert({
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Code
|
||||||
self.id = values.id || values._id || null;
|
self.id = values.id || values._id || null;
|
||||||
self.userId = values.userId || null;
|
self.userId = values.userId || null;
|
||||||
self.created = values.created || new Date();
|
self.created = values.created || new Date();
|
||||||
|
self.firstUpload = values.firstUpload || null;
|
||||||
self.expiration = values.expiration || null;
|
self.expiration = values.expiration || null;
|
||||||
self.expirationDate = values.expirationDate || null;
|
self.expirationDate = values.expirationDate || null;
|
||||||
self.description = values.description || null;
|
self.description = values.description || null;
|
||||||
|
@ -65,8 +66,9 @@ class CodeRepository
|
||||||
_id: codeId,
|
_id: codeId,
|
||||||
userId: code.userId,
|
userId: code.userId,
|
||||||
created: code.created || now,
|
created: code.created || now,
|
||||||
|
firstUpload: code.firstUpload,
|
||||||
expiration: code.expiration,
|
expiration: code.expiration,
|
||||||
expirationDate: ExpirationUnits.apply(code.expiration, code.created),
|
expirationDate: code.expirationDate,
|
||||||
description: code.description,
|
description: code.description,
|
||||||
message: code.message,
|
message: code.message,
|
||||||
messageHTML: self.getMessageHTML(code.message),
|
messageHTML: self.getMessageHTML(code.message),
|
||||||
|
@ -95,7 +97,8 @@ class CodeRepository
|
||||||
{
|
{
|
||||||
self.store.update({ _id: code.id }, { $set: {
|
self.store.update({ _id: code.id }, { $set: {
|
||||||
expiration: code.expiration,
|
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,
|
description: code.description,
|
||||||
message: code.message,
|
message: code.message,
|
||||||
messageHTML: self.getMessageHTML(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)
|
move(codeId, userId)
|
||||||
{
|
{
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
@ -22,7 +22,8 @@ export default {
|
||||||
uploadDisclaimer: '',
|
uploadDisclaimer: '',
|
||||||
expirationNotice: {
|
expirationNotice: {
|
||||||
never: '',
|
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: {
|
expirationValues: {
|
||||||
|
|
|
@ -22,7 +22,8 @@ export default {
|
||||||
uploadDisclaimer: '',
|
uploadDisclaimer: '',
|
||||||
expirationNotice: {
|
expirationNotice: {
|
||||||
never: '',
|
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: {
|
expirationValues: {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="expirationDate" v-if="showExpirationNotice()">
|
<div class="expirationDate" v-if="showExpirationNotice()">
|
||||||
{{ expirationDate === null ? $t('expirationNotice.never') : $t('expirationNotice.ever', getExpirationNoticeDateTime()) }}
|
{{ getExpirationNotice() }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ export default {
|
||||||
return {
|
return {
|
||||||
uploadToken: shared.uploadToken,
|
uploadToken: shared.uploadToken,
|
||||||
message: null,
|
message: null,
|
||||||
expirationDate: null
|
expirationDate: null,
|
||||||
|
expiration: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ export default {
|
||||||
{
|
{
|
||||||
self.message = response.data.message;
|
self.message = response.data.message;
|
||||||
self.expirationDate = response.data.expirationDate !== null ? new Date(response.data.expirationDate) : null;
|
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;
|
var self = this;
|
||||||
|
|
||||||
if (self.expirationDate === null)
|
if (self.expirationDate != null)
|
||||||
return self.$i18n.t('expirationNotice.never') != '';
|
return self.$i18n.t('expirationNotice.date') != '';
|
||||||
else
|
|
||||||
return self.$i18n.t('expirationNotice.ever') != '';
|
if (self.expiration != null)
|
||||||
|
return self.$i18n.t('expirationNotice.timespan') != '';
|
||||||
|
|
||||||
|
return self.$i18n.t('expirationNotice.never') != '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
getExpirationNoticeDateTime()
|
getExpirationNotice()
|
||||||
{
|
{
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return {
|
if (self.expirationDate != null)
|
||||||
date: self.$options.filters.formatDate(self.expirationDate),
|
return self.$i18n.t('expirationNotice.date', {
|
||||||
time: self.$options.filters.formatTime(self.expirationDate)
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,14 @@
|
||||||
</select>
|
</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="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>
|
||||||
<div class="pure-form-description" v-if="!code.id && maxExpiration !== null">
|
<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>
|
||||||
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
|
@ -210,16 +214,16 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
getExpirationValueUnits()
|
getExpirationValueUnits(expiration)
|
||||||
{
|
{
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (self.maxExpiration === null)
|
if (expiration === null)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
return self.$tc('expirationValues.' + self.maxExpiration.units,
|
return self.$tc('expirationValues.' + expiration.units,
|
||||||
self.maxExpiration.value,
|
expiration.value,
|
||||||
{ count: self.maxExpiration.value });
|
{ count: expiration.value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue