diff options
| author | Fuwn <[email protected]> | 2024-02-17 01:32:59 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-17 01:32:59 -0800 |
| commit | ae14e8263a9d42c539b748c9781d3c249f94af59 (patch) | |
| tree | e04754cc3815203aa5bdaef804d697e0b103a917 | |
| parent | fix(hololive): wait for pinned streams (diff) | |
| download | due.moe-ae14e8263a9d42c539b748c9781d3c249f94af59.tar.xz due.moe-ae14e8263a9d42c539b748c9781d3c249f94af59.zip | |
feat(settings): delete remote configuration
| -rw-r--r-- | src/lib/Database/userConfiguration.ts | 8 | ||||
| -rw-r--r-- | src/lib/Locale/english.ts | 3 | ||||
| -rw-r--r-- | src/lib/Locale/japanese.ts | 3 | ||||
| -rw-r--r-- | src/lib/Locale/layout.ts | 1 | ||||
| -rw-r--r-- | src/lib/Settings/Categories/SettingSync.svelte | 19 | ||||
| -rw-r--r-- | src/routes/api/configuration/+server.ts | 32 |
6 files changed, 63 insertions, 3 deletions
diff --git a/src/lib/Database/userConfiguration.ts b/src/lib/Database/userConfiguration.ts index f1e3ef95..de86fbe4 100644 --- a/src/lib/Database/userConfiguration.ts +++ b/src/lib/Database/userConfiguration.ts @@ -64,3 +64,11 @@ export const toggleHololiveStreamPinning = async (userId: number, streamId: stri pinned_hololive_streams: pinnedStreams }); }; + +export const deleteUserConfiguration = async (userId: number) => { + const { data, error } = await supabase.from('user_configuration').delete().eq('user_id', userId); + + if (error || !data) return null; + + return data; +}; diff --git a/src/lib/Locale/english.ts b/src/lib/Locale/english.ts index 831018a7..7b1b3d00 100644 --- a/src/lib/Locale/english.ts +++ b/src/lib/Locale/english.ts @@ -150,7 +150,8 @@ const English: Locale = { title: 'Push Local Configuration', hint: 'Enable settings sync and overwrite any remote configuration with your local settings' }, - disable: 'Disable & Keep Local Configuration' + disable: 'Disable & Keep Local Configuration', + delete: 'Delete Remote Configuration' } } }, diff --git a/src/lib/Locale/japanese.ts b/src/lib/Locale/japanese.ts index 07bff6b9..28c8f9bb 100644 --- a/src/lib/Locale/japanese.ts +++ b/src/lib/Locale/japanese.ts @@ -151,7 +151,8 @@ const Japanese: Locale = { title: 'ローカル設定をプッシュ', hint: '設定同期を有効にして、リモート設定をローカル設定で上書きします' }, - disable: '設定の同期を無効にし、ローカル設定を保持する' + disable: '設定の同期を無効にし、ローカル設定を保持する', + delete: 'リモート設定を削除' } } }, diff --git a/src/lib/Locale/layout.ts b/src/lib/Locale/layout.ts index 2f48f0a1..10f9d5f8 100644 --- a/src/lib/Locale/layout.ts +++ b/src/lib/Locale/layout.ts @@ -153,6 +153,7 @@ export interface Locale { hint: LocaleValue; }; disable: LocaleValue; + delete: LocaleValue; }; }; }; diff --git a/src/lib/Settings/Categories/SettingSync.svelte b/src/lib/Settings/Categories/SettingSync.svelte index 61fc6221..6a7de8d1 100644 --- a/src/lib/Settings/Categories/SettingSync.svelte +++ b/src/lib/Settings/Categories/SettingSync.svelte @@ -88,6 +88,25 @@ > {$locale().settings.settingsSync.buttons.disable} </button> + <button + on:click={() => { + fetch(root(`/api/configuration?id=${$identity.id}`), { + method: 'DELETE' + }).then((response) => { + if (response.ok) { + $settings.settingsSync = false; + + addNotification( + options({ + heading: 'Remote configuration deleted and settings sync disabled' + }) + ); + } + }); + }} + > + {$locale().settings.settingsSync.buttons.delete} + </button> <p /> diff --git a/src/routes/api/configuration/+server.ts b/src/routes/api/configuration/+server.ts index 418742a8..8b37628f 100644 --- a/src/routes/api/configuration/+server.ts +++ b/src/routes/api/configuration/+server.ts @@ -1,5 +1,9 @@ import { userIdentity } from '$lib/Data/AniList/identity'; -import { getUserConfiguration, setUserConfiguration } from '$lib/Database/userConfiguration.js'; +import { + deleteUserConfiguration, + getUserConfiguration, + setUserConfiguration +} from '$lib/Database/userConfiguration.js'; const unauthorised = new Response('Unauthorised', { status: 401 }); @@ -38,3 +42,29 @@ export const PUT = async ({ cookies, request }) => { } ); }; + +export const DELETE = async ({ cookies }) => { + const userCookie = cookies.get('user'); + + if (!userCookie) return unauthorised; + + const user = JSON.parse(userCookie); + + return Response.json( + await deleteUserConfiguration( + ( + await userIdentity({ + tokenType: user['token_type'], + expiresIn: user['expires_in'], + accessToken: user['access_token'], + refreshToken: user['refresh_token'] + }) + ).id + ), + { + headers: { + 'Access-Control-Allow-Origin': 'https://due.moe' + } + } + ); +}; |