mirror of
https://github.com/spacebarchat/server.git
synced 2026-03-30 18:15:41 +00:00
Prettier u6
This commit is contained in:
@@ -42,8 +42,7 @@ export abstract class Connection {
|
||||
* @returns redirect_uri for this connection
|
||||
*/
|
||||
getRedirectUri() {
|
||||
const endpointPublic =
|
||||
Config.get().general.frontPage ?? "http://localhost:3001";
|
||||
const endpointPublic = Config.get().general.frontPage ?? "http://localhost:3001";
|
||||
return `${endpointPublic}/connections/${this.id}/callback`;
|
||||
}
|
||||
|
||||
@@ -51,9 +50,7 @@ export abstract class Connection {
|
||||
* Processes the callback
|
||||
* @param args Callback arguments
|
||||
*/
|
||||
abstract handleCallback(
|
||||
params: ConnectionCallbackSchema,
|
||||
): Promise<ConnectedAccount | null>;
|
||||
abstract handleCallback(params: ConnectionCallbackSchema): Promise<ConnectedAccount | null>;
|
||||
|
||||
/**
|
||||
* Gets a user id from state
|
||||
@@ -91,9 +88,7 @@ export abstract class Connection {
|
||||
* @param data connected account data
|
||||
* @returns the new connected account
|
||||
*/
|
||||
async createConnection(
|
||||
data: ConnectedAccountSchema,
|
||||
): Promise<ConnectedAccount> {
|
||||
async createConnection(data: ConnectedAccountSchema): Promise<ConnectedAccount> {
|
||||
const ca = ConnectedAccount.create({ ...data });
|
||||
await ca.save();
|
||||
return ca;
|
||||
|
||||
@@ -49,12 +49,7 @@ export const ConnectionConfig = {
|
||||
|
||||
function applyConfig(val: any) {
|
||||
async function apply(obj: any, key = ""): Promise<any> {
|
||||
if (typeof obj === "object" && obj !== null && !(obj instanceof Date))
|
||||
return Promise.all(
|
||||
Object.keys(obj).map((k) =>
|
||||
apply(obj[k], key ? `${key}_${k}` : k),
|
||||
),
|
||||
);
|
||||
if (typeof obj === "object" && obj !== null && !(obj instanceof Date)) return Promise.all(Object.keys(obj).map((k) => apply(obj[k], key ? `${key}_${k}` : k)));
|
||||
|
||||
let pair = pairs.find((x) => x.key === key);
|
||||
if (!pair) pair = new ConnectionConfigEntity();
|
||||
@@ -84,8 +79,7 @@ function pairsToConfig(pairs: ConnectionConfigEntity[]) {
|
||||
let i = 0;
|
||||
|
||||
for (const key of keys) {
|
||||
if (!isNaN(Number(key)) && !prevObj[prev]?.length)
|
||||
prevObj[prev] = obj = [];
|
||||
if (!isNaN(Number(key)) && !prevObj[prev]?.length) prevObj[prev] = obj = [];
|
||||
if (i++ === keys.length - 1) obj[key] = p.value;
|
||||
else if (!obj[key]) obj[key] = {};
|
||||
|
||||
|
||||
@@ -67,18 +67,11 @@ export class ConnectionLoader {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public static async setConnectionConfig(
|
||||
id: string,
|
||||
config: Partial<unknown>,
|
||||
): Promise<void> {
|
||||
if (!config)
|
||||
console.warn(`[Connections/WARN] ${id} tried to set config=null!`);
|
||||
public static async setConnectionConfig(id: string, config: Partial<unknown>): Promise<void> {
|
||||
if (!config) console.warn(`[Connections/WARN] ${id} tried to set config=null!`);
|
||||
|
||||
await ConnectionConfig.set({
|
||||
[id]: Object.assign(
|
||||
config,
|
||||
ConnectionLoader.getConnectionConfig(id) || {},
|
||||
),
|
||||
[id]: Object.assign(config, ConnectionLoader.getConnectionConfig(id) || {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,10 @@ export class ConnectedAccountDTO {
|
||||
metadata_visibility?: number;
|
||||
two_way_link?: boolean;
|
||||
|
||||
constructor(
|
||||
connectedAccount: ConnectedAccount,
|
||||
with_token: boolean = false,
|
||||
) {
|
||||
constructor(connectedAccount: ConnectedAccount, with_token: boolean = false) {
|
||||
this.id = connectedAccount.external_id;
|
||||
this.user_id = connectedAccount.user_id;
|
||||
this.access_token =
|
||||
connectedAccount.token_data && with_token
|
||||
? connectedAccount.token_data.access_token
|
||||
: undefined;
|
||||
this.access_token = connectedAccount.token_data && with_token ? connectedAccount.token_data.access_token : undefined;
|
||||
this.friend_sync = connectedAccount.friend_sync;
|
||||
this.name = connectedAccount.name;
|
||||
this.revoked = connectedAccount.revoked;
|
||||
@@ -53,9 +47,7 @@ export class ConnectedAccountDTO {
|
||||
this.visibility = +(connectedAccount.visibility || false);
|
||||
this.integrations = connectedAccount.integrations;
|
||||
this.metadata_ = connectedAccount.metadata_;
|
||||
this.metadata_visibility = +(
|
||||
connectedAccount.metadata_visibility || false
|
||||
);
|
||||
this.metadata_visibility = +(connectedAccount.metadata_visibility || false);
|
||||
this.two_way_link = connectedAccount.two_way_link;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,7 @@ export class DmChannelDTO {
|
||||
recipients: MinimalPublicUserDTO[];
|
||||
type: number;
|
||||
|
||||
static async from(
|
||||
channel: Channel,
|
||||
excluded_recipients: string[] = [],
|
||||
origin_channel_id?: string,
|
||||
) {
|
||||
static async from(channel: Channel, excluded_recipients: string[] = [], origin_channel_id?: string) {
|
||||
const obj = new DmChannelDTO();
|
||||
obj.icon = channel.icon || null;
|
||||
obj.id = channel.id;
|
||||
@@ -61,9 +57,7 @@ export class DmChannelDTO {
|
||||
excludedRecipients(excluded_recipients: string[]): DmChannelDTO {
|
||||
return {
|
||||
...this,
|
||||
recipients: this.recipients.filter(
|
||||
(r) => !excluded_recipients.includes(r.id),
|
||||
),
|
||||
recipients: this.recipients.filter((r) => !excluded_recipients.includes(r.id)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,11 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
Channel,
|
||||
Emoji,
|
||||
Guild,
|
||||
Role,
|
||||
Sticker,
|
||||
} from "../entities";
|
||||
import { Channel, Emoji, Guild, Role, Sticker } from "../entities";
|
||||
import { ChannelOverride, ChannelType, PublicMember, PublicUser, UserGuildSettings } from "@spacebar/schemas";
|
||||
|
||||
// TODO: this is not the best place for this type
|
||||
export type ReadyUserGuildSettingsEntries = Omit<
|
||||
UserGuildSettings,
|
||||
"channel_overrides"
|
||||
> & {
|
||||
export type ReadyUserGuildSettingsEntries = Omit<UserGuildSettings, "channel_overrides"> & {
|
||||
channel_overrides: (ChannelOverride & { channel_id: string })[];
|
||||
};
|
||||
|
||||
@@ -43,13 +34,9 @@ export interface ReadyPrivateChannel {
|
||||
type: ChannelType.DM | ChannelType.GROUP_DM;
|
||||
}
|
||||
|
||||
export type GuildOrUnavailable =
|
||||
| { id: string; unavailable: boolean }
|
||||
| (Guild & { joined_at?: Date; unavailable: undefined });
|
||||
export type GuildOrUnavailable = { id: string; unavailable: boolean } | (Guild & { joined_at?: Date; unavailable: undefined });
|
||||
|
||||
const guildIsAvailable = (
|
||||
guild: GuildOrUnavailable,
|
||||
): guild is Guild & { joined_at: Date; unavailable: false } => {
|
||||
const guildIsAvailable = (guild: GuildOrUnavailable): guild is Guild & { joined_at: Date; unavailable: false } => {
|
||||
return guild.unavailable != true;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,22 +16,11 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
BeforeRemove,
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
RelationId,
|
||||
} from "typeorm";
|
||||
import { BeforeRemove, Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
||||
import { URL } from "url";
|
||||
import { deleteFile } from "../util/cdn";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import {
|
||||
getUrlSignature,
|
||||
NewUrlUserSignatureData,
|
||||
NewUrlSignatureData,
|
||||
} from "../Signing";
|
||||
import { getUrlSignature, NewUrlUserSignatureData, NewUrlSignatureData } from "../Signing";
|
||||
|
||||
@Entity({
|
||||
name: "attachments",
|
||||
@@ -63,13 +52,9 @@ export class Attachment extends BaseClass {
|
||||
message_id: string;
|
||||
|
||||
@JoinColumn({ name: "message_id" })
|
||||
@ManyToOne(
|
||||
() => require("./Message").Message,
|
||||
(message: import("./Message").Message) => message.attachments,
|
||||
{
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
)
|
||||
@ManyToOne(() => require("./Message").Message, (message: import("./Message").Message) => message.attachments, {
|
||||
onDelete: "CASCADE",
|
||||
})
|
||||
message: import("./Message").Message;
|
||||
|
||||
@BeforeRemove()
|
||||
@@ -80,14 +65,10 @@ export class Attachment extends BaseClass {
|
||||
signUrls(data: NewUrlUserSignatureData): Attachment {
|
||||
return {
|
||||
...this,
|
||||
url: getUrlSignature(
|
||||
new NewUrlSignatureData({ ...data, url: this.url }),
|
||||
)
|
||||
url: getUrlSignature(new NewUrlSignatureData({ ...data, url: this.url }))
|
||||
.applyToUrl(this.url)
|
||||
.toString(),
|
||||
proxy_url: getUrlSignature(
|
||||
new NewUrlSignatureData({ ...data, url: this.proxy_url }),
|
||||
)
|
||||
proxy_url: getUrlSignature(new NewUrlSignatureData({ ...data, url: this.proxy_url }))
|
||||
.applyToUrl(this.proxy_url)
|
||||
.toString(),
|
||||
};
|
||||
|
||||
@@ -16,14 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
BaseEntity,
|
||||
BeforeInsert,
|
||||
BeforeUpdate,
|
||||
FindOptionsWhere,
|
||||
ObjectIdColumn,
|
||||
PrimaryColumn,
|
||||
} from "typeorm";
|
||||
import { BaseEntity, BeforeInsert, BeforeUpdate, FindOptionsWhere, ObjectIdColumn, PrimaryColumn } from "typeorm";
|
||||
import { Snowflake } from "../util/Snowflake";
|
||||
import { getDatabase } from "../util/Database";
|
||||
import { OrmUtils } from "../imports/OrmUtils";
|
||||
@@ -62,28 +55,18 @@ export class BaseClassWithoutId extends BaseEntity {
|
||||
);
|
||||
}
|
||||
|
||||
static increment<T extends BaseClass>(
|
||||
conditions: FindOptionsWhere<T>,
|
||||
propertyPath: string,
|
||||
value: number | string,
|
||||
) {
|
||||
static increment<T extends BaseClass>(conditions: FindOptionsWhere<T>, propertyPath: string, value: number | string) {
|
||||
const repository = this.getRepository();
|
||||
return repository.increment(conditions, propertyPath, value);
|
||||
}
|
||||
|
||||
static decrement<T extends BaseClass>(
|
||||
conditions: FindOptionsWhere<T>,
|
||||
propertyPath: string,
|
||||
value: number | string,
|
||||
) {
|
||||
static decrement<T extends BaseClass>(conditions: FindOptionsWhere<T>, propertyPath: string, value: number | string) {
|
||||
const repository = this.getRepository();
|
||||
return repository.decrement(conditions, propertyPath, value);
|
||||
}
|
||||
}
|
||||
|
||||
export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb")
|
||||
? ObjectIdColumn
|
||||
: PrimaryColumn;
|
||||
export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryColumn;
|
||||
|
||||
export class BaseClass extends BaseClassWithoutId {
|
||||
@PrimaryIdColumn()
|
||||
|
||||
@@ -16,19 +16,9 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ObjectIdColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
BaseEntity,
|
||||
} from "typeorm";
|
||||
import { Column, Entity, ObjectIdColumn, PrimaryGeneratedColumn, BaseEntity } from "typeorm";
|
||||
|
||||
export const PrimaryIdAutoGenerated = process.env.DATABASE?.startsWith(
|
||||
"mongodb",
|
||||
)
|
||||
? ObjectIdColumn
|
||||
: PrimaryGeneratedColumn;
|
||||
export const PrimaryIdAutoGenerated = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryGeneratedColumn;
|
||||
|
||||
@Entity({
|
||||
name: "migrations",
|
||||
|
||||
@@ -16,14 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
RelationId,
|
||||
} from "typeorm";
|
||||
import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { User } from "./User";
|
||||
import { RelationshipType } from "@spacebar/schemas";
|
||||
|
||||
@@ -48,7 +48,7 @@ export class Session extends BaseClassWithoutId {
|
||||
@Column({ type: "simple-json", default: "[]" })
|
||||
activities: Activity[];
|
||||
|
||||
@Column({ type: "simple-json"})
|
||||
@Column({ type: "simple-json" })
|
||||
client_info: {
|
||||
platform?: string;
|
||||
os?: string;
|
||||
@@ -93,7 +93,8 @@ export class Session extends BaseClassWithoutId {
|
||||
approx_last_used_time: (this.last_seen ?? new Date(0)).toISOString(),
|
||||
client_info: {
|
||||
os: this.client_info?.os,
|
||||
platform: this.client_info?.platform + (this.client_info?.version ? ` ${this.client_info?.version}` : "") + (this.session_nickname ? ` (${this.session_nickname})` : ""),
|
||||
platform:
|
||||
this.client_info?.platform + (this.client_info?.version ? ` ${this.client_info?.version}` : "") + (this.session_nickname ? ` (${this.session_nickname})` : ""),
|
||||
location: this.last_seen_location,
|
||||
},
|
||||
};
|
||||
@@ -108,7 +109,7 @@ export class Session extends BaseClassWithoutId {
|
||||
client_status: this.client_status,
|
||||
approx_last_used_time: (this.last_seen ?? new Date(0)).toISOString(),
|
||||
client_info: {
|
||||
...this.client_info ?? {},
|
||||
...(this.client_info ?? {}),
|
||||
location: this.last_seen_location,
|
||||
},
|
||||
last_seen: this.last_seen,
|
||||
@@ -134,7 +135,7 @@ export class Session extends BaseClassWithoutId {
|
||||
activities: hasPrivateActivities ? [] : this.activities,
|
||||
hidden_activities: hasPrivateActivities ? this.activities : [],
|
||||
active: TimeSpan.fromDates(this.last_seen?.getTime() ?? 0, new Date().getTime()).totalMillis < inactiveTreshold,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async updateIpInfo() {
|
||||
@@ -163,21 +164,21 @@ export class Session extends BaseClassWithoutId {
|
||||
}
|
||||
|
||||
export interface ExtendedLocationInfo {
|
||||
is_eu: boolean,
|
||||
city: string,
|
||||
region: string,
|
||||
region_code: string,
|
||||
country_name: string,
|
||||
country_code: string,
|
||||
continent_name: string,
|
||||
continent_code: string,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
postal: string,
|
||||
calling_code: string,
|
||||
flag: string,
|
||||
emoji_flag: string,
|
||||
emoji_unicode: string,
|
||||
is_eu: boolean;
|
||||
city: string;
|
||||
region: string;
|
||||
region_code: string;
|
||||
country_name: string;
|
||||
country_code: string;
|
||||
continent_name: string;
|
||||
continent_code: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
postal: string;
|
||||
calling_code: string;
|
||||
flag: string;
|
||||
emoji_flag: string;
|
||||
emoji_unicode: string;
|
||||
}
|
||||
|
||||
export const PrivateSessionProjection: (keyof Session)[] = ["user_id", "session_id", "activities", "client_info", "status"];
|
||||
|
||||
@@ -16,14 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
RelationId,
|
||||
} from "typeorm";
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
|
||||
import { Sticker } from ".";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
|
||||
|
||||
@@ -16,14 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
RelationId,
|
||||
} from "typeorm";
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { TeamMember } from "./TeamMember";
|
||||
import { User } from "./User";
|
||||
|
||||
@@ -39,13 +39,9 @@ export class TeamMember extends BaseClass {
|
||||
team_id: string;
|
||||
|
||||
@JoinColumn({ name: "team_id" })
|
||||
@ManyToOne(
|
||||
() => require("./Team").Team,
|
||||
(team: import("./Team").Team) => team.members,
|
||||
{
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
)
|
||||
@ManyToOne(() => require("./Team").Team, (team: import("./Team").Team) => team.members, {
|
||||
onDelete: "CASCADE",
|
||||
})
|
||||
team: import("./Team").Team;
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -19,15 +19,7 @@
|
||||
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
|
||||
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
|
||||
import { User } from "./User";
|
||||
import {
|
||||
FrecencyUserSettings,
|
||||
PreloadedUserSettings,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} from "discord-protos";
|
||||
import { FrecencyUserSettings, PreloadedUserSettings } from "discord-protos";
|
||||
|
||||
@Entity({
|
||||
name: "user_settings_protos",
|
||||
@@ -71,17 +63,9 @@ export class UserSettingsProtos extends BaseClassWithoutId {
|
||||
bigintReviver(_key: string, value: unknown): unknown {
|
||||
if (typeof value === "string" && /^\d+n$/.test(value)) {
|
||||
return BigInt((value as string).slice(0, -1));
|
||||
} else if (
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
"__type" in value
|
||||
) {
|
||||
} else if (typeof value === "object" && value !== null && "__type" in value) {
|
||||
if (value.__type === "Uint8Array" && "data" in value) {
|
||||
return new Uint8Array(
|
||||
(value.data as string)
|
||||
.match(/.{1,2}/g)!
|
||||
.map((byte: string) => parseInt(byte, 16)),
|
||||
);
|
||||
return new Uint8Array((value.data as string).match(/.{1,2}/g)!.map((byte: string) => parseInt(byte, 16)));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
@@ -89,9 +73,7 @@ export class UserSettingsProtos extends BaseClassWithoutId {
|
||||
|
||||
get userSettings(): PreloadedUserSettings | undefined {
|
||||
if (!this._userSettings) return undefined;
|
||||
return PreloadedUserSettings.fromJson(
|
||||
JSON.parse(this._userSettings, this.bigintReviver),
|
||||
);
|
||||
return PreloadedUserSettings.fromJson(JSON.parse(this._userSettings, this.bigintReviver));
|
||||
}
|
||||
|
||||
set userSettings(value: PreloadedUserSettings | undefined) {
|
||||
@@ -105,9 +87,7 @@ export class UserSettingsProtos extends BaseClassWithoutId {
|
||||
|
||||
get frecencySettings(): FrecencyUserSettings | undefined {
|
||||
if (!this._frecencySettings) return undefined;
|
||||
return FrecencyUserSettings.fromJson(
|
||||
JSON.parse(this._frecencySettings, this.bigintReviver),
|
||||
);
|
||||
return FrecencyUserSettings.fromJson(JSON.parse(this._frecencySettings, this.bigintReviver));
|
||||
}
|
||||
|
||||
set frecencySettings(value: FrecencyUserSettings | undefined) {
|
||||
|
||||
Reference in New Issue
Block a user