Browse Source

Enviroment variables parsing fix

Pitu 6 years ago
parent
commit
73d85e8c79

+ 3 - 1
nuxt.config.js

@@ -14,7 +14,9 @@ export default {
 		serviceName: process.env.SERVICE_NAME,
 		serviceName: process.env.SERVICE_NAME,
 		maxFileSize: process.env.MAX_SIZE,
 		maxFileSize: process.env.MAX_SIZE,
 		chunkSize: process.env.CHUNK_SIZE,
 		chunkSize: process.env.CHUNK_SIZE,
-		maxLinksPerAlbum: process.env.MAX_LINKS_PER_ALBUM
+		maxLinksPerAlbum: process.env.MAX_LINKS_PER_ALBUM,
+		publicMode: process.env.PUBLIC_MODE,
+		userAccounts: process.env.USER_ACCOUNTS
 	},
 	},
 	srcDir: 'src/site/',
 	srcDir: 'src/site/',
 	head: {
 	head: {

+ 1 - 1
src/api/routes/albums/link/linkPOST.js

@@ -22,7 +22,7 @@ class linkPOST extends Route {
 			Count the amount of links created for that album already and error out if max was reached
 			Count the amount of links created for that album already and error out if max was reached
 		*/
 		*/
 		const count = await db.table('links').where('albumId', albumId).count({ count: 'id' });
 		const count = await db.table('links').where('albumId', albumId).count({ count: 'id' });
-		if (count[0].count >= process.env.MAX_LINKS_PER_ALBUM) return res.status(400).json({ message: 'Maximum links per album reached' });
+		if (count[0].count >= parseInt(process.env.MAX_LINKS_PER_ALBUM, 10)) return res.status(400).json({ message: 'Maximum links per album reached' });
 
 
 		/*
 		/*
 			Try to allocate a new identifier on the db
 			Try to allocate a new identifier on the db

+ 1 - 1
src/api/routes/auth/registerPOST.js

@@ -10,7 +10,7 @@ class registerPOST extends Route {
 	}
 	}
 
 
 	async run(req, res, db) {
 	async run(req, res, db) {
-		if (!process.env.USER_ACCOUNTS) return res.status(401).json({ message: 'Creation of new accounts is currently disabled' });
+		if (process.env.USER_ACCOUNTS == 'false') 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' });
 		if (!req.body) return res.status(400).json({ message: 'No body provided' });
 		const { username, password } = req.body;
 		const { username, password } = req.body;
 		if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' });
 		if (!username || !password) return res.status(401).json({ message: 'Invalid body provided' });

+ 2 - 2
src/api/routes/files/uploadPOST.js

@@ -181,7 +181,7 @@ class uploadPOST extends Route {
 		/*
 		/*
 			If exif removal has been force service-wide or requested by the user, remove it
 			If exif removal has been force service-wide or requested by the user, remove it
 		*/
 		*/
-		if (process.env.STRIP_EXIF) { // || user.settings.stripExif) {
+		if (process.env.STRIP_EXIF == 'true') { // || user.settings.stripExif) {
 			// Util.removeExif(upload.filename);
 			// Util.removeExif(upload.filename);
 		}
 		}
 
 
@@ -195,7 +195,7 @@ class uploadPOST extends Route {
 		const busboy = new Busboy({
 		const busboy = new Busboy({
 			headers: req.headers,
 			headers: req.headers,
 			limits: {
 			limits: {
-				fileSize: process.env.MAX_SIZE * (1000 * 1000),
+				fileSize: parseInt(process.env.MAX_SIZE, 10) * (1000 * 1000),
 				files: 1
 				files: 1
 			}
 			}
 		});
 		});

+ 9 - 9
src/api/routes/service/configGET.js

@@ -11,15 +11,15 @@ class configGET extends Route {
 			config: {
 			config: {
 				serviceName: process.env.SERVICE_NAME,
 				serviceName: process.env.SERVICE_NAME,
 				uploadFolder: process.env.UPLOAD_FOLDER,
 				uploadFolder: process.env.UPLOAD_FOLDER,
-				linksPerAlbum: process.env.MAX_LINKS_PER_ALBUM,
-				maxUploadSize: process.env.MAX_SIZE,
-				filenameLength: process.env.GENERATED_FILENAME_LENGTH,
-				albumLinkLength: process.env.GENERATED_ALBUM_LENGTH,
-				generateThumbnails: process.env.GENERATE_THUMBNAILS,
-				generateZips: process.env.GENERATE_ZIPS,
-				stripExif: process.env.STRIP_EXIF,
-				publicMode: process.env.PUBLIC_MODE,
-				enableAccounts: process.env.USER_ACCOUNTS
+				linksPerAlbum: parseInt(process.env.MAX_LINKS_PER_ALBUM, 10),
+				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' ? true : false,
+				generateZips: process.env.GENERATE_ZIPS == 'true' ? true : false,
+				stripExif: process.env.STRIP_EXIF == 'true' ? true : false,
+				publicMode: process.env.PUBLIC_MODE == 'true' ? true : false,
+				enableAccounts: process.env.USER_ACCOUNTS == 'true' ? true : false
 			}
 			}
 		});
 		});
 	}
 	}

+ 3 - 3
src/api/structures/Server.js

