2025-06-30 18:58:24 +02:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
*/
|
2025-07-07 22:42:49 +02:00
|
|
|
import { readSubscriptions, readUsers } from "~/server/database";
|
2025-06-11 21:05:17 +02:00
|
|
|
import type { ApiSession } from "~/shared/types/api";
|
2025-03-07 12:41:57 +01:00
|
|
|
|
2025-06-11 21:05:17 +02:00
|
|
|
export default defineEventHandler(async (event): Promise<ApiSession | undefined> => {
|
2025-07-07 22:42:49 +02:00
|
|
|
const session = await getServerSession(event, false);
|
2025-03-07 12:41:57 +01:00
|
|
|
if (!session)
|
|
|
|
return;
|
2025-07-07 22:42:49 +02:00
|
|
|
const users = await readUsers();
|
|
|
|
const account = users.find(user => user.id === session.accountId);
|
2025-03-07 14:11:07 +01:00
|
|
|
const subscriptions = await readSubscriptions();
|
|
|
|
const push = Boolean(
|
|
|
|
subscriptions.find(sub => sub.type === "push" && sub.sessionId === session.id)
|
|
|
|
);
|
2025-03-07 12:41:57 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: session.id,
|
2025-07-07 22:42:49 +02:00
|
|
|
account,
|
2025-03-07 14:11:07 +01:00
|
|
|
push,
|
|
|
|
};
|
2025-03-07 12:41:57 +01:00
|
|
|
})
|