mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
Max users
This commit is contained in:
parent
911c02ef3b
commit
511ff64191
4 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -63,6 +63,8 @@ export type Source = {
|
|||
|
||||
mediaProxy?: string;
|
||||
proxyRemoteFiles?: boolean;
|
||||
|
||||
maxUserSignups?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue