ba-cafe

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e0a9ca5da4718833f9a5c25352573b306e165511
parent 8c272fdbee0c0f61c25ea2e2d1ec9997087f14b5
Author: Sunny <122193933+Sunny-JP@users.noreply.github.com>
Date:   Sat, 24 Jan 2026 14:51:11 +0900

Merge pull request #15 from Sunny-JP/v4-sunny-dev

V4 sunny dev
Diffstat:
Msrc/app/api/tap/route.ts | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/app/api/tap/route.ts b/src/app/api/tap/route.ts @@ -38,6 +38,7 @@ export async function POST(request: Request) { if (upsertError) throw new Error(upsertError.message); if (tapTime && shouldScheduleNotification(new Date(tapTime))) { + await cleanupOldDevices(user.id); await scheduleNotification(user.id, tapTime); } return NextResponse.json({ success: true, history: newHistory }); @@ -54,18 +55,23 @@ async function cleanupOldDevices(userId: string) { }); if (!res.ok) return; const { subscriptions } = await res.json(); - const oldSubs = (subscriptions || []) + const allPushSubs = (subscriptions || []) .filter((s: any) => s.type === "Push") - .sort((a: any, b: any) => new Date(b.last_active || 0).getTime() - new Date(a.last_active || 0).getTime()) - .slice(2); - await Promise.all(oldSubs.map((sub: any) => - fetch(`https://api.onesignal.com/apps/${ONESIGNAL_APP_ID}/subscriptions/${sub.id}`, { - method: "DELETE", - headers: { "Authorization": `Basic ${ONESIGNAL_REST_KEY}` } - }) - )); + .sort((a: any, b: any) => + new Date(b.last_active || 0).getTime() - new Date(a.last_active || 0).getTime() + ); + if (allPushSubs.length > 2) { + const toDelete = allPushSubs.slice(2); + + await Promise.all(toDelete.map((sub: any) => + fetch(`https://api.onesignal.com/apps/${ONESIGNAL_APP_ID}/subscriptions/${sub.id}`, { + method: "DELETE", + headers: { "Authorization": `Basic ${ONESIGNAL_REST_KEY}` } + }) + )); + } } catch (e) { - console.error("Cleanup Error:", e); + console.error("OneSignal Cleanup Error:", e); } }