Add device diagnostics and P2P access controls
This commit is contained in:
@@ -41,10 +41,12 @@ export function registerP2pRoutes(app, deps) {
|
||||
if (!m) return null;
|
||||
const d = await p2pDb.getDevice(m[1]);
|
||||
if (!d || !same(d.secret_hash, sha(m[2]))) return null;
|
||||
if (d.banned_at) return { ...d, _banned: true };
|
||||
return d;
|
||||
}
|
||||
const requireDevice = async (c, next) => {
|
||||
const d = await deviceOf(c);
|
||||
if (d?._banned) return c.json({ ok: false, error: 'device access revoked' }, 403);
|
||||
if (!d) return c.json({ ok: false, error: 'unknown device' }, 401);
|
||||
c.set('device', d);
|
||||
await next();
|
||||
@@ -67,6 +69,7 @@ export function registerP2pRoutes(app, deps) {
|
||||
deviceId, secretHash: sha(secret),
|
||||
fingerprint: String(body.fingerprint || '').slice(0, 128) || null,
|
||||
profile: String(body.profile || '').slice(0, 64) || null,
|
||||
userAgent: String(c.req.header('user-agent') || '').slice(0, 500),
|
||||
now: t,
|
||||
});
|
||||
return c.json({ ok: true, deviceId, secret });
|
||||
|
||||
Reference in New Issue
Block a user