@@ -10,14 +10,14 @@ const jetpack = require('fs-jetpack');
 const path = require('path');
 const path = require('path');
 
 
 const rateLimiter = new RateLimit({
 const rateLimiter = new RateLimit({
-	windowMs: process.env.RATE_LIMIT_WINDOW,
-	max: process.env.RATE_LIMIT_MAX,
+	windowMs: parseInt(process.env.RATE_LIMIT_WINDOW, 10),
+	max: parseInt(process.env.RATE_LIMIT_MAX, 10),
 	delayMs: 0
 	delayMs: 0
 });
 });
 
 
 class Server {
 class Server {
 	constructor() {
 	constructor() {
-		this.port = process.env.SERVER_PORT;
+		this.port = parseInt(process.env.SERVER_PORT, 10);
 		this.server = express();
 		this.server = express();
 		this.server.set('trust proxy', 1);
 		this.server.set('trust proxy', 1);
 		this.server.use(helmet());
 		this.server.use(helmet());

+ 2 - 2
src/api/utils/Util.js

@@ -106,7 +106,7 @@ class Util {
 	static getUniqueFilename(name) {
 	static getUniqueFilename(name) {
 		const retry = (i = 0) => {
 		const retry = (i = 0) => {
 			const filename = randomstring.generate({
 			const filename = randomstring.generate({
-				length: process.env.GENERATED_FILENAME_LENGTH,
+				length: parseInt(process.env.GENERATED_FILENAME_LENGTH, 10),
 				capitalization: 'lowercase'
 				capitalization: 'lowercase'
 			}) + path.extname(name);
 			}) + path.extname(name);
 			const exists = jetpack.exists(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, filename));
 			const exists = jetpack.exists(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, filename));
@@ -121,7 +121,7 @@ class Util {
 	static getUniqueAlbumIdentifier() {
 	static getUniqueAlbumIdentifier() {
 		const retry = async (i = 0) => {
 		const retry = async (i = 0) => {
 			const identifier = randomstring.generate({
 			const identifier = randomstring.generate({
-				length: process.env.GENERATED_ALBUM_LENGTH,
+				length: parseInt(process.env.GENERATED_ALBUM_LENGTH, 10),
 				capitalization: 'lowercase'
 				capitalization: 'lowercase'
 			});
 			});
 			const exists = await db.table('links').where({ identifier }).first();
 			const exists = await db.table('links').where({ identifier }).first();

+ 8 - 2
src/site/pages/index.vue

@@ -51,7 +51,7 @@
 					<div class="columns">
 					<div class="columns">
 						<div class="column is-3 is-offset-2">
 						<div class="column is-3 is-offset-2">
 							<div class="logo">
 							<div class="logo">
-								<Logo/>
+								<Logo />
 							</div>
 							</div>
 						</div>
 						</div>
 						<div class="column is-5 centered">
 						<div class="column is-5 centered">
@@ -64,7 +64,10 @@
 						</div>
 						</div>
 					</div>
 					</div>
 					<div class="spacer mt7" />
 					<div class="spacer mt7" />
-					<Uploader />
+					<Uploader v-if="config.publicMode && !loggedIn" />
+					<div v-else>
+						This site has disabled public uploads. You need an account.
+					</div>
 				</div>
 				</div>
 			</div>
 			</div>
 			<div class="hero-foot">
 			<div class="hero-foot">
@@ -96,6 +99,9 @@ export default {
 	computed: {
 	computed: {
 		loggedIn() {
 		loggedIn() {
 			return this.$store.state.loggedIn;
 			return this.$store.state.loggedIn;
+		},
+		config() {
+			return this.$store.state.config;
 		}
 		}
 	},
 	},
 	mounted() {
 	mounted() {

+ 3 - 1
src/site/pages/login.vue

@@ -31,8 +31,10 @@
 						</b-field>
 						</b-field>
 
 
 						<p class="control has-addons is-pulled-right">
 						<p class="control has-addons is-pulled-right">
-							<router-link to="/register"
+							<router-link v-if="config.enableAccounts"
+								to="/register"
 								class="is-text">Don't have an account?</router-link>
 								class="is-text">Don't have an account?</router-link>
+							<span v-else>Registration is closed at the moment</span>
 							<a id="loginBtn"
 							<a id="loginBtn"
 								class="button"
 								class="button"
 								@click="login">Log in</a>
 								@click="login">Log in</a>

+ 5 - 3
src/site/store/index.js

@@ -44,9 +44,11 @@ const actions = {
 			URL: process.env.DOMAIN,
 			URL: process.env.DOMAIN,
 			baseURL: `${process.env.DOMAIN}${process.env.ROUTE_PREFIX}`,
 			baseURL: `${process.env.DOMAIN}${process.env.ROUTE_PREFIX}`,
 			serviceName: process.env.SERVICE_NAME,
 			serviceName: process.env.SERVICE_NAME,
-			maxFileSize: process.env.MAX_SIZE,
-			chunkSize: process.env.CHUNK_SIZE,
-			maxLinksPerAlbum: process.env.MAX_LINKS_PER_ALBUM
+			maxFileSize: parseInt(process.env.MAX_SIZE, 10),
+			chunkSize: parseInt(process.env.CHUNK_SIZE, 10),
+			maxLinksPerAlbum: parseInt(process.env.MAX_LINKS_PER_ALBUM, 10),
+			publicMode: process.env.PUBLIC_MODE == 'true' ? true : false,
+			enableAccounts: process.env.USER_ACCOUNTS == 'true' ? true : false
 		});
 		});
 	}
 	}
 };
 };