aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-06-15 00:12:26 +0900
committerPitu <[email protected]>2021-06-15 00:12:26 +0900
commitd3c80127ecdc83cffb9ba9a05f47452fec60287c (patch)
treefb056e08947393a6487238b247703565f049a149 /src/api/routes
parentchore: get host from req instead of config (diff)
downloadhost.fuwn.me-d3c80127ecdc83cffb9ba9a05f47452fec60287c.tar.xz
host.fuwn.me-d3c80127ecdc83cffb9ba9a05f47452fec60287c.zip
chore: update process.env usage
Diffstat (limited to 'src/api/routes')
-rw-r--r--src/api/routes/albums/albumZipGET.js8
-rw-r--r--src/api/routes/auth/loginPOST.js3
-rw-r--r--src/api/routes/auth/registerPOST.js2
-rw-r--r--src/api/routes/service/configGET.js17
-rw-r--r--src/api/routes/uploads/uploadPOST.js8
5 files changed, 19 insertions, 19 deletions
diff --git a/src/api/routes/albums/albumZipGET.js b/src/api/routes/albums/albumZipGET.js
index 22b0b6f..8def099 100644
--- a/src/api/routes/albums/albumZipGET.js
+++ b/src/api/routes/albums/albumZipGET.js
@@ -38,13 +38,13 @@ class albumGET extends Route {
If the date when the album was zipped is greater than the album's last edit, we just send the zip to the user
*/
if (album.zippedAt > album.editedAt) {
- const filePath = path.join(__dirname, '../../../../', process.env.UPLOAD_FOLDER, 'zips', `${album.userId}-${album.id}.zip`);
+ const filePath = path.join(__dirname, '../../../../uploads', 'zips', `${album.userId}-${album.id}.zip`);
const exists = await jetpack.existsAsync(filePath);
/*
Make sure the file exists just in case, and if not, continue to it's generation.
*/
if (exists) {
- const fileName = `${process.env.SERVICE_NAME}-${identifier}.zip`;
+ const fileName = `${Util.config.serviceName}-${identifier}.zip`;
return res.download(filePath, fileName);
}
}
@@ -77,8 +77,8 @@ class albumGET extends Route {
.update('zippedAt', db.fn.now())
.wasMutated();
- const filePath = path.join(__dirname, '../../../../', process.env.UPLOAD_FOLDER, 'zips', `${album.userId}-${album.id}.zip`);
- const fileName = `${process.env.SERVICE_NAME}-${identifier}.zip`;
+ const filePath = path.join(__dirname, '../../../../uploads', 'zips', `${album.userId}-${album.id}.zip`);
+ const fileName = `${Util.config.serviceName}-${identifier}.zip`;
return res.download(filePath, fileName);
} catch (error) {
log.error(error);
diff --git a/src/api/routes/auth/loginPOST.js b/src/api/routes/auth/loginPOST.js
index 373252b..cc72145 100644
--- a/src/api/routes/auth/loginPOST.js
+++ b/src/api/routes/auth/loginPOST.js
@@ -2,6 +2,7 @@ const bcrypt = require('bcrypt');
const moment = require('moment');
const JWT = require('jsonwebtoken');
const Route = require('../../structures/Route');
+const Util = require('../../utils/Util');
class loginPOST extends Route {
constructor() {
@@ -37,7 +38,7 @@ class loginPOST extends Route {
iss: 'chibisafe',
sub: user.id,
iat: moment.utc().valueOf()
- }, process.env.SECRET, { expiresIn: '30d' });
+ }, Util.config.secret, { expiresIn: '30d' });
return res.json({
message: 'Successfully logged in.',
diff --git a/src/api/routes/auth/registerPOST.js b/src/api/routes/auth/registerPOST.js
index 7b9eb3c..e740c83 100644
--- a/src/api/routes/auth/registerPOST.js
+++ b/src/api/routes/auth/registerPOST.js
@@ -12,7 +12,7 @@ class registerPOST extends Route {
async run(req, res, db) {
// Only allow admins to create new accounts if the sign up is deactivated
const user = await Util.isAuthorized(req);
- if ((!user || !user.isAdmin) && process.env.USER_ACCOUNTS === 'false') return res.status(401).json({ message: 'Creation of new accounts is currently disabled' });
+ if ((!user || !user.isAdmin) && !Util.config.userAccounts) return res.status(401).json({ message: 'Creation of new accounts is currently disabled' });
if (!req.body) return res.status(400).json({ message: 'No body provided' });
const { username, password } = req.body;
diff --git a/src/api/routes/service/configGET.js b/src/api/routes/service/configGET.js
index 291f0a4..b0a9c16 100644
--- a/src/api/routes/service/configGET.js
+++ b/src/api/routes/service/configGET.js
@@ -1,4 +1,5 @@
const Route = require('../../structures/Route');
+const Util = require('../../utils/Util');
class configGET extends Route {
constructor() {
@@ -9,15 +10,13 @@ class configGET extends Route {
return res.json({
message: 'Successfully retrieved config',
config: {
- serviceName: process.env.SERVICE_NAME,
- uploadFolder: process.env.UPLOAD_FOLDER,
- maxUploadSize: parseInt(process.env.MAX_SIZE, 10),
- filenameLength: parseInt(process.env.GENERATED_FILENAME_LENGTH, 10),
- albumLinkLength: parseInt(process.env.GENERATED_ALBUM_LENGTH, 10),
- generateThumbnails: process.env.GENERATE_THUMBNAILS === 'true',
- generateZips: process.env.GENERATE_ZIPS === 'true',
- publicMode: process.env.PUBLIC_MODE === 'true',
- enableAccounts: process.env.USER_ACCOUNTS === 'true'
+ serviceName: Util.config.serviceName,
+ maxUploadSize: Util.config.maxSize,
+ filenameLength: Util.config.generatedFilenameLength,
+ albumLinkLength: Util.config.generatedAlbumLength,
+ generateZips: Util.config.generateZips,
+ publicMode: Util.config.publicMode,
+ enableAccounts: Util.config.userAccounts
}
});
}
diff --git a/src/api/routes/uploads/uploadPOST.js b/src/api/routes/uploads/uploadPOST.js
index 7386490..4e96c80 100644
--- a/src/api/routes/uploads/uploadPOST.js
+++ b/src/api/routes/uploads/uploadPOST.js
@@ -8,8 +8,8 @@ const multerStorage = require('../../utils/multerStorage');
const chunksData = {};
const chunkedUploadsTimeout = 1800000;
-const chunksDir = path.join(__dirname, '../../../../', process.env.UPLOAD_FOLDER, 'chunks');
-const uploadDir = path.join(__dirname, '../../../../', process.env.UPLOAD_FOLDER);
+const chunksDir = path.join(__dirname, '../../../../uploads/chunks');
+const uploadDir = path.join(__dirname, '../../../../uploads');
const cleanUpChunks = async (uuid, onTimeout) => {
@@ -72,7 +72,7 @@ const initChunks = async uuid => {
const executeMulter = multer({
// Guide: https://github.com/expressjs/multer#limits
limits: {
- fileSize: parseInt(process.env.MAX_SIZE, 10) * (1000 * 1000),
+ fileSize: Util.config.maxSize * (1000 * 1000),
// Maximum number of non-file fields.
// Dropzone.js will add 6 extra fields for chunked uploads.
// We don't use them for anything else.
@@ -257,7 +257,7 @@ class uploadPOST extends Route {
async run(req, res, db) {
const user = await Util.isAuthorized(req);
- if (!user && process.env.PUBLIC_MODE === 'false') return res.status(401).json({ message: 'Not authorized to use this resource' });
+ if (!user && !Util.config.publicMode) return res.status(401).json({ message: 'Not authorized to use this resource' });
const { finishedchunks } = req.headers;
const albumId = req.headers.albumid ? req.headers.albumid === 'null' ? null : req.headers.albumid : null;
if (albumId && !user) return res.status(401).json({ message: 'Only registered users can upload files to an album' });