KI-AGENT: Matrix Push Worker Rate Limit entschärfen

This commit is contained in:
2026-05-22 21:35:33 +02:00
parent 51e0ae95b1
commit c699d2ade8
2 changed files with 25 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import jwt from "jsonwebtoken"
type MatrixErrorResponse = {
errcode?: string
error?: string
retry_after_ms?: number
}
type MatrixRoomEvent = {
@@ -382,13 +383,23 @@ export function matrixService(server: FastifyInstance) {
const password = serviceUserPassword()
try {
await registerWithSharedSecret(username, password, true)
} catch (err: any) {
if (err.errcode !== "M_USER_IN_USE") {
throw err
const login = await loginMatrixUser(username, password)
matrixServiceSessionCache = {
accessToken: login.access_token,
matrixUserId: login.user_id,
validUntilMs: Date.now() + 30 * 60 * 1000,
}
return matrixServiceSessionCache
} catch (loginErr: any) {
if (loginErr.statusCode === 429) throw loginErr
}
try {
await registerWithSharedSecret(username, password, true)
} catch (registerErr: any) {
if (registerErr.errcode !== "M_USER_IN_USE") throw registerErr
}
const login = await loginMatrixUser(username, password)
matrixServiceSessionCache = {
accessToken: login.access_token,
@@ -442,6 +453,7 @@ export function matrixService(server: FastifyInstance) {
{
statusCode: response.status,
errcode: error.errcode,
retryAfterMs: error.retry_after_ms,
body,
}
)