resolve typing errors, run api when appservice runs

This commit is contained in:
jesopo 2022-08-31 15:35:31 +00:00 committed by gnuxie
parent be18613722
commit 4a9e5d422d
3 changed files with 9 additions and 4 deletions

View File

@ -19,6 +19,7 @@
},
"devDependencies": {
"@types/crypto-js": "^4.0.2",
"@types/express": "^4.17.13",
"@types/html-to-text": "^8.0.1",
"@types/humanize-duration": "^3.27.1",
"@types/js-yaml": "^4.0.5",

View File

@ -34,6 +34,8 @@ export class Api {
}
public start(port: number) {
this.httpdConfig.use(express.json());
this.httpdConfig.get("/get", this.pathGet);
this.httpdConfig.get("/list", this.pathList);
this.httpdConfig.post("/create", this.pathCreate);
@ -42,13 +44,13 @@ export class Api {
}
private async pathGet(request: express.Request, response: express.Response) {
const accessToken = request.params.query["openId"];
const accessToken = request.query["openId"];
if (accessToken === undefined) {
response.status(401);
return;
}
const mjolnirId = request.params.query["mxid"];
const mjolnirId = request.query["mxid"];
if (mjolnirId === undefined) {
response.status(400);
return;
@ -69,7 +71,7 @@ export class Api {
}
private async pathList(request: express.Request, response: express.Response) {
const accessToken = request.params.query["openId"];
const accessToken = request.query["openId"];
if (accessToken === undefined) {
response.status(401);
return;
@ -83,7 +85,7 @@ export class Api {
}
private async pathCreate(request: express.Request, response: express.Response) {
const accessToken = request.params.query["openId"];
const accessToken = request.body["openId"];
if (accessToken === undefined) {
response.status(401);
return;

View File

@ -20,6 +20,7 @@ import { AppServiceRegistration, Bridge, Cli, Request, WeakEvent, BridgeContext,
// needed by appservice irc, though it looks completely dead.
import * as Datastore from "nedb";
import { MjolnirManager } from ".//MjolnirManager";
import { Api } from "./Api";
// ts-node src/appservice/AppService.ts -r -u "http://localhost:9000" # remember to add the registration to homeserver.yaml! you probably want host.docker.internal as the hostname of the appservice if using mx-tester
// ts-node src/appservice/AppService -p 9000 # to start.
@ -29,6 +30,7 @@ export class MjolnirAppService {
private readonly mjolnirManager: MjolnirManager = new MjolnirManager();
public constructor() {
new Api("http://localhost:9999", this).start(9001);
this.bridge = new Bridge({
homeserverUrl: "http://localhost:9999",
domain: "localhost:9999",