nook: surface per-license maxDevices in activate + status responses
This commit is contained in:
@@ -68,7 +68,7 @@ export async function POST(event: APIEvent) {
|
|||||||
args: [new Date().toISOString(), existing.id]
|
args: [new Date().toISOString(), existing.id]
|
||||||
});
|
});
|
||||||
const count = await activeCount(conn, license.id);
|
const count = await activeCount(conn, license.id);
|
||||||
return json({ ok: true, email: license.email, activatedCount: count });
|
return json({ ok: true, email: license.email, activatedCount: count, maxDevices: license.maxDevices });
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = await activeCount(conn, license.id);
|
const count = await activeCount(conn, license.id);
|
||||||
@@ -88,7 +88,7 @@ export async function POST(event: APIEvent) {
|
|||||||
new Date().toISOString()
|
new Date().toISOString()
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
return json({ ok: true, email: license.email, activatedCount: count + 1 });
|
return json({ ok: true, email: license.email, activatedCount: count + 1, maxDevices: license.maxDevices });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function activeCount(
|
async function activeCount(
|
||||||
|
|||||||
@@ -29,16 +29,16 @@ export async function POST(event: APIEvent) {
|
|||||||
const conn = NookConnectionFactory();
|
const conn = NookConnectionFactory();
|
||||||
|
|
||||||
const licenseRes = await conn.execute({
|
const licenseRes = await conn.execute({
|
||||||
sql: "SELECT id, revoked FROM licenses WHERE key = ?",
|
sql: "SELECT id, revoked, max_devices FROM licenses WHERE key = ?",
|
||||||
args: [key]
|
args: [key]
|
||||||
});
|
});
|
||||||
if (licenseRes.rows.length === 0) {
|
if (licenseRes.rows.length === 0) {
|
||||||
return json({ state: "unknown_key", activatedCount: 0 });
|
return json({ state: "unknown_key", activatedCount: 0, maxDevices: 0 });
|
||||||
}
|
}
|
||||||
const license = licenseRes.rows[0] as { id: string; revoked: number };
|
const license = licenseRes.rows[0] as { id: string; revoked: number; maxDevices: number };
|
||||||
|
|
||||||
if (license.revoked === 1) {
|
if (license.revoked === 1) {
|
||||||
return json({ state: "revoked", activatedCount: 0 });
|
return json({ state: "revoked", activatedCount: 0, maxDevices: 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const countRes = await conn.execute({
|
const countRes = await conn.execute({
|
||||||
@@ -47,5 +47,5 @@ export async function POST(event: APIEvent) {
|
|||||||
});
|
});
|
||||||
const activatedCount = Number((countRes.rows[0] as { n: number | bigint }).n);
|
const activatedCount = Number((countRes.rows[0] as { n: number | bigint }).n);
|
||||||
|
|
||||||
return json({ state: "valid", activatedCount });
|
return json({ state: "valid", activatedCount, maxDevices: license.maxDevices });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user