Skip to content

Commit

Permalink
refactor: move code with private env to different file (#521)
Browse files Browse the repository at this point in the history
* fix: add BACKEND_URL arg to avoid build error

* fix: add BACKEND_URL arg to avoid build error

* refactor: move code with private env to different file
  • Loading branch information
AyushSehrawat authored Jul 14, 2024
1 parent ffad7e3 commit a02ab94
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
39 changes: 39 additions & 0 deletions frontend/src/lib/forms/helpers.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { BACKEND_URL } from '$env/static/private';

// TODO: Add toCheck
export async function setSettings(fetch: any, toSet: any) {
const settings = await fetch(`${BACKEND_URL}/settings/set`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(toSet)
});
const settingsData = await settings.json();

return {
data: settingsData
};
}

export async function saveSettings(fetch: any) {
const data = await fetch(`${BACKEND_URL}/settings/save`, {
method: 'POST'
});
const response = await data.json();

return {
data: response
};
}

export async function loadSettings(fetch: any) {
const data = await fetch(`${BACKEND_URL}/settings/load`, {
method: 'GET'
});
const response = await data.json();

return {
data: response
};
}
40 changes: 0 additions & 40 deletions frontend/src/lib/forms/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
import { type SuperValidated, type Infer } from 'sveltekit-superforms';
import { BACKEND_URL } from '$env/static/private';

import { z } from 'zod';

// TODO: Add toCheck
export async function setSettings(fetch: any, toSet: any) {
const settings = await fetch(`${BACKEND_URL}/settings/set`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(toSet)
});
const settingsData = await settings.json();

return {
data: settingsData
};
}

export async function saveSettings(fetch: any) {
const data = await fetch(`${BACKEND_URL}/settings/save`, {
method: 'POST'
});
const response = await data.json();

return {
data: response
};
}

export async function loadSettings(fetch: any) {
const data = await fetch(`${BACKEND_URL}/settings/load`, {
method: 'GET'
});
const response = await data.json();

return {
data: response
};
}

// General Settings -----------------------------------------------------------------------------------
export const generalSettingsToGet: string[] = ['debug', 'log', 'symlink', 'downloaders'];

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/routes/settings/content/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { superValidate, message } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { fail, error, redirect } from '@sveltejs/kit';
import {
setSettings,
saveSettings,
loadSettings,
contentSettingsSchema,
contentSettingsToGet,
contentSettingsToPass,
contentSettingsToSet
} from '$lib/forms/helpers';
import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server';
import { BACKEND_URL } from '$env/static/private';

export const load: PageServerLoad = async ({ fetch }) => {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/routes/settings/general/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { superValidate, message } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { fail, error, redirect } from '@sveltejs/kit';
import {
setSettings,
saveSettings,
loadSettings,
generalSettingsSchema,
generalSettingsToGet,
generalSettingsToPass,
generalSettingsToSet
} from '$lib/forms/helpers';
import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server';
import { BACKEND_URL } from '$env/static/private';

export const load: PageServerLoad = async ({ fetch }) => {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/routes/settings/mediaserver/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { superValidate, message } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { fail, error, redirect } from '@sveltejs/kit';
import {
setSettings,
saveSettings,
loadSettings,
mediaServerSettingsSchema,
mediaServerSettingsToGet,
mediaServerSettingsToPass,
mediaServerSettingsToSet
} from '$lib/forms/helpers';
import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server';
import { BACKEND_URL } from '$env/static/private';

export const load: PageServerLoad = async ({ fetch }) => {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/routes/settings/scrapers/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { superValidate, message } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { fail, error, redirect } from '@sveltejs/kit';
import {
setSettings,
saveSettings,
loadSettings,
scrapersSettingsSchema,
scrapersSettingsToGet,
scrapersSettingsToPass,
scrapersSettingsToSet
} from '$lib/forms/helpers';
import { setSettings, saveSettings, loadSettings } from '$lib/forms/helpers.server';
import { BACKEND_URL } from '$env/static/private';

export const load: PageServerLoad = async ({ fetch }) => {
Expand Down

0 comments on commit a02ab94

Please sign in to comment.