Rename PERUSER => PER_USER

b9375ed7ea7b429147e17727586028722b26924f

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +8 -8Ignore whitespace
server.js+3 -3
@@ -65,7 +65,7 @@ const DEFAULT_WHITELIST = true;
65const DEFAULT_ACCOUNTS = false;65const DEFAULT_ACCOUNTS = false;
66const DEFAULT_CSRF_DISABLED = false;66const DEFAULT_CSRF_DISABLED = false;
67const DEFAULT_BASIC_AUTH = false;67const DEFAULT_BASIC_AUTH = false;
68const DEFAULT_PERUSER_BASIC_AUTH = false;68const DEFAULT_PER_USER_BASIC_AUTH = false;
6969
70const DEFAULT_ENABLE_IPV6 = false;70const DEFAULT_ENABLE_IPV6 = false;
71const DEFAULT_ENABLE_IPV4 = true;71const DEFAULT_ENABLE_IPV4 = true;
@@ -185,7 +185,7 @@ const enableWhitelist = cliArguments.whitelist ?? getConfigValue('whitelistMode'
185const dataRoot = cliArguments.dataRoot ?? getConfigValue('dataRoot', './data');185const dataRoot = cliArguments.dataRoot ?? getConfigValue('dataRoot', './data');
186const disableCsrf = cliArguments.disableCsrf ?? getConfigValue('disableCsrfProtection', DEFAULT_CSRF_DISABLED);186const disableCsrf = cliArguments.disableCsrf ?? getConfigValue('disableCsrfProtection', DEFAULT_CSRF_DISABLED);
187const basicAuthMode = cliArguments.basicAuthMode ?? getConfigValue('basicAuthMode', DEFAULT_BASIC_AUTH);187const basicAuthMode = cliArguments.basicAuthMode ?? getConfigValue('basicAuthMode', DEFAULT_BASIC_AUTH);
188const PERUSER_BASIC_AUTH = getConfigValue('perUserBasicAuth', DEFAULT_PERUSER_BASIC_AUTH);188const perUserBasicAuth = getConfigValue('perUserBasicAuth', DEFAULT_PER_USER_BASIC_AUTH);
189const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);189const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);
190190
191const uploadsPath = path.join(dataRoot, require('./src/constants').UPLOADS_DIRECTORY);191const uploadsPath = path.join(dataRoot, require('./src/constants').UPLOADS_DIRECTORY);
@@ -758,7 +758,7 @@ const postSetupTasks = async function (v6Failed, v4Failed) {
758 }758 }
759759
760 if (basicAuthMode) {760 if (basicAuthMode) {
761 if (!PERUSER_BASIC_AUTH) {761 if (!perUserBasicAuth) {
762 const basicAuthUser = getConfigValue('basicAuthUser', {});762 const basicAuthUser = getConfigValue('basicAuthUser', {});
763 if (!basicAuthUser?.username || !basicAuthUser?.password) {763 if (!basicAuthUser?.username || !basicAuthUser?.password) {
764 console.warn(color.yellow('Basic Authentication is enabled, but username or password is not set or empty!'));764 console.warn(color.yellow('Basic Authentication is enabled, but username or password is not set or empty!'));
src/middleware/basicAuth.js+3 -3
@@ -6,7 +6,7 @@ const { getAllUserHandles, toKey, getPasswordHash } = require('../users.js');
6const { getConfig, getConfigValue } = require('../util.js');6const { getConfig, getConfigValue } = require('../util.js');
7const storage = require('node-persist');7const storage = require('node-persist');
88
9const PERUSER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false);9const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false);
1010
11const unauthorizedResponse = (res) => {11const unauthorizedResponse = (res) => {
12 res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');12 res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
@@ -31,9 +31,9 @@ const basicAuthMiddleware = async function (request, response, callback) {
31 .toString('utf8')31 .toString('utf8')
32 .split(':');32 .split(':');
3333
34 if (! PERUSER_BASIC_AUTH && username === config.basicAuthUser.username && password === config.basicAuthUser.password) {34 if (! PER_USER_BASIC_AUTH && username === config.basicAuthUser.username && password === config.basicAuthUser.password) {
35 return callback();35 return callback();
36 } else if (PERUSER_BASIC_AUTH) {36 } else if (PER_USER_BASIC_AUTH) {
37 const userHandles = await getAllUserHandles();37 const userHandles = await getAllUserHandles();
38 for (const userHandle of userHandles) {38 for (const userHandle of userHandles) {
39 if (username == userHandle) {39 if (username == userHandle) {
src/users.js+2 -2
@@ -20,7 +20,7 @@ const KEY_PREFIX = 'user:';
20const AVATAR_PREFIX = 'avatar:';20const AVATAR_PREFIX = 'avatar:';
21const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false);21const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false);
22const AUTHELIA_AUTH = getConfigValue('autheliaAuth', false);22const AUTHELIA_AUTH = getConfigValue('autheliaAuth', false);
23const PERUSER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false);23const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false);
24const ANON_CSRF_SECRET = crypto.randomBytes(64).toString('base64');24const ANON_CSRF_SECRET = crypto.randomBytes(64).toString('base64');
2525
26/**26/**
@@ -588,7 +588,7 @@ async function tryAutoLogin(request) {
588 return true;588 return true;
589 }589 }
590590
591 if (PERUSER_BASIC_AUTH && await basicUserLogin(request)) {591 if (PER_USER_BASIC_AUTH && await basicUserLogin(request)) {
592 return true;592 return true;
593 }593 }
594 }594 }