mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 13:14:06 +01:00
Merge pull request #4 from notsapinho/main
added toBigInt and BigInt getters to bitfields
This commit is contained in:
commit
c5c2af70a5
@ -1,5 +1,6 @@
|
|||||||
import { Schema, model, Types, Document } from "mongoose";
|
import { Schema, model, Types, Document } from "mongoose";
|
||||||
import db from "../util/Database";
|
import db from "../util/Database";
|
||||||
|
import toBigInt from "../util/toBigInt";
|
||||||
|
|
||||||
export interface AnyChannel extends Channel, DMChannel, TextChannel, VoiceChannel {}
|
export interface AnyChannel extends Channel, DMChannel, TextChannel, VoiceChannel {}
|
||||||
|
|
||||||
@ -24,8 +25,8 @@ export const ChannelSchema = new Schema({
|
|||||||
topic: String,
|
topic: String,
|
||||||
permission_overwrites: [
|
permission_overwrites: [
|
||||||
{
|
{
|
||||||
allow: Types.Long,
|
allow: { type: String, get: toBigInt },
|
||||||
deny: Types.Long,
|
deny: { type: String, get: toBigInt },
|
||||||
id: String,
|
id: String,
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
@ -32,6 +32,8 @@ export interface Guild {
|
|||||||
// channels: GuildChannel[]; // * Channels are stored in a seperate collection
|
// channels: GuildChannel[]; // * Channels are stored in a seperate collection
|
||||||
// emojis: Emoji[]; // * Emojis are stored in a seperate collection
|
// emojis: Emoji[]; // * Emojis are stored in a seperate collection
|
||||||
// voice_states: []; // * voice_states are stored in a seperate collection
|
// voice_states: []; // * voice_states are stored in a seperate collection
|
||||||
|
//TODO:
|
||||||
|
presences?: object[];
|
||||||
mfa_level?: number;
|
mfa_level?: number;
|
||||||
name: string;
|
name: string;
|
||||||
owner_id: string;
|
owner_id: string;
|
||||||
@ -69,6 +71,7 @@ export const GuildSchema = new Schema({
|
|||||||
max_presences: Number,
|
max_presences: Number,
|
||||||
max_video_channel_users: { type: Number, default: 25 },
|
max_video_channel_users: { type: Number, default: 25 },
|
||||||
member_count: Number,
|
member_count: Number,
|
||||||
|
presences: { type: [Object], default: [] },
|
||||||
presence_count: Number,
|
presence_count: Number,
|
||||||
mfa_level: Number,
|
mfa_level: Number,
|
||||||
name: { type: String, required: true },
|
name: { type: String, required: true },
|
||||||
@ -98,6 +101,7 @@ GuildSchema.virtual("channels", {
|
|||||||
justOne: false,
|
justOne: false,
|
||||||
autopopulate: true,
|
autopopulate: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
GuildSchema.virtual("roles", {
|
GuildSchema.virtual("roles", {
|
||||||
ref: RoleModel,
|
ref: RoleModel,
|
||||||
localField: "id",
|
localField: "id",
|
||||||
@ -128,7 +132,7 @@ GuildSchema.virtual("joined_at", {
|
|||||||
foreignField: "guild_id",
|
foreignField: "guild_id",
|
||||||
justOne: true,
|
justOne: true,
|
||||||
}).get((member: any, virtual: any, doc: any) => {
|
}).get((member: any, virtual: any, doc: any) => {
|
||||||
return member.joined_at;
|
return member?.joined_at;
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Schema, model, Types, Document } from "mongoose";
|
import { Schema, model, Types, Document } from "mongoose";
|
||||||
import db from "../util/Database";
|
import db from "../util/Database";
|
||||||
|
import toBigInt from "../util/toBigInt";
|
||||||
|
|
||||||
export interface Role {
|
export interface Role {
|
||||||
id: string;
|
id: string;
|
||||||
@ -28,12 +29,13 @@ export const RoleSchema = new Schema({
|
|||||||
managed: Boolean,
|
managed: Boolean,
|
||||||
mentionable: Boolean,
|
mentionable: Boolean,
|
||||||
name: String,
|
name: String,
|
||||||
permissions: Types.Long,
|
permissions: { type: String, get: toBigInt },
|
||||||
position: Number,
|
position: Number,
|
||||||
tags: {
|
tags: {
|
||||||
bot_id: String,
|
bot_id: String,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
RoleSchema.set("removeResponse", ["guild_id"]);
|
RoleSchema.set("removeResponse", ["guild_id"]);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -2,6 +2,7 @@ import { Activity } from "./Activity";
|
|||||||
import { ClientStatus, Status } from "./Status";
|
import { ClientStatus, Status } from "./Status";
|
||||||
import { Schema, Types, Document } from "mongoose";
|
import { Schema, Types, Document } from "mongoose";
|
||||||
import db from "../util/Database";
|
import db from "../util/Database";
|
||||||
|
import toBigInt from "../util/toBigInt";
|
||||||
|
|
||||||
export const PublicUserProjection = {
|
export const PublicUserProjection = {
|
||||||
username: true,
|
username: true,
|
||||||
@ -141,8 +142,8 @@ export const UserSchema = new Schema({
|
|||||||
created_at: Date,
|
created_at: Date,
|
||||||
verified: Boolean,
|
verified: Boolean,
|
||||||
email: String,
|
email: String,
|
||||||
flags: Types.Long, // TODO: automatically convert Types.Long to BitField of UserFlags
|
flags: { type: String, get: toBigInt }, // TODO: automatically convert Types.Long to BitField of UserFlags
|
||||||
public_flags: Types.Long,
|
public_flags: { type: String, get: toBigInt },
|
||||||
guilds: [String], // array of guild ids the user is part of
|
guilds: [String], // array of guild ids the user is part of
|
||||||
user_data: {
|
user_data: {
|
||||||
fingerprints: [String],
|
fingerprints: [String],
|
||||||
|
@ -7,7 +7,12 @@ const uri = process.env.MONGO_URL || "mongodb://localhost:27017/fosscord?readPre
|
|||||||
|
|
||||||
console.log(`[DB] connect: ${uri}`);
|
console.log(`[DB] connect: ${uri}`);
|
||||||
|
|
||||||
const connection = mongoose.createConnection(uri, { autoIndex: true, useNewUrlParser: true, useUnifiedTopology: true });
|
const connection = mongoose.createConnection(uri, {
|
||||||
|
autoIndex: true,
|
||||||
|
useNewUrlParser: true,
|
||||||
|
useUnifiedTopology: true,
|
||||||
|
useFindAndModify: false,
|
||||||
|
});
|
||||||
|
|
||||||
export default <Connection>connection;
|
export default <Connection>connection;
|
||||||
|
|
||||||
@ -56,6 +61,12 @@ export class MongooseCache extends EventEmitter {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
changeStream = (pipeline: any) => {
|
||||||
|
this.pipeline = pipeline;
|
||||||
|
this.destroy();
|
||||||
|
this.init();
|
||||||
|
};
|
||||||
|
|
||||||
convertResult = (obj: any) => {
|
convertResult = (obj: any) => {
|
||||||
if (obj instanceof Long) return BigInt(obj.toString());
|
if (obj instanceof Long) return BigInt(obj.toString());
|
||||||
if (typeof obj === "object") {
|
if (typeof obj === "object") {
|
||||||
|
@ -44,7 +44,7 @@ class LongSchema extends mongoose.SchemaType {
|
|||||||
if (val instanceof Number || "number" == typeof val) return BigInt(val);
|
if (val instanceof Number || "number" == typeof val) return BigInt(val);
|
||||||
if (!Array.isArray(val) && val.toString) return BigInt(val.toString());
|
if (!Array.isArray(val) && val.toString) return BigInt(val.toString());
|
||||||
|
|
||||||
// @ts-ignore
|
//@ts-ignore
|
||||||
throw new SchemaType.CastError("Long", val);
|
throw new SchemaType.CastError("Long", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import Config from "./Config";
|
|||||||
|
|
||||||
export function checkToken(token: string): Promise<any> {
|
export function checkToken(token: string): Promise<any> {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
jwt.verify(token, Config.getAll().api.security.jwtSecret, JWTOptions, (err, decoded: any) => {
|
jwt.verify(token, Config.getAll()?.api?.security?.jwtSecret, JWTOptions, (err, decoded: any) => {
|
||||||
if (err || !decoded) return rej("Invalid Token");
|
if (err || !decoded) return rej("Invalid Token");
|
||||||
|
|
||||||
return res(decoded);
|
return res(decoded);
|
||||||
|
@ -5,3 +5,4 @@ export * from "./MessageFlags";
|
|||||||
export * from "./Permissions";
|
export * from "./Permissions";
|
||||||
export * from "./Snowflake";
|
export * from "./Snowflake";
|
||||||
export * from "./UserFlags";
|
export * from "./UserFlags";
|
||||||
|
export * from "./toBigInt"
|
3
src/util/toBigInt.ts
Normal file
3
src/util/toBigInt.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default function toBigInt(string: String): BigInt {
|
||||||
|
return BigInt(string);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user