bug fixes.

This commit is contained in:
KingKDot
2026-05-18 23:07:11 -05:00
parent 59a2622b47
commit 423e41854f
14 changed files with 110 additions and 69 deletions
+20 -2
View File
@@ -1634,7 +1634,15 @@ export function saveSavedScript(
name: string,
content: string,
scriptType: string,
): SavedScriptRecord {
): SavedScriptRecord | null {
const owner = db
.query<{ user_id: number }, [string]>(
`SELECT user_id FROM saved_scripts WHERE id = ?`,
)
.get(id);
if (owner && owner.user_id !== userId) {
return null;
}
const now = Date.now();
db.run(
`INSERT INTO saved_scripts (id, user_id, name, content, script_type, created_at, updated_at)
@@ -1643,7 +1651,8 @@ export function saveSavedScript(
name = excluded.name,
content = excluded.content,
script_type = excluded.script_type,
updated_at = excluded.updated_at`,
updated_at = excluded.updated_at
WHERE saved_scripts.user_id = excluded.user_id`,
id,
userId,
name,
@@ -2058,6 +2067,15 @@ export function deletePushSubscription(endpoint: string): void {
db.run(`DELETE FROM push_subscriptions WHERE endpoint=?`, endpoint);
}
export function deletePushSubscriptionForUser(userId: number, endpoint: string): boolean {
const result = db.run(
`DELETE FROM push_subscriptions WHERE endpoint=? AND user_id=?`,
endpoint,
userId,
);
return ((result as any)?.changes || 0) > 0;
}
export function deletePushSubscriptionsByUser(userId: number): void {
db.run(`DELETE FROM push_subscriptions WHERE user_id=?`, userId);
}