Max users

This commit is contained in:
ThatOneCalculator 2022-10-30 21:38:20 -07:00
parent 01e289c6de
commit db6e17364a
4 changed files with 15 additions and 1 deletions

View File

@ -144,3 +144,6 @@ id: 'aid'
# Upload or download file size limits (bytes)
#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 { dirname } from 'node:path';
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 _dirname = dirname(_filename);

View File

@ -63,6 +63,8 @@ export type Source = {
mediaProxy?: string;
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 { UsedUsername } from '@/models/entities/used-username.js';
import { db } from '@/db/postgre.js';
import config from '@/config/index.js';
export async function signup(opts: {
username: User['username'];
@ -21,6 +22,14 @@ export async function signup(opts: {
const { username, password, passwordHash, host } = opts;
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
if (!Users.validateLocalUsername(username)) {
throw new Error('INVALID_USERNAME');