Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Dec 14, 2024
1 parent 2367a18 commit 0a6b81d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit"
},
"cSpell.words": ["displayname", "Elysia", "Unpadded"],
"cSpell.words": ["displayname", "Elysia", "homeserver", "Unpadded"],
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 2 additions & 2 deletions packages/homeserver/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ export class MatrixError<TCode extends string> extends Error {
public readonly status: number = 400;

public constructor(
public readonly code: TCode,
public readonly errcode: TCode,
message: string,
) {
super(message);
}

public toJSON() {
return {
errcode: this.code,
errcode: this.errcode,
error: this.message,
};
}
Expand Down
29 changes: 22 additions & 7 deletions packages/homeserver/src/makeRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ export const makeSignedRequest = async <
signingName: string;
queryString?: string;
}) => {
const { address, headers } = await resolveHostAddressByServerName(domain, signingName);
const { address, headers } = await resolveHostAddressByServerName(
domain,
signingName,
);
const url = new URL(`https://${address}${uri}`);
if (queryString) {
url.search = queryString;
}
const signedBody =
body && (await signJson(computeHash({ ...body, signatures: {} }), signingKey, signingName));
body &&
(await signJson(
computeHash({ ...body, signatures: {} }),
signingKey,
signingName,
));

console.log("body ->", method, domain, url.toString(), signedBody);

Expand Down Expand Up @@ -96,7 +104,10 @@ export const makeRequest = async <
options?: Record<string, any>;
queryString?: string;
}) => {
const { address, headers } = await resolveHostAddressByServerName(domain, signingName);
const { address, headers } = await resolveHostAddressByServerName(
domain,
signingName,
);
const url = new URL(`https://${address}${uri}`);
if (queryString) {
url.search = queryString;
Expand Down Expand Up @@ -124,11 +135,12 @@ export const makeUnsignedRequest = async <
method,
domain,
uri,
body,
options = {},
signingKey,
signingName,
queryString,
}: {
}: (B extends Record<string, unknown> ? { body: B } : { body?: never }) & {
method: M;
domain: string;
uri: U;
Expand All @@ -144,17 +156,20 @@ export const makeUnsignedRequest = async <
domain,
method,
uri,
options.body,
body,
);

const { address, headers } = await resolveHostAddressByServerName(domain, signingName);
const { address, headers } = await resolveHostAddressByServerName(
domain,
signingName,
);
const url = new URL(`https://${address}${uri}`);
if (queryString) {
url.search = queryString;
}
const response = await fetch(url.toString(), {
...options,
...(options.body && { body: JSON.stringify(options.body) }),
...(body && { body: JSON.stringify(body) }),
method,
headers: {
Authorization: auth,
Expand Down
6 changes: 2 additions & 4 deletions packages/homeserver/src/procedures/makeJoin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Elysia, t } from "elysia";

import "@hs/endpoints/src/query";
import "@hs/endpoints/src/server";
import { IncompatibleRoomVersionError, NotFoundError } from "../errors";
Expand All @@ -17,10 +15,10 @@ export const makeJoinEventBuilder =
async (
roomId: string,
userId: string,
roomVersion: string,
roomVersions: string[],
origin: string,
) => {
if (roomVersion !== "10") {
if (!roomVersions.includes("10")) {
throw new IncompatibleRoomVersionError(
"Your homeserver does not support the features required to join this room",
{ roomVersion: "10" },
Expand Down
14 changes: 7 additions & 7 deletions packages/homeserver/src/routes/federation/getMissingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export const getMissingEventsRoute = new Elysia().post(
body.limit,
);

return {
events,
};
return events;
},
{
params: t.Object(
Expand Down Expand Up @@ -69,9 +67,11 @@ export const getMissingEventsRoute = new Elysia().post(
},
),
detail: {
security: [{
'matrixAuth': []
}],
}
security: [
{
matrixAuth: [],
},
],
},
},
);
22 changes: 12 additions & 10 deletions packages/homeserver/src/routes/federation/makeJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ export const makeJoinRoute = new Elysia().get(
description: "The authorization header",
}),
}),
response: {
200: t.Object({}),
400: t.Object({}),
403: t.Object({}),
404: t.Object({}),
},
// response: {
// 200: t.Object({}),
// 400: t.Object({}),
// 403: t.Object({}),
// 404: t.Object({}),
// },
query: t.Object({
ver: t.String({
description:
"The version of the room where the user is being invited to.",
}),
ver: t.Array(
t.String({
description:
"The version of the room where the user is being invited to.",
}),
),
}),
params: t.Object(
{
Expand Down

0 comments on commit 0a6b81d

Please sign in to comment.