fixes and improvements to env variables usage

This commit is contained in:
pluja
2023-10-27 16:21:43 +02:00
parent bded8f0dc6
commit f389df7c51
5 changed files with 12 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
<script> <script>
import { validateURL, CLIENT_API_HOST, WHISHPER_GPU } from '$lib/utils.js'; import { validateURL, CLIENT_API_HOST } from '$lib/utils.js';
import { env } from '$env/dynamic/public';
import toast from 'svelte-french-toast'; import toast from 'svelte-french-toast';
@@ -9,7 +10,7 @@
let language = 'auto'; let language = 'auto';
let sourceUrl = ''; let sourceUrl = '';
let fileInput; let fileInput;
let device = (WHISHPER_GPU) ? 'cuda' : 'cpu'; let device = (env.PUBLIC_WHISHPER_GPU) ? 'cuda' : 'cpu';
let languages = [ let languages = [
'auto', 'auto',
@@ -181,7 +182,7 @@
<span class="label-text">Device</span> <span class="label-text">Device</span>
</label> </label>
<select name="device" bind:value={device} class="select select-bordered"> <select name="device" bind:value={device} class="select select-bordered">
{#if WHISHPER_GPU } {#if env.PUBLIC_WHISHPER_GPU }
<option selected value="cuda">GPU</option> <option selected value="cuda">GPU</option>
<option value="cpu">CPU</option> <option value="cpu">CPU</option>
{:else} {:else}

View File

@@ -1,7 +1,8 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import toast from 'svelte-french-toast'; import toast from 'svelte-french-toast';
import { CLIENT_API_HOST, TRANSLATION_API_HOST } from '$lib/utils'; import { CLIENT_API_HOST } from '$lib/utils';
import { env } from '$env/dynamic/public';
export let tr; export let tr;
let targetLanguage = null; let targetLanguage = null;
@@ -9,7 +10,7 @@
let availableLanguages = []; let availableLanguages = [];
const getAvailableLangs = () => { const getAvailableLangs = () => {
const fetchLanguages = () => { const fetchLanguages = () => {
fetch(`${TRANSLATION_API_HOST}/languages`) fetch(`${env.PUBLIC_TRANSLATION_API_HOST}/languages`)
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
if (data) { if (data) {

View File

@@ -5,10 +5,7 @@ import { env } from '$env/dynamic/public';
export let CLIENT_API_HOST = browser ? `${dev ? env.PUBLIC_API_HOST : ""}` : `${env.PUBLIC_INTERNAL_API_HOST}`; export let CLIENT_API_HOST = browser ? `${dev ? env.PUBLIC_API_HOST : ""}` : `${env.PUBLIC_INTERNAL_API_HOST}`;
export let CLIENT_WS_HOST = browser ? `${dev ? env.PUBLIC_API_HOST.replace("http://", "").replace("https://", "") : ""}` : `${dev ? env.PUBLIC_INTERNAL_API_HOST.replace("http://", "").replace("https://", "") : ""}`; export let CLIENT_WS_HOST = browser ? `${dev ? env.PUBLIC_API_HOST.replace("http://", "").replace("https://", "") : ""}` : `${dev ? env.PUBLIC_INTERNAL_API_HOST.replace("http://", "").replace("https://", "") : ""}`;
export let TRANSLATION_API_HOST = browser ? `${dev ? env.PUBLIC_TRANSLATION_API_HOST : ""}` : `${dev ? env.PUBLIC_TRANSLATION_API_HOST : ""}`;
export let WHISHPER_GPU = env.PUBLIC_WHISHPER_GPU === 'true' ||
env.PUBLIC_WHISHPER_GPU === 'True' ||
env.PUBLIC_WHISHPER_GPU === '1';
// URL Validator // URL Validator
export const validateURL = function (url) { export const validateURL = function (url) {
try { try {

View File

@@ -1,12 +1,11 @@
import { transcriptions } from '$lib/stores'; import { transcriptions } from '$lib/stores';
import { browser, dev } from '$app/environment'; import { browser, dev } from '$app/environment';
import { CLIENT_API_HOST } from '$lib/utils'; import { env } from '$env/dynamic/public';
/** @type {import('./$types').PageLoad} */ /** @type {import('./$types').PageLoad} */
export async function load({ fetch }) { export async function load({ fetch }) {
// Use different endpoints for server-side and client-side // Use different endpoints for server-side and client-side
const endpoint = browser ? `${CLIENT_API_HOST}/api/transcriptions` : `${process.env.INTERNAL_API_HOST}/api/transcriptions`; const endpoint = browser ? `${env.PUBLIC_API_HOST}/api/transcriptions` : `${env.PUBLIC_INTERNAL_API_HOST}/api/transcriptions`;
console.log(endpoint);
const response = await fetch(endpoint); const response = await fetch(endpoint);
const ts = await response.json(); const ts = await response.json();

View File

@@ -1,14 +1,13 @@
/** @type {import('./$types').PageLoad} */ /** @type {import('./$types').PageLoad} */
import { currentTranscription } from '$lib/stores'; import { currentTranscription } from '$lib/stores';
import { CLIENT_API_HOST } from '$lib/utils';
import { browser } from '$app/environment'; import { browser } from '$app/environment';
import { env } from '$env/dynamic/public';
export async function load({params}) { export async function load({params}) {
// Fetch json from /api/transcriptions/{id} // Fetch json from /api/transcriptions/{id}
let id = params.id; let id = params.id;
// Use different endpoints for server-side and client-side // Use different endpoints for server-side and client-side
const endpoint = browser ? `${env.PUBLIC_API_HOST}/api/transcriptions` : `${env.PUBLIC_INTERNAL_API_HOST}/api/transcriptions`;
const endpoint = browser ? `${CLIENT_API_HOST}/api/transcriptions` : `${process.env.INTERNAL_API_HOST}/api/transcriptions`;
const response = await fetch(`${endpoint}/${id}`); const response = await fetch(`${endpoint}/${id}`);
const ts = await response.json(); const ts = await response.json();
// Set currentTranscription to the fetched transcription // Set currentTranscription to the fetched transcription