Max users

This commit is contained in:
ThatOneCalculator 2022-10-30 21:38:20 -07:00
parent 911c02ef3b
commit 511ff64191
4 changed files with 15 additions and 1 deletions

View File

@ -144,3 +144,6 @@ id: 'aid'
# Upload or download file size limits (bytes) # Upload or download file size limits (bytes)
#maxFileSize: 262144000 #maxFileSize: 262144000
# Maxium users, should be used for hosting management services
#maxUserSignups: 100

View File

@ -6,7 +6,7 @@ import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path'; import { dirname } from 'node:path';
import * as yaml from 'js-yaml'; import * as yaml from 'js-yaml';
import { Source, Mixin } from './types.js'; import type { Source, Mixin } from './types.js';
const _filename = fileURLToPath(import.meta.url); const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename); const _dirname = dirname(_filename);

View File

@ -63,6 +63,8 @@ export type Source = {
mediaProxy?: string; mediaProxy?: string;
proxyRemoteFiles?: boolean; proxyRemoteFiles?: boolean;
maxUserSignups?: number;
}; };
/** /**

View File

@ -11,6 +11,7 @@ import { UserKeypair } from '@/models/entities/user-keypair.js';
import { usersChart } from '@/services/chart/index.js'; import { usersChart } from '@/services/chart/index.js';
import { UsedUsername } from '@/models/entities/used-username.js'; import { UsedUsername } from '@/models/entities/used-username.js';
import { db } from '@/db/postgre.js'; import { db } from '@/db/postgre.js';
import config from '@/config/index.js';
export async function signup(opts: { export async function signup(opts: {
username: User['username']; username: User['username'];
@ -21,6 +22,14 @@ export async function signup(opts: {
const { username, password, passwordHash, host } = opts; const { username, password, passwordHash, host } = opts;
let hash = passwordHash; let hash = passwordHash;
const userCount = await Users.countBy({
host: IsNull(),
});
if (config.maxUserSignups != null && config.maxUserSignups > userCount) {
throw new Error('MAX_USERS_REACHED');
}
// Validate username // Validate username
if (!Users.validateLocalUsername(username)) { if (!Users.validateLocalUsername(username)) {
throw new Error('INVALID_USERNAME'); throw new Error('INVALID_USERNAME');