ba-cafe

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

commit f18b9522207bb972e7d026fa9cb0fc64b41334fa
parent 94025e9e154ad5603e2e2a3942dc03d7589f42fa
Author: Sunny <122193933+Sunny-JP@users.noreply.github.com>
Date:   Sat, 24 Jan 2026 22:18:24 +0900

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

fix api
Diffstat:
Msrc/app/api/tap/route.ts | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/app/api/tap/route.ts b/src/app/api/tap/route.ts @@ -62,17 +62,21 @@ async function cleanupDevices(userId: string, currentId: string) { const data = await res.json(); const subs = data.subscriptions || (data.identity && data.identity.subscriptions) || []; - const pushSubs = subs.filter((s: any) => String(s.type).includes("Push") || String(s.type) === "1"); - const otherDevices = pushSubs.filter((s: any) => s.id !== currentId); - - otherDevices.sort((a: any, b: any) => { - const timeA = Number(a.last_active || a.created_at || 0); - const timeB = Number(b.last_active || b.created_at || 0); - return timeB - timeA; + const activePushSubs = subs.filter((s: any) => { + const isPush = String(s.type).includes("Push") || String(s.type) === "1"; + return isPush && s.enabled === true; }); - if (pushSubs.length > 2) { - const toDelete = otherDevices.slice(1); + const otherActiveDevices = activePushSubs.filter((s: any) => s.id !== currentId); + + if (activePushSubs.length > 2) { + otherActiveDevices.sort((a: any, b: any) => { + const timeA = Number(a.last_active || a.created_at || 0); + const timeB = Number(b.last_active || b.created_at || 0); + return timeB - timeA; + }); + + const toDelete = otherActiveDevices.slice(1); for (const sub of toDelete) { await fetch(`https://onesignal.com/api/v1/apps/${APP_ID}/subscriptions/${sub.id}`, { method: "DELETE",