Moved file management into upload repository

Minor visual tweaks
This commit is contained in:
Mark van Renswoude 2018-05-02 20:28:32 +02:00
parent bb91384cab
commit c466db2431
6 changed files with 3823 additions and 3802 deletions

View File

@ -258,25 +258,7 @@ module.exports = (repository) =>
return; return;
} }
repository.uploads.delete(upload.id); await repository.uploads.delete(upload.id);
await Promise.all(upload.files.map(async (file) =>
{
if (!file.id) return;
if (!(await repository.uploads.fileExists(file.id)))
{
var fullpath = resolvePath(config.fileUpload.path, file.id);
try
{
await fs.unlink(fullpath);
}
catch (err)
{
console.log('Failed to delete ' + fullpath);
}
}
}));
res.sendStatus(200); res.sendStatus(200);
}); });
})); }));

View File

@ -1,5 +1,8 @@
const map = require('lodash/map'); const map = require('lodash/map');
const filter = require('lodash/filter'); const filter = require('lodash/filter');
const resolvePath = require('resolve-path');
const fs = require('mz/fs');
const config = require('../../config');
class Upload class Upload
@ -137,7 +140,7 @@ class UploadRepository
return new Promise((resolve, reject) => return new Promise((resolve, reject) =>
{ {
self.store.remove({ _id: uploadId }, (err, numRemoved) => self.store.findOne({ _id: uploadId }, (err, doc) =>
{ {
if (err) if (err)
{ {
@ -145,7 +148,41 @@ class UploadRepository
return; return;
} }
resolve(); if (doc === null)
{
resolve();
return;
}
let upload = new Upload(doc);
self.store.remove({ _id: uploadId }, async (err, numRemoved) =>
{
if (err)
{
reject(err);
return;
}
await Promise.all(upload.files.map(async (file) =>
{
if (!file.id) return;
if (!(await self.fileExists(file.id)))
{
var fullpath = resolvePath(config.fileUpload.path, file.id);
try
{
await fs.unlink(fullpath);
}
catch (err)
{
console.log('Failed to delete ' + fullpath);
}
}
}));
resolve();
});
}); });
}); });
} }

7556
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,7 @@ export default {
created: 'Date created', created: 'Date created',
description: 'Description', description: 'Description',
descriptionHint: 'The description will be visible only in the admin panel', descriptionHint: 'The description will be visible only in the admin panel',
expiration: 'Expiration', expiration: 'Expires after',
message: 'Message', message: 'Message',
messageHint: 'The message will be displayed to the user on the upload page after the code is entered. Markdown is supported.', messageHint: 'The message will be displayed to the user on the upload page after the code is entered. Markdown is supported.',

View File

@ -72,7 +72,7 @@ export default {
created: 'Datum aangemaakt', created: 'Datum aangemaakt',
description: 'Omschrijving', description: 'Omschrijving',
descriptionHint: 'De omschrijving is alleen zichtbaar in beheer', descriptionHint: 'De omschrijving is alleen zichtbaar in beheer',
expiration: 'Verloopt', expiration: 'Verloopt na',
message: 'Bericht', message: 'Bericht',
messageHint: 'Het bericht wordt getoond aan de gebruiker op de upload pagina na het invoeren van de code. Markdown kan worden gebruikt.', messageHint: 'Het bericht wordt getoond aan de gebruiker op de upload pagina na het invoeren van de code. Markdown kan worden gebruikt.',
@ -100,7 +100,7 @@ export default {
add: 'Gebruiker toevoegen', add: 'Gebruiker toevoegen',
list: { list: {
username: '(Gebruikers)naam', username: 'Gebruiker / naam',
inactive: '(inactief)', inactive: '(inactief)',
email: 'Email', email: 'Email',
actions: 'Acties' actions: 'Acties'

View File

@ -12,10 +12,12 @@
<a :href="getCodeUrl(code.id)" target="_blank">{{ getCodeUrl(code.id) }}</a> <a :href="getCodeUrl(code.id)" target="_blank">{{ getCodeUrl(code.id) }}</a>
</div> </div>
<!--
<div class="pure-control-group" v-if="code.id"> <div class="pure-control-group" v-if="code.id">
<label for="user">{{ $t('admin.codes.detail.owner') }}</label> <label for="user">{{ $t('admin.codes.detail.owner') }}</label>
<input id="user" type="text" readonly :value="code.username" class="pure-input-2-3"> <input id="user" type="text" readonly :value="code.username" class="pure-input-2-3">
</div> </div>
-->
<div class="pure-control-group" v-if="code.id"> <div class="pure-control-group" v-if="code.id">
<label for="created">{{ $t('admin.codes.detail.created') }}</label> <label for="created">{{ $t('admin.codes.detail.created') }}</label>