fix util
This commit is contained in:
parent
7674149085
commit
681ce2ac47
@ -158,7 +158,7 @@ export class Guild extends BaseClass {
|
|||||||
vanity_url_code?: string;
|
vanity_url_code?: string;
|
||||||
|
|
||||||
@JoinColumn({ name: "vanity_url_code" })
|
@JoinColumn({ name: "vanity_url_code" })
|
||||||
@OneToOne(() => Invite, (invite: Invite) => invite.code)
|
@ManyToOne(() => Invite)
|
||||||
vanity_url?: Invite;
|
vanity_url?: Invite;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
|
@ -148,8 +148,8 @@ export class Message extends BaseClass {
|
|||||||
party_id: string;
|
party_id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Column({ type: "bigint", nullable: true })
|
@Column({ nullable: true })
|
||||||
flags?: bigint;
|
flags?: string;
|
||||||
|
|
||||||
@RelationId((message: Message) => message.stickers)
|
@RelationId((message: Message) => message.stickers)
|
||||||
sticker_ids: string[];
|
sticker_ids: string[];
|
||||||
|
@ -7,12 +7,8 @@ export class RateLimit extends BaseClass {
|
|||||||
@Column()
|
@Column()
|
||||||
id: "global" | "error" | string; // channel_239842397 | guild_238927349823 | webhook_238923423498
|
id: "global" | "error" | string; // channel_239842397 | guild_238927349823 | webhook_238923423498
|
||||||
|
|
||||||
@RelationId((rate_limit: RateLimit) => rate_limit.user)
|
@Column() // no relation as it also
|
||||||
user_id: string;
|
executor_id: string;
|
||||||
|
|
||||||
@JoinColumn({ name: "user_id" })
|
|
||||||
@ManyToOne(() => User, (user) => user.id)
|
|
||||||
user: User;
|
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
hits: number;
|
hits: number;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
||||||
|
|
||||||
import { BaseClass } from "./BaseClass";
|
import { BaseClass } from "./BaseClass";
|
||||||
import { Guild } from "./Guild";
|
import { Guild } from "./Guild";
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ export class User extends BaseClass {
|
|||||||
avatar?: string; // hash of the user avatar
|
avatar?: string; // hash of the user avatar
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
accent_color?: number = 0; // banner color of user
|
accent_color?: number; // banner color of user
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
banner?: string; // hash of the user banner
|
banner?: string; // hash of the user banner
|
||||||
@ -58,52 +58,52 @@ export class User extends BaseClass {
|
|||||||
phone?: string; // phone number of the user
|
phone?: string; // phone number of the user
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
desktop: boolean = false; // if the user has desktop app installed
|
desktop: boolean; // if the user has desktop app installed
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
mobile: boolean = false; // if the user has mobile app installed
|
mobile: boolean; // if the user has mobile app installed
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
premium: boolean = false; // if user bought nitro
|
premium: boolean; // if user bought nitro
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
premium_type: number = 0; // nitro level
|
premium_type: number; // nitro level
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
bot: boolean = false; // if user is bot
|
bot: boolean; // if user is bot
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
bio: string = ""; // short description of the user (max 190 chars -> should be configurable)
|
bio: string; // short description of the user (max 190 chars -> should be configurable)
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
system: boolean = false; // shouldn't be used, the api sents this field type true, if the generated message comes from a system generated author
|
system: boolean; // shouldn't be used, the api sents this field type true, if the generated message comes from a system generated author
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
nsfw_allowed: boolean = false; // if the user is older than 18 (resp. Config)
|
nsfw_allowed: boolean; // if the user is older than 18 (resp. Config)
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
mfa_enabled: boolean = false; // if multi factor authentication is enabled
|
mfa_enabled: boolean; // if multi factor authentication is enabled
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
created_at: Date = new Date(); // registration date
|
created_at: Date = new Date(); // registration date
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
verified: boolean = false; // if the user is offically verified
|
verified: boolean; // if the user is offically verified
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
disabled: boolean = false; // if the account is disabled
|
disabled: boolean; // if the account is disabled
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
deleted: boolean = false; // if the user was deleted
|
deleted: boolean; // if the user was deleted
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
email?: string; // email of the user
|
email?: string; // email of the user
|
||||||
|
|
||||||
@Column({ type: "bigint" })
|
@Column()
|
||||||
flags: bigint = BigInt(0); // UserFlags
|
flags: string; // UserFlags
|
||||||
|
|
||||||
@Column({ type: "bigint" })
|
@Column()
|
||||||
public_flags: bigint = BigInt(0);
|
public_flags: string;
|
||||||
|
|
||||||
@RelationId((user: User) => user.relationships)
|
@RelationId((user: User) => user.relationships)
|
||||||
relationship_ids: string[]; // array of guild ids the user is part of
|
relationship_ids: string[]; // array of guild ids the user is part of
|
||||||
@ -123,13 +123,13 @@ export class User extends BaseClass {
|
|||||||
data: {
|
data: {
|
||||||
valid_tokens_since: Date; // all tokens with a previous issue date are invalid
|
valid_tokens_since: Date; // all tokens with a previous issue date are invalid
|
||||||
hash?: string; // hash of the password, salt is saved in password (bcrypt)
|
hash?: string; // hash of the password, salt is saved in password (bcrypt)
|
||||||
} = { valid_tokens_since: new Date() };
|
};
|
||||||
|
|
||||||
@Column({ type: "simple-array" })
|
@Column({ type: "simple-array" })
|
||||||
fingerprints: string[] = []; // array of fingerprints -> used to prevent multiple accounts
|
fingerprints: string[] = []; // array of fingerprints -> used to prevent multiple accounts
|
||||||
|
|
||||||
@Column({ type: "simple-json" })
|
@Column({ type: "simple-json" })
|
||||||
settings: UserSettings = defaultSettings;
|
settings: UserSettings;
|
||||||
|
|
||||||
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
|
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
|
||||||
const user = await User.findOne(user_id, {
|
const user = await User.findOne(user_id, {
|
||||||
|
@ -14,6 +14,7 @@ export * from "./RateLimit";
|
|||||||
export * from "./ReadState";
|
export * from "./ReadState";
|
||||||
export * from "./Relationship";
|
export * from "./Relationship";
|
||||||
export * from "./Role";
|
export * from "./Role";
|
||||||
|
export * from "./Sticker";
|
||||||
export * from "./Team";
|
export * from "./Team";
|
||||||
export * from "./TeamMember";
|
export * from "./TeamMember";
|
||||||
export * from "./Template";
|
export * from "./Template";
|
||||||
|
@ -515,4 +515,4 @@ export type EVENT =
|
|||||||
| "RELATIONSHIP_REMOVE"
|
| "RELATIONSHIP_REMOVE"
|
||||||
| CUSTOMEVENTS;
|
| CUSTOMEVENTS;
|
||||||
|
|
||||||
export type CUSTOMEVENTS = "INVALIDATED";
|
export type CUSTOMEVENTS = "INVALIDATED" | "RATELIMIT";
|
||||||
|
@ -6,6 +6,7 @@ var config: ConfigEntity;
|
|||||||
|
|
||||||
export const Config = {
|
export const Config = {
|
||||||
init: async function init() {
|
init: async function init() {
|
||||||
|
if (config) return config;
|
||||||
config = new ConfigEntity({}, { id: "0" });
|
config = new ConfigEntity({}, { id: "0" });
|
||||||
return this.set((config.value || {}).merge(DefaultConfigOptions));
|
return this.set((config.value || {}).merge(DefaultConfigOptions));
|
||||||
},
|
},
|
||||||
@ -13,7 +14,8 @@ export const Config = {
|
|||||||
return config.value as ConfigValue;
|
return config.value as ConfigValue;
|
||||||
},
|
},
|
||||||
set: function set(val: any) {
|
set: function set(val: any) {
|
||||||
config.value = val.merge(config.value);
|
if (!config) return;
|
||||||
|
config.value = val.merge(config?.value || {});
|
||||||
return config.save();
|
return config.save();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { Connection, createConnection } from "typeorm";
|
import { Connection, createConnection, ValueTransformer } from "typeorm";
|
||||||
import * as Models from "../entities";
|
import * as Models from "../entities";
|
||||||
|
|
||||||
// UUID extension option is only supported with postgres
|
// UUID extension option is only supported with postgres
|
||||||
@ -14,10 +14,10 @@ export function initDatabase() {
|
|||||||
console.log("[Database] connecting ...");
|
console.log("[Database] connecting ...");
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
promise = createConnection({
|
promise = createConnection({
|
||||||
// type: "sqlite",
|
type: "sqlite",
|
||||||
// database: "database.db",
|
database: "database.db",
|
||||||
type: "postgres",
|
// type: "postgres",
|
||||||
url: "postgres://fosscord:wb94SmuURM2Syv&@localhost/fosscord",
|
// url: "postgres://fosscord:wb94SmuURM2Syv&@localhost/fosscord",
|
||||||
//
|
//
|
||||||
entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"),
|
entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"),
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
@ -25,6 +25,8 @@ export function initDatabase() {
|
|||||||
cache: {
|
cache: {
|
||||||
duration: 1000 * 3, // cache all find queries for 3 seconds
|
duration: 1000 * 3, // cache all find queries for 3 seconds
|
||||||
},
|
},
|
||||||
|
bigNumberStrings: false,
|
||||||
|
supportBigNumbers: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
promise.then((connection) => {
|
promise.then((connection) => {
|
||||||
|
@ -12,7 +12,8 @@ export function checkToken(token: string, jwtSecret: string): Promise<any> {
|
|||||||
const user = await User.findOne({ id: decoded.id }, { select: ["data", "bot", "disabled", "deleted"] });
|
const user = await User.findOne({ id: decoded.id }, { select: ["data", "bot", "disabled", "deleted"] });
|
||||||
if (!user) return rej("Invalid Token");
|
if (!user) return rej("Invalid Token");
|
||||||
// we need to round it to seconds as it saved as seconds in jwt iat and valid_tokens_since is stored in milliseconds
|
// we need to round it to seconds as it saved as seconds in jwt iat and valid_tokens_since is stored in milliseconds
|
||||||
if (decoded.iat * 1000 < user.data.valid_tokens_since.setSeconds(0, 0)) return rej("Invalid Token");
|
if (decoded.iat * 1000 < new Date(user.data.valid_tokens_since).setSeconds(0, 0))
|
||||||
|
return rej("Invalid Token");
|
||||||
if (user.disabled) return rej("User disabled");
|
if (user.disabled) return rej("User disabled");
|
||||||
if (user.deleted) return rej("User not found");
|
if (user.deleted) return rej("User not found");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user