aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/database/migrations/20190221225812_initialMigration.js22
-rw-r--r--src/api/database/seeds/initial.js2
-rw-r--r--src/api/databaseMigration.js14
-rw-r--r--src/api/routes/albums/albumZipGET.js4
-rw-r--r--src/api/routes/files/filesAlbumsGET.js2
-rw-r--r--src/api/routes/uploads/uploadPOST.js4
-rw-r--r--src/api/structures/Route.js8
-rw-r--r--src/api/structures/Server.js12
-rw-r--r--src/api/utils/QueryHelper.js14
-rw-r--r--src/api/utils/ThumbUtil.js4
-rw-r--r--src/api/utils/videoPreview/FragmentPreview.js4
-rw-r--r--src/api/utils/videoPreview/FrameIntervalPreview.js8
12 files changed, 49 insertions, 49 deletions
diff --git a/src/api/database/migrations/20190221225812_initialMigration.js b/src/api/database/migrations/20190221225812_initialMigration.js
index b755a33..92103c1 100644
--- a/src/api/database/migrations/20190221225812_initialMigration.js
+++ b/src/api/database/migrations/20190221225812_initialMigration.js
@@ -1,5 +1,5 @@
-exports.up = async (knex) => {
- await knex.schema.createTable('users', (table) => {
+exports.up = async knex => {
+ await knex.schema.createTable('users', table => {
table.increments();
table.string('username').unique();
table.text('password');
@@ -12,7 +12,7 @@ exports.up = async (knex) => {
table.timestamp('editedAt');
});
- await knex.schema.createTable('albums', (table) => {
+ await knex.schema.createTable('albums', table => {
table.increments();
table.integer('userId');
table.string('name');
@@ -24,7 +24,7 @@ exports.up = async (knex) => {
table.unique(['userId', 'name']);
});
- await knex.schema.createTable('files', (table) => {
+ await knex.schema.createTable('files', table => {
table.increments();
table.integer('userId');
table.string('name');
@@ -38,7 +38,7 @@ exports.up = async (knex) => {
table.timestamp('editedAt');
});
- await knex.schema.createTable('links', (table) => {
+ await knex.schema.createTable('links', table => {
table.increments();
table.integer('userId');
table.integer('albumId');
@@ -53,7 +53,7 @@ exports.up = async (knex) => {
table.unique(['userId', 'albumId', 'identifier']);
});
- await knex.schema.createTable('albumsFiles', (table) => {
+ await knex.schema.createTable('albumsFiles', table => {
table.increments();
table.integer('albumId');
table.integer('fileId');
@@ -61,13 +61,13 @@ exports.up = async (knex) => {
table.unique(['albumId', 'fileId']);
});
- await knex.schema.createTable('albumsLinks', (table) => {
+ await knex.schema.createTable('albumsLinks', table => {
table.increments();
table.integer('albumId');
table.integer('linkId').unique();
});
- await knex.schema.createTable('tags', (table) => {
+ await knex.schema.createTable('tags', table => {
table.increments();
table.string('uuid');
table.integer('userId');
@@ -78,7 +78,7 @@ exports.up = async (knex) => {
table.unique(['userId', 'name']);
});
- await knex.schema.createTable('fileTags', (table) => {
+ await knex.schema.createTable('fileTags', table => {
table.increments();
table.integer('fileId');
table.integer('tagId');
@@ -86,13 +86,13 @@ exports.up = async (knex) => {
table.unique(['fileId', 'tagId']);
});
- await knex.schema.createTable('bans', (table) => {
+ await knex.schema.createTable('bans', table => {
table.increments();
table.string('ip');
table.timestamp('createdAt');
});
};
-exports.down = async (knex) => {
+exports.down = async knex => {
await knex.schema.dropTableIfExists('users');
await knex.schema.dropTableIfExists('albums');
await knex.schema.dropTableIfExists('files');
diff --git a/src/api/database/seeds/initial.js b/src/api/database/seeds/initial.js
index 2383a7b..edc1949 100644
--- a/src/api/database/seeds/initial.js
+++ b/src/api/database/seeds/initial.js
@@ -2,7 +2,7 @@
const bcrypt = require('bcrypt');
const moment = require('moment');
-exports.seed = async (db) => {
+exports.seed = async db => {
const now = moment.utc().toDate();
const user = await db.table('users').where({ username: process.env.ADMIN_ACCOUNT }).first();
if (user) return;
diff --git a/src/api/databaseMigration.js b/src/api/databaseMigration.js
index 7e919f3..9afbb4a 100644
--- a/src/api/databaseMigration.js
+++ b/src/api/databaseMigration.js
@@ -27,7 +27,7 @@ const generateThumbnailForImage = async (filename, output) => {
}
};
-const generateThumbnailForVideo = (filename) => {
+const generateThumbnailForVideo = filename => {
try {
ffmpeg(nodePath.join(__dirname, '../../uploads', filename))
.thumbnail({
@@ -36,7 +36,7 @@ const generateThumbnailForVideo = (filename) => {
folder: nodePath.join(__dirname, '../../uploads/thumbs/square'),
size: '64x64'
})
- .on('error', (error) => console.error(error.message));
+ .on('error', error => console.error(error.message));
ffmpeg(nodePath.join(__dirname, '../../uploads', filename))
.thumbnail({
timestamps: [0],
@@ -44,7 +44,7 @@ const generateThumbnailForVideo = (filename) => {
folder: nodePath.join(__dirname, '../../uploads/thumbs'),
size: '150x?'
})
- .on('error', (error) => console.error(error.message));
+ .on('error', error => console.error(error.message));
console.log('finished', filename);
} catch (error) {
console.log('error', filename);
@@ -64,15 +64,15 @@ const newDb = require('knex')({
connection: {
filename: nodePath.join(__dirname, '../../', 'database.sqlite')
},
- postProcessResponse: (result) => {
+ postProcessResponse: result => {
const booleanFields = [
'enabled',
'enableDownload',
'isAdmin'
];
- const processResponse = (row) => {
- Object.keys(row).forEach((key) => {
+ const processResponse = row => {
+ Object.keys(row).forEach(key => {
if (booleanFields.includes(key)) {
if (row[key] === 0) row[key] = false;
else if (row[key] === 1) row[key] = true;
@@ -81,7 +81,7 @@ const newDb = require('knex')({
return row;
};
- if (Array.isArray(result)) return result.map((row) => processResponse(row));
+ if (Array.isArray(result)) return result.map(row => processResponse(row));
if (typeof result === 'object') return processResponse(result);
return result;
},
diff --git a/src/api/routes/albums/albumZipGET.js b/src/api/routes/albums/albumZipGET.js
index cf1f6f8..26da2ba 100644
--- a/src/api/routes/albums/albumZipGET.js
+++ b/src/api/routes/albums/albumZipGET.js
@@ -64,11 +64,11 @@ class albumGET extends Route {
/*
Get the actual files
*/
- const fileIds = fileList.map((el) => el.fileId);
+ const fileIds = fileList.map(el => el.fileId);
const files = await db.table('files')
.whereIn('id', fileIds)
.select('name');
- const filesToZip = files.map((el) => el.name);
+ const filesToZip = files.map(el => el.name);
try {
Util.createZip(filesToZip, album);
diff --git a/src/api/routes/files/filesAlbumsGET.js b/src/api/routes/files/filesAlbumsGET.js
index 90aa654..7f1190c 100644
--- a/src/api/routes/files/filesAlbumsGET.js
+++ b/src/api/routes/files/filesAlbumsGET.js
@@ -18,7 +18,7 @@ class filesGET extends Route {
.select('albumId');
if (albumFiles.length) {
- albumFiles = albumFiles.map((a) => a.albumId);
+ albumFiles = albumFiles.map(a => a.albumId);
albums = await db.table('albums')
.whereIn('id', albumFiles)
.select('id', 'name');
diff --git a/src/api/routes/uploads/uploadPOST.js b/src/api/routes/uploads/uploadPOST.js
index 567862a..5458d48 100644
--- a/src/api/routes/uploads/uploadPOST.js
+++ b/src/api/routes/uploads/uploadPOST.js
@@ -56,7 +56,7 @@ class uploadPOST extends Route {
if (!album) return res.status(401).json({ message: 'Album doesn\'t exist or it doesn\'t belong to the user' });
}
- return upload(req, res, async (err) => {
+ return upload(req, res, async err => {
if (err) console.error(err.message);
let uploadedFile = {};
@@ -142,7 +142,7 @@ class uploadPOST extends Route {
async checkIfFileExists(db, user, hash) {
const exists = await db.table('files')
- .where(function () { // eslint-disable-line func-names
+ .where(function() { // eslint-disable-line func-names
if (user) this.where('userId', user.id);
else this.whereNull('userId');
})
diff --git a/src/api/structures/Route.js b/src/api/structures/Route.js
index 74589c5..3806325 100644
--- a/src/api/structures/Route.js
+++ b/src/api/structures/Route.js
@@ -9,7 +9,7 @@ const db = require('knex')({
database: process.env.DB_DATABASE,
filename: nodePath.join(__dirname, '../../../database.sqlite')
},
- postProcessResponse: (result) => {
+ postProcessResponse: result => {
/*
Fun fact: Depending on the database used by the user and given that I don't want
to force a specific database for everyone because of the nature of this project,
@@ -18,8 +18,8 @@ const db = require('knex')({
*/
const booleanFields = ['enabled', 'enableDownload', 'isAdmin'];
- const processResponse = (row) => {
- Object.keys(row).forEach((key) => {
+ const processResponse = row => {
+ Object.keys(row).forEach(key => {
if (booleanFields.includes(key)) {
if (row[key] === 0) row[key] = false;
else if (row[key] === 1) row[key] = true;
@@ -28,7 +28,7 @@ const db = require('knex')({
return row;
};
- if (Array.isArray(result)) return result.map((row) => processResponse(row));
+ if (Array.isArray(result)) return result.map(row => processResponse(row));
if (typeof result === 'object') return processResponse(result);
return result;
},
diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js
index 83b2880..0ef91fd 100644
--- a/src/api/structures/Server.js
+++ b/src/api/structures/Server.js
@@ -42,16 +42,16 @@ class Server {
if (ext) { ext = `.${ext.toLowerCase()}`; }
if (
- ThumbUtil.imageExtensions.indexOf(ext) > -1
- || ThumbUtil.videoExtensions.indexOf(ext) > -1
- || req.path.indexOf('_nuxt') > -1
- || req.path.indexOf('favicon.ico') > -1
+ ThumbUtil.imageExtensions.indexOf(ext) > -1 ||
+ ThumbUtil.videoExtensions.indexOf(ext) > -1 ||
+ req.path.indexOf('_nuxt') > -1 ||
+ req.path.indexOf('favicon.ico') > -1
) {
return true;
}
return false;
},
- 'stream': {
+ stream: {
write(str) { log.debug(str); }
}
}));
@@ -64,7 +64,7 @@ class Server {
}
registerAllTheRoutes() {
- jetpack.find(this.routesFolder, { matching: '*.js' }).forEach((routeFile) => {
+ jetpack.find(this.routesFolder, { matching: '*.js' }).forEach(routeFile => {
// eslint-disable-next-line import/no-dynamic-require, global-require
const RouteClass = require(path.join('../../../', routeFile));
let routes = [RouteClass];
diff --git a/src/api/utils/QueryHelper.js b/src/api/utils/QueryHelper.js
index 7fabd06..c26c8eb 100644
--- a/src/api/utils/QueryHelper.js
+++ b/src/api/utils/QueryHelper.js
@@ -2,16 +2,16 @@ const chrono = require('chrono-node');
class QueryHelper {
static parsers = {
- before: (val) => QueryHelper.parseChronoList(val),
- after: (val) => QueryHelper.parseChronoList(val),
- tag: (val) => QueryHelper.sanitizeTags(val)
+ before: val => QueryHelper.parseChronoList(val),
+ after: val => QueryHelper.parseChronoList(val),
+ tag: val => QueryHelper.sanitizeTags(val)
};
static requirementHandlers = {
- album: (knex) => knex
+ album: knex => knex
.join('albumsFiles', 'files.id', '=', 'albumsFiles.fileId')
.join('albums', 'albumsFiles.albumId', '=', 'album.id'),
- tag: (knex) => knex
+ tag: knex => knex
.join('fileTags', 'files.id', '=', 'fileTags.fileId')
.join('tags', 'fileTags.tagId', '=', 'tags.id')
}
@@ -93,11 +93,11 @@ class QueryHelper {
}
static parseChronoList(list) {
- return list.map((e) => chrono.parse(e));
+ return list.map(e => chrono.parse(e));
}
static sanitizeTags(list) {
- return list.map((e) => e.replace(/\s/g, '_'));
+ return list.map(e => e.replace(/\s/g, '_'));
}
static generateInclusionForTags(db, knex, list) {
diff --git a/src/api/utils/ThumbUtil.js b/src/api/utils/ThumbUtil.js
index 10a7cd9..254090d 100644
--- a/src/api/utils/ThumbUtil.js
+++ b/src/api/utils/ThumbUtil.js
@@ -53,7 +53,7 @@ class ThumbUtil {
folder: ThumbUtil.squareThumbPath,
size: '64x64'
})
- .on('error', (error) => log.error(error.message));
+ .on('error', error => log.error(error.message));
ffmpeg(filePath)
.thumbnail({
@@ -62,7 +62,7 @@ class ThumbUtil {
folder: ThumbUtil.thumbPath,
size: '150x?'
})
- .on('error', (error) => log.error(error.message));
+ .on('error', error => log.error(error.message));
try {
await previewUtil({
diff --git a/src/api/utils/videoPreview/FragmentPreview.js b/src/api/utils/videoPreview/FragmentPreview.js
index 4f681fa..1d1ee02 100644
--- a/src/api/utils/videoPreview/FragmentPreview.js
+++ b/src/api/utils/videoPreview/FragmentPreview.js
@@ -25,7 +25,7 @@ const getStartTime = (vDuration, fDuration, ignoreBeforePercent, ignoreAfterPerc
return getRandomInt(ignoreBeforePercent * safeVDuration, ignoreAfterPercent * safeVDuration);
};
-module.exports = async (opts) => {
+module.exports = async opts => {
const {
log = noop,
@@ -78,7 +78,7 @@ module.exports = async (opts) => {
.outputOptions([`-t ${fragmentDurationSecond}`])
.noAudio()
.output(output)
- .on('start', (cmd) => log && log({ cmd }))
+ .on('start', cmd => log && log({ cmd }))
.on('end', resolve)
.on('error', reject)
.run();
diff --git a/src/api/utils/videoPreview/FrameIntervalPreview.js b/src/api/utils/videoPreview/FrameIntervalPreview.js
index 8bb9836..96c6e3a 100644
--- a/src/api/utils/videoPreview/FrameIntervalPreview.js
+++ b/src/api/utils/videoPreview/FrameIntervalPreview.js
@@ -4,7 +4,7 @@ const probe = require('ffmpeg-probe');
const noop = () => {};
-module.exports = async (opts) => {
+module.exports = async opts => {
const {
log = noop,
@@ -22,7 +22,7 @@ module.exports = async (opts) => {
const info = await probe(input);
// const numFramesTotal = parseInt(info.streams[0].nb_frames, 10);
const { avg_frame_rate: avgFrameRate, duration } = info.streams[0];
- const [frames, time] = avgFrameRate.split('/').map((e) => parseInt(e, 10));
+ const [frames, time] = avgFrameRate.split('/').map(e => parseInt(e, 10));
const numFramesTotal = (frames / time) * duration;
@@ -63,9 +63,9 @@ module.exports = async (opts) => {
.noAudio()
.outputFormat('webm')
.output(output)
- .on('start', (cmd) => log && log({ cmd }))
+ .on('start', cmd => log && log({ cmd }))
.on('end', () => resolve())
- .on('error', (err) => reject(err))
+ .on('error', err => reject(err))
.run();
});