Skip to content

Commit 7e4a78f

Browse files
committed
fix: handle breaking changes from dep update
1 parent 3827c7f commit 7e4a78f

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

lib/crypto.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function getKey(): Promise<CryptoKey> {
1313

1414
_signKey = await crypto.subtle.importKey(
1515
"raw",
16-
hex.decode(new TextEncoder().encode(config.signKey)),
16+
hex.decodeHex(config.signKey),
1717
{ name: "HMAC", hash: "SHA-256" },
1818
false,
1919
["sign", "verify"],
@@ -26,12 +26,12 @@ export async function sign(input: string): Promise<string> {
2626
const key = await getKey();
2727
const inputData = encoder.encode(input);
2828
const sig = await crypto.subtle.sign("HMAC", key, inputData);
29-
return new TextDecoder().decode(hex.encode(new Uint8Array(sig)));
29+
return hex.encodeHex(sig);
3030
}
3131

3232
export async function verify(input: string, signature: string): Promise<boolean> {
3333
const key = await getKey();
34-
const signatureData = hex.decode(encoder.encode(signature));
3534
const inputData = encoder.encode(input);
36-
return await crypto.subtle.verify("HMAC", key, signatureData, inputData);
35+
const sig = hex.decodeHex(signature);
36+
return await crypto.subtle.verify("HMAC", key, sig, inputData);
3737
}

lib/handler.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { http } from "../deps.ts";
1+
import { httpErrors } from "../deps.ts";
22
import config from "./config.ts";
33
import { hasKey, verify } from "./crypto.ts";
44
import filterWebhook from "./filter.ts";
@@ -19,20 +19,20 @@ export default async function handle(
1919

2020
// everything else should be a POST
2121
if (req.method !== "POST") {
22-
throw http.createHttpError(405);
22+
throw httpErrors.createError(405);
2323
}
2424

2525
// split url into parts
2626
const [, id, token] = url.pathname.split("/");
2727
if (!id || !token) {
28-
throw http.createHttpError(400);
28+
throw httpErrors.createError(400);
2929
}
3030

3131
// verify signature
3232
if (hasKey) {
3333
const signature = url.searchParams.get("sig");
34-
if (!signature) throw http.createHttpError(400);
35-
if (!(await verify(`${id}/${token}`, signature))) throw http.createHttpError(403);
34+
if (!signature) throw httpErrors.createError(400);
35+
if (!(await verify(`${id}/${token}`, signature))) throw httpErrors.createError(403);
3636
}
3737

3838
// extract data
@@ -70,7 +70,7 @@ function getUrlConfig(params: URLSearchParams): UrlConfig {
7070
config.commentBurstLimit = parseInt(value);
7171
break;
7272
default:
73-
throw http.createHttpError(418, `Unknown config option: ${key}`);
73+
throw httpErrors.createError(418, `Unknown config option: ${key}`);
7474
}
7575
}
7676
return config;

lib/manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Lock, log, redis, TTLCache } from "../deps.ts";
1+
import { log, Mutex, redis, TTLCache } from "../deps.ts";
22
import config from "./config.ts";
33

44
const KEY_EXPIRY = 3; // seconds
@@ -22,12 +22,12 @@ class LocalCommentManager implements CommentManager {
2222

2323
class RedisCommentManager implements CommentManager {
2424
private connectOptions: redis.RedisConnectOptions;
25-
private lock: Lock;
25+
private lock: Mutex;
2626
private _redis: Promise<redis.Redis> | undefined;
2727

2828
constructor(options: redis.RedisConnectOptions) {
2929
this.connectOptions = options;
30-
this.lock = new Lock();
30+
this.lock = new Mutex();
3131
}
3232

3333
// manual lazy init, redis.createLazyClient currently doesn't support pipelines :/

main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { http, log } from "./deps.ts";
1+
import { http, httpErrors, log } from "./deps.ts";
22
import config from "./lib/config.ts";
33
import handler from "./lib/handler.ts";
44
import { requestLog } from "./lib/util.ts";
55

6-
async function setupLogs(): Promise<void> {
7-
await log.setup({
6+
function setupLogs() {
7+
log.setup({
88
handlers: {
9-
console: new log.handlers.ConsoleHandler("DEBUG", {
9+
console: new log.ConsoleHandler("DEBUG", {
1010
formatter: (rec) => `${rec.datetime.toISOString()} [${rec.levelName}] ${rec.msg}`,
1111
}),
1212
},
@@ -32,7 +32,7 @@ async function handleRequest(req: Request, connInfo: http.ConnInfo): Promise<Res
3232
[res, meta] = webhookResult;
3333
}
3434
} catch (err) {
35-
if (http.isHttpError(err) && err.expose) {
35+
if (err instanceof httpErrors.HttpError && err.expose) {
3636
reqLog.warning(`http error: ${err.message}`);
3737
res = new Response(err.message, { status: err.status });
3838
} else {
@@ -69,7 +69,7 @@ async function handleRequest(req: Request, connInfo: http.ConnInfo): Promise<Res
6969
}
7070

7171
if (import.meta.main) {
72-
await setupLogs();
72+
setupLogs();
7373

7474
if (!config.signKey) {
7575
log.warning("url signing disabled");

0 commit comments

Comments
 (0)