|
|
|
|
@ -32,6 +32,7 @@ export async function findActiveToken(
|
|
|
|
|
user_id: string;
|
|
|
|
|
group_id: string | null;
|
|
|
|
|
token_hash: string;
|
|
|
|
|
token_plain: string | null;
|
|
|
|
|
created_at: string;
|
|
|
|
|
revoked_at: string | null;
|
|
|
|
|
last_used_at: string | null;
|
|
|
|
|
@ -39,14 +40,14 @@ export async function findActiveToken(
|
|
|
|
|
const db = await getDb();
|
|
|
|
|
const sql = groupId
|
|
|
|
|
? `
|
|
|
|
|
SELECT id, type, user_id, group_id, token_hash, created_at, revoked_at, last_used_at
|
|
|
|
|
SELECT id, type, user_id, group_id, token_hash, token_plain, created_at, revoked_at, last_used_at
|
|
|
|
|
FROM calendar_tokens
|
|
|
|
|
WHERE type = ? AND user_id = ? AND group_id = ? AND revoked_at IS NULL
|
|
|
|
|
ORDER BY id DESC
|
|
|
|
|
LIMIT 1
|
|
|
|
|
`
|
|
|
|
|
: `
|
|
|
|
|
SELECT id, type, user_id, group_id, token_hash, created_at, revoked_at, last_used_at
|
|
|
|
|
SELECT id, type, user_id, group_id, token_hash, token_plain, created_at, revoked_at, last_used_at
|
|
|
|
|
FROM calendar_tokens
|
|
|
|
|
WHERE type = ? AND user_id = ? AND group_id IS NULL AND revoked_at IS NULL
|
|
|
|
|
ORDER BY id DESC
|
|
|
|
|
@ -74,10 +75,10 @@ export async function createCalendarTokenUrl(
|
|
|
|
|
const createdAt = toIsoSql(new Date());
|
|
|
|
|
|
|
|
|
|
const insert = db.prepare(`
|
|
|
|
|
INSERT INTO calendar_tokens (type, user_id, group_id, token_hash, created_at)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?)
|
|
|
|
|
INSERT INTO calendar_tokens (type, user_id, group_id, token_hash, token_plain, created_at)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
|
|
|
`);
|
|
|
|
|
const res = insert.run(type, userId, groupId ?? null, tokenHash, createdAt);
|
|
|
|
|
const res = insert.run(type, userId, groupId ?? null, tokenHash, token, createdAt);
|
|
|
|
|
const id = Number(res.lastInsertRowid || 0);
|
|
|
|
|
|
|
|
|
|
return { url: buildCalendarIcsUrl(type, token), token, id };
|
|
|
|
|
|