Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Store invite fix #169

Merged
merged 17 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🐛 fix: the lookup API handler timing out
rezk2ll committed Jan 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 39d1e9ce0f52fdf373c8715ca32343d1f8585248
87 changes: 43 additions & 44 deletions packages/matrix-identity-server/src/lookup/index.ts
Original file line number Diff line number Diff line change
@@ -18,53 +18,52 @@ const lookup = <T extends string = never>(
): expressAppHandler => {
return (req, res) => {
idServer.authenticate(req, res, (data, id) => {
jsonContent(req, res, idServer.logger, (obj) => {
validateParameters(res, schema, obj, idServer.logger, (obj) => {
if (
!(
Array.isArray((obj as { addresses: string[] }).addresses) &&
(obj as { addresses: string[] }).addresses.every(
(address) => typeof address === 'string'
) &&
(obj as { addresses: string[] }).addresses.length <=
(idServer.conf.hashes_rate_limit as number)
)
) {
/* istanbul ignore next */
send(res, 400, errMsg('invalidParam'))
} else {
idServer.logger.debug(
`lookup request to search ${JSON.stringify(obj)}`
)
idServer.db
.get('hashes', ['value', 'hash', 'active'], {
hash: (obj as { addresses: string[] }).addresses
})
.then((rows) => {
// send(res, 200, rows)
const mappings: Record<string, string> = {}
const inactives: Record<string, string> = {}
rows.forEach((row) => {
if (row.active === 1) {
// @ts-expect-error row.hash is not null
mappings[row.hash] = row.value
} else {
// @ts-expect-error row.hash is not null
inactives[row.hash] = row.value
}
})
if (idServer.conf.additional_features ?? false) {
send(res, 200, { mappings, inactive_mappings: inactives })
const obj = (req as any).body
validateParameters(res, schema, obj, idServer.logger, (obj) => {
if (
!(
Array.isArray((obj as { addresses: string[] }).addresses) &&
(obj as { addresses: string[] }).addresses.every(
(address) => typeof address === 'string'
) &&
(obj as { addresses: string[] }).addresses.length <=
(idServer.conf.hashes_rate_limit as number)
)
) {
/* istanbul ignore next */
send(res, 400, errMsg('invalidParam'))
} else {
idServer.logger.debug(
`lookup request to search ${JSON.stringify(obj)}`
)
idServer.db
.get('hashes', ['value', 'hash', 'active'], {
hash: (obj as { addresses: string[] }).addresses
})
.then((rows) => {
// send(res, 200, rows)
const mappings: Record<string, string> = {}
const inactives: Record<string, string> = {}
rows.forEach((row) => {
if (row.active === 1) {
// @ts-expect-error row.hash is not null
mappings[row.hash] = row.value
} else {
send(res, 200, { mappings })
// @ts-expect-error row.hash is not null
inactives[row.hash] = row.value
}
})
.catch((e) => {
/* istanbul ignore next */
send(res, 500, errMsg('unknown', e))
})
}
})
if (idServer.conf.additional_features ?? false) {
send(res, 200, { mappings, inactive_mappings: inactives })
} else {
send(res, 200, { mappings })
}
})
.catch((e) => {
/* istanbul ignore next */
send(res, 500, errMsg('unknown', e))
})
}
})
})
}