recover olm based on last seen

This commit is contained in:
miloschwartz
2026-10-28 16:48:18 -04:00
parent 44a9e87a62
commit 3cacaedb8b
@@ -1,7 +1,7 @@
import { db, currentFingerprint, olms } from "@server/db"; import { db, currentFingerprint, olms } from "@server/db";
import logger from "@server/logger"; import logger from "@server/logger";
import HttpCode from "@server/types/HttpCode"; import HttpCode from "@server/types/HttpCode";
import { and, eq } from "drizzle-orm"; import { and, desc, eq } from "drizzle-orm";
import { NextFunction, Request, Response } from "express"; import { NextFunction, Request, Response } from "express";
import response from "@server/lib/response"; import response from "@server/lib/response";
import createHttpError from "http-errors"; import createHttpError from "http-errors";
@@ -71,7 +71,8 @@ export async function recoverOlmWithFingerprint(
) )
) )
) )
.orderBy(currentFingerprint.lastSeen); .orderBy(desc(currentFingerprint.lastSeen))
.limit(1);
if (!result || result.length == 0) { if (!result || result.length == 0) {
return next( return next(
@@ -82,15 +83,6 @@ export async function recoverOlmWithFingerprint(
); );
} }
if (result.length > 1) {
return next(
createHttpError(
HttpCode.CONFLICT,
"multiple matching fingerprints found, not resetting secrets"
)
);
}
const [{ olm: foundOlm }] = result; const [{ olm: foundOlm }] = result;
const newSecret = generateId(48); const newSecret = generateId(48);