adding connection now works
This commit is contained in:
parent
21bfda32e4
commit
6a52e65e27
@ -25,6 +25,8 @@ import {
|
|||||||
registerRoutes,
|
registerRoutes,
|
||||||
Sentry,
|
Sentry,
|
||||||
WebAuthn,
|
WebAuthn,
|
||||||
|
ConnectionConfig,
|
||||||
|
ConnectionLoader
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Server, ServerOptions } from "lambert-server";
|
import { Server, ServerOptions } from "lambert-server";
|
||||||
@ -64,6 +66,7 @@ export class FosscordServer extends Server {
|
|||||||
await Config.init();
|
await Config.init();
|
||||||
await initEvent();
|
await initEvent();
|
||||||
await Email.init();
|
await Email.init();
|
||||||
|
await ConnectionConfig.init();
|
||||||
await initInstance();
|
await initInstance();
|
||||||
await Sentry.init(this.app);
|
await Sentry.init(this.app);
|
||||||
WebAuthn.init();
|
WebAuthn.init();
|
||||||
@ -130,6 +133,8 @@ export class FosscordServer extends Server {
|
|||||||
|
|
||||||
Sentry.errorHandler(this.app);
|
Sentry.errorHandler(this.app);
|
||||||
|
|
||||||
|
ConnectionLoader.loadConnections();
|
||||||
|
|
||||||
if (logRequests)
|
if (logRequests)
|
||||||
console.log(
|
console.log(
|
||||||
red(
|
red(
|
||||||
|
@ -6,7 +6,7 @@ import { route } from "../../../util";
|
|||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { connection_id: connection_name } = req.params;
|
const { connection_name } = req.params;
|
||||||
const connection = ConnectionStore.connections.get(connection_name);
|
const connection = ConnectionStore.connections.get(connection_name);
|
||||||
if (!connection)
|
if (!connection)
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
|
@ -13,7 +13,7 @@ router.post(
|
|||||||
"/",
|
"/",
|
||||||
route({ body: "ConnectionCallbackSchema" }),
|
route({ body: "ConnectionCallbackSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { connection_id: connection_name } = req.params;
|
const { connection_name } = req.params;
|
||||||
const connection = ConnectionStore.connections.get(connection_name);
|
const connection = ConnectionStore.connections.get(connection_name);
|
||||||
if (!connection)
|
if (!connection)
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
|
@ -118,15 +118,10 @@ export default class BattleNetConnection extends Connection {
|
|||||||
if (exists) return false;
|
if (exists) return false;
|
||||||
await this.createConnection({
|
await this.createConnection({
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
external_id: userInfo.id,
|
external_id: userInfo.id.toString(),
|
||||||
friend_sync: params.friend_sync,
|
friend_sync: params.friend_sync,
|
||||||
name: userInfo.battletag,
|
name: userInfo.battletag,
|
||||||
revoked: false,
|
|
||||||
show_activity: false,
|
|
||||||
type: this.id,
|
type: this.id,
|
||||||
verified: true,
|
|
||||||
visibility: 0,
|
|
||||||
integrations: [],
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -99,15 +99,10 @@ export default class GitHubConnection extends Connection {
|
|||||||
if (exists) return false;
|
if (exists) return false;
|
||||||
await this.createConnection({
|
await this.createConnection({
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
external_id: userInfo.id,
|
external_id: userInfo.id.toString(),
|
||||||
friend_sync: params.friend_sync,
|
friend_sync: params.friend_sync,
|
||||||
name: userInfo.name,
|
name: userInfo.name,
|
||||||
revoked: false,
|
|
||||||
show_activity: false,
|
|
||||||
type: this.id,
|
type: this.id,
|
||||||
verified: true,
|
|
||||||
visibility: 0,
|
|
||||||
integrations: [],
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { ConnectedAccount } from "../entities";
|
import { ConnectedAccount } from "../entities";
|
||||||
import { OrmUtils } from "../imports";
|
import { OrmUtils } from "../imports";
|
||||||
import { ConnectionCallbackSchema } from "../schemas";
|
import { ConnectedAccountSchema, ConnectionCallbackSchema } from "../schemas";
|
||||||
import { DiscordApiErrors } from "../util";
|
import { DiscordApiErrors } from "../util";
|
||||||
|
|
||||||
export default abstract class Connection {
|
export default abstract class Connection {
|
||||||
@ -54,7 +54,7 @@ export default abstract class Connection {
|
|||||||
this.states.delete(state);
|
this.states.delete(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createConnection(data: any): Promise<void> {
|
async createConnection(data: ConnectedAccountSchema): Promise<void> {
|
||||||
const ca = OrmUtils.mergeDeep(new ConnectedAccount(), data);
|
const ca = OrmUtils.mergeDeep(new ConnectedAccount(), data);
|
||||||
await ca.save();
|
await ca.save();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ export const ConnectionConfig = {
|
|||||||
set: function set(val: Partial<any>) {
|
set: function set(val: Partial<any>) {
|
||||||
if (!config || !val) return;
|
if (!config || !val) return;
|
||||||
config = val.merge(config);
|
config = val.merge(config);
|
||||||
console.debug("config", config); // TODO: if no more issues with sql, remove this or find the reason why it's happening
|
|
||||||
|
|
||||||
return applyConfig(config);
|
return applyConfig(config);
|
||||||
},
|
},
|
||||||
|
@ -23,7 +23,6 @@ export class ConnectionLoader {
|
|||||||
|
|
||||||
dirs.forEach(async (x) => {
|
dirs.forEach(async (x) => {
|
||||||
let modPath = path.resolve(path.join(root, x));
|
let modPath = path.resolve(path.join(root, x));
|
||||||
console.log(`Loading connection: ${modPath}`);
|
|
||||||
const mod = new (require(modPath).default)() as Connection;
|
const mod = new (require(modPath).default)() as Connection;
|
||||||
ConnectionStore.connections.set(mod.id, mod);
|
ConnectionStore.connections.set(mod.id, mod);
|
||||||
|
|
||||||
@ -55,11 +54,13 @@ export class ConnectionLoader {
|
|||||||
console.log(
|
console.log(
|
||||||
`[ConnectionConfig/WARN] ${id} tried to set config=null!`,
|
`[ConnectionConfig/WARN] ${id} tried to set config=null!`,
|
||||||
);
|
);
|
||||||
await ConnectionConfig.set({
|
|
||||||
|
const a = {
|
||||||
[id]: OrmUtils.mergeDeep(
|
[id]: OrmUtils.mergeDeep(
|
||||||
ConnectionLoader.getConnectionConfig(id) || {},
|
ConnectionLoader.getConnectionConfig(id) || {},
|
||||||
config,
|
config,
|
||||||
),
|
),
|
||||||
});
|
};
|
||||||
|
await ConnectionConfig.set(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,17 @@ export class ConnectedAccountDTO {
|
|||||||
id: string;
|
id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
access_token?: string;
|
access_token?: string;
|
||||||
friend_sync: boolean;
|
friend_sync?: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
revoked: boolean;
|
revoked?: boolean;
|
||||||
show_activity: boolean;
|
show_activity?: boolean;
|
||||||
type: string;
|
type: string;
|
||||||
verified: boolean;
|
verified?: boolean;
|
||||||
visibility: boolean;
|
visibility?: number;
|
||||||
integrations: string[];
|
integrations?: string[];
|
||||||
metadata_: any;
|
metadata_?: any;
|
||||||
metadata_visibility: boolean;
|
metadata_visibility?: number;
|
||||||
two_way_link: boolean;
|
two_way_link?: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
connectedAccount: ConnectedAccount,
|
connectedAccount: ConnectedAccount,
|
||||||
|
@ -40,39 +40,39 @@ export class ConnectedAccount extends BaseClass {
|
|||||||
})
|
})
|
||||||
user: User;
|
user: User;
|
||||||
|
|
||||||
@Column({ select: false })
|
@Column({ select: false, nullable: true })
|
||||||
access_token: string;
|
access_token?: string;
|
||||||
|
|
||||||
@Column({ select: false })
|
@Column({ select: false })
|
||||||
friend_sync: boolean = false;
|
friend_sync?: boolean = false;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column({ select: false })
|
@Column({ select: false })
|
||||||
revoked: boolean = false;
|
revoked?: boolean = false;
|
||||||
|
|
||||||
@Column({ select: false })
|
@Column({ select: false })
|
||||||
show_activity: boolean = true;
|
show_activity?: boolean = true;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
type: string;
|
type: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
verified: boolean;
|
verified?: boolean = true;
|
||||||
|
|
||||||
@Column({ select: false })
|
@Column({ select: false })
|
||||||
visibility: boolean = true;
|
visibility?: number = 0;
|
||||||
|
|
||||||
@Column({ type: "simple-array" })
|
@Column({ type: "simple-array" })
|
||||||
integrations: string[];
|
integrations?: string[] = [];
|
||||||
|
|
||||||
@Column({ type: "simple-json", name: "metadata" })
|
@Column({ type: "simple-json", name: "metadata", nullable: true })
|
||||||
metadata_: any;
|
metadata_?: any;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
metadata_visibility: boolean = true;
|
metadata_visibility?: number = 0;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
two_way_link: boolean = false;
|
two_way_link?: boolean = false;
|
||||||
}
|
}
|
||||||
|
@ -25,3 +25,4 @@ export * from "./dtos/index";
|
|||||||
export * from "./schemas";
|
export * from "./schemas";
|
||||||
export * from "./imports";
|
export * from "./imports";
|
||||||
export * from "./config";
|
export * from "./config";
|
||||||
|
export * from "./connections"
|
16
src/util/schemas/ConnectedAccountSchema.ts
Normal file
16
src/util/schemas/ConnectedAccountSchema.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
export interface ConnectedAccountSchema {
|
||||||
|
external_id: string;
|
||||||
|
user_id: string;
|
||||||
|
access_token?: string;
|
||||||
|
friend_sync?: boolean;
|
||||||
|
name: string;
|
||||||
|
revoked?: boolean;
|
||||||
|
show_activity?: boolean;
|
||||||
|
type: string;
|
||||||
|
verified?: boolean;
|
||||||
|
visibility?: number;
|
||||||
|
integrations?: string[];
|
||||||
|
metadata_?: any;
|
||||||
|
metadata_visibility?: number;
|
||||||
|
two_way_link?: boolean;
|
||||||
|
}
|
@ -30,6 +30,7 @@ export * from "./ChannelModifySchema";
|
|||||||
export * from "./ChannelPermissionOverwriteSchema";
|
export * from "./ChannelPermissionOverwriteSchema";
|
||||||
export * from "./ChannelReorderSchema";
|
export * from "./ChannelReorderSchema";
|
||||||
export * from "./CodesVerificationSchema";
|
export * from "./CodesVerificationSchema";
|
||||||
|
export * from "./ConnectedAccountSchema";
|
||||||
export * from "./ConnectionCallbackSchema";
|
export * from "./ConnectionCallbackSchema";
|
||||||
export * from "./DmChannelCreateSchema";
|
export * from "./DmChannelCreateSchema";
|
||||||
export * from "./EmojiCreateSchema";
|
export * from "./EmojiCreateSchema";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user