aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Settings/Categories/SettingSync.svelte7
-rw-r--r--src/routes/+layout.svelte5
-rw-r--r--src/stores/settings.ts34
-rw-r--r--src/stores/settingsSyncTimes.ts13
4 files changed, 54 insertions, 5 deletions
diff --git a/src/lib/Settings/Categories/SettingSync.svelte b/src/lib/Settings/Categories/SettingSync.svelte
index 54962b44..61fc6221 100644
--- a/src/lib/Settings/Categories/SettingSync.svelte
+++ b/src/lib/Settings/Categories/SettingSync.svelte
@@ -6,6 +6,7 @@
import { getNotificationsContext } from 'svelte-notifications';
import SettingHint from '../SettingHint.svelte';
import locale from '$stores/locale';
+ import settingsSyncTimes from '$stores/settingsSyncTimes';
const { addNotification } = getNotificationsContext();
</script>
@@ -87,4 +88,10 @@
>
{$locale().settings.settingsSync.buttons.disable}
</button>
+
+ <p />
+
+ <b>Last Push</b>: {$locale().dateFormatter($settingsSyncTimes.lastPush)}
+ <br />
+ <b>Last Pull</b>: {$locale().dateFormatter($settingsSyncTimes.lastPull)}
{/if}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 64f3d28d..dc3f371b 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -24,6 +24,7 @@
import { injectSpeedInsights } from '@vercel/speed-insights/sveltekit';
import subtitles from '$lib/Data/Static/subtitles.json';
import settingsSyncPulled from '$stores/settingsSyncPulled';
+ import settingsSyncTimes from '$stores/settingsSyncTimes';
injectSpeedInsights();
@@ -82,6 +83,10 @@
console.log('Pulled remote configuration');
settings.set(data.configuration);
settingsSyncPulled.set(true);
+ settingsSyncTimes.set({
+ lastPull: new Date(),
+ lastPush: new Date(data.updated_at + 'Z')
+ });
}
});
});
diff --git a/src/stores/settings.ts b/src/stores/settings.ts
index e92d4150..31b047e2 100644
--- a/src/stores/settings.ts
+++ b/src/stores/settings.ts
@@ -2,6 +2,8 @@ import { browser } from '$app/environment';
import root from '$lib/Utility/root';
import { get, writable } from 'svelte/store';
import settingsSyncPulled from './settingsSyncPulled';
+import settingsSyncTimes from './settingsSyncTimes';
+import identity from './identity';
export interface Settings {
cacheMangaMinutes: number;
@@ -142,11 +144,33 @@ settings.subscribe((value) => {
if (browser) localStorage.setItem('settings', JSON.stringify(value));
if (value.settingsSync && get(settingsSyncPulled) == true)
- fetch(root(`/api/configuration`), {
- method: 'PUT',
- body: JSON.stringify(value)
- }).then((response) => {
- if (response.ok) console.log('Pushed local configuration');
+ fetch(root(`/api/configuration?id=${get(identity).id}`)).then((response) => {
+ if (response.ok)
+ response.json().then((data) => {
+ const isEqualsJson = (object1: Settings, object2: Settings) => {
+ type AnyObject = { [key: string]: unknown };
+
+ return (
+ Object.keys(object1).length === Object.keys(object2).length &&
+ Object.keys(object1).every(
+ (key) =>
+ (object1 as unknown as AnyObject)[key] == (object2 as unknown as AnyObject)[key]
+ )
+ );
+ };
+
+ if (data && data.configuration && !isEqualsJson(data.configuration, value)) {
+ console.log(isEqualsJson(data.configuration, value));
+ fetch(root(`/api/configuration`), {
+ method: 'PUT',
+ body: JSON.stringify(value)
+ }).then((response) => {
+ if (response.ok) console.log('Pushed local configuration');
+
+ settingsSyncTimes.update((times) => ({ ...times, lastPush: new Date() }));
+ });
+ }
+ });
});
});
diff --git a/src/stores/settingsSyncTimes.ts b/src/stores/settingsSyncTimes.ts
new file mode 100644
index 00000000..d9b790d2
--- /dev/null
+++ b/src/stores/settingsSyncTimes.ts
@@ -0,0 +1,13 @@
+import { writable } from 'svelte/store';
+
+interface SettingsSyncTimes {
+ lastPush: Date;
+ lastPull: Date;
+}
+
+const settingsSyncPulled = writable<SettingsSyncTimes>({
+ lastPush: new Date(),
+ lastPull: new Date()
+});
+
+export default settingsSyncPulled;