2025-06-30 18:58:24 +02:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
*/
|
2025-03-05 18:41:47 +01:00
|
|
|
import { readSubscriptions, writeSubscriptions } from "~/server/database";
|
2025-02-28 15:32:03 +01:00
|
|
|
|
2025-03-05 15:36:50 +01:00
|
|
|
export default defineEventHandler(async (event) => {
|
2025-06-09 16:51:05 +02:00
|
|
|
const session = await requireServerSession(event);
|
2025-03-05 18:41:47 +01:00
|
|
|
const subscriptions = await readSubscriptions();
|
2025-03-07 12:30:39 +01:00
|
|
|
const existingIndex = subscriptions.findIndex(
|
2025-03-07 14:11:07 +01:00
|
|
|
sub => sub.type === "push" && sub.sessionId === session.id
|
2025-03-07 12:30:39 +01:00
|
|
|
);
|
2025-02-28 15:32:03 +01:00
|
|
|
if (existingIndex !== -1) {
|
|
|
|
subscriptions.splice(existingIndex, 1);
|
|
|
|
} else {
|
2025-03-05 15:36:50 +01:00
|
|
|
return { message: "No subscription registered."};
|
2025-02-28 15:32:03 +01:00
|
|
|
}
|
2025-03-05 18:41:47 +01:00
|
|
|
await writeSubscriptions(subscriptions);
|
2025-03-05 15:36:50 +01:00
|
|
|
return { message: "Existing subscription removed."};
|
2025-03-07 14:11:07 +01:00
|
|
|
});
|