Improved how we get public env vars
This commit is contained in:
@@ -137,27 +137,25 @@ export async function parseChannelRSS(channelId: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
updateLastRssFetch(channelId, channelName ?? 'Unknown');
|
||||
await updateLastRssFetch(channelId, channelName ?? 'Unknown');
|
||||
}
|
||||
|
||||
async function updateLastRssFetch(channelId: string, channelName: string) {
|
||||
localDb.channelSubscriptions
|
||||
const subscription = await localDb.channelSubscriptions
|
||||
.where('channelId')
|
||||
.equals(channelId)
|
||||
.first()
|
||||
.then((subscription) => {
|
||||
if (subscription) {
|
||||
localDb.channelSubscriptions.where('channelId').equals(channelId).modify({
|
||||
lastRSSFetch: new Date()
|
||||
});
|
||||
} else {
|
||||
localDb.channelSubscriptions.add({
|
||||
channelId: channelId,
|
||||
channelName: channelName,
|
||||
lastRSSFetch: new Date()
|
||||
});
|
||||
}
|
||||
.first();
|
||||
if (subscription) {
|
||||
await localDb.channelSubscriptions.where('channelId').equals(channelId).modify({
|
||||
lastRSSFetch: new Date()
|
||||
});
|
||||
} else {
|
||||
await localDb.channelSubscriptions.add({
|
||||
channelId: channelId,
|
||||
channelName: channelName,
|
||||
lastRSSFetch: new Date()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearFeedYTjs() {
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
import { Network, type ConnectionStatus } from '@capacitor/network';
|
||||
import { fade } from 'svelte/transition';
|
||||
import { addToast } from './Toast.svelte';
|
||||
import { isMobile, isUnrestrictedPlatform, isYTBackend, truncate } from '$lib/misc';
|
||||
import { getPublicEnv, isMobile, isUnrestrictedPlatform, isYTBackend, truncate } from '$lib/misc';
|
||||
import {
|
||||
generateThumbnailWebVTT,
|
||||
drawTimelineThumbnail,
|
||||
@@ -515,11 +515,8 @@
|
||||
// Due to CORs issues with redirects, hosted instances of Materialious
|
||||
// dirctly provide the companion instance
|
||||
// while clients can just use the reirect provided by Invidious' API
|
||||
if (
|
||||
import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE ||
|
||||
env.PUBLIC_DEFAULT_COMPANION_INSTANCE
|
||||
) {
|
||||
dashUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE || env.PUBLIC_DEFAULT_COMPANION_INSTANCE}/api/manifest/dash/id/${data.video.videoId}`;
|
||||
if (getPublicEnv('DEFAULT_COMPANION_INSTANCE')) {
|
||||
dashUrl = `${getPublicEnv('DEFAULT_COMPANION_INSTANCE')}/api/manifest/dash/id/${data.video.videoId}`;
|
||||
} else {
|
||||
if (!data.video.dashUrl) {
|
||||
error(500, 'No dash manifest found');
|
||||
@@ -582,16 +579,12 @@
|
||||
if (data.video.captions) {
|
||||
for (const caption of data.video.captions) {
|
||||
let captionUrl: string;
|
||||
if (
|
||||
!import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE &&
|
||||
!env.PUBLIC_DEFAULT_COMPANION_INSTANCE &&
|
||||
$invidiousInstanceStore
|
||||
) {
|
||||
if (!getPublicEnv('DEFAULT_COMPANION_INSTANCE') && $invidiousInstanceStore) {
|
||||
captionUrl = caption.url.startsWith('http')
|
||||
? caption.url
|
||||
: `${new URL($invidiousInstanceStore).origin}${caption.url}`;
|
||||
} else {
|
||||
captionUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE || env.PUBLIC_DEFAULT_COMPANION_INSTANCE}${caption.url}`;
|
||||
captionUrl = `${getPublicEnv('DEFAULT_COMPANION_INSTANCE')}${caption.url}`;
|
||||
}
|
||||
|
||||
await player.addTextTrackAsync(
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
isUnrestrictedPlatform,
|
||||
setInvidiousInstance,
|
||||
goToInvidiousLogin,
|
||||
invidiousLogout
|
||||
invidiousLogout,
|
||||
timeout
|
||||
} from '../../misc';
|
||||
import { getPages, type Pages } from '../../navPages';
|
||||
import ColorPicker from 'svelte-awesome-color-picker';
|
||||
@@ -82,12 +83,16 @@
|
||||
async function setInstance(event: Event) {
|
||||
event.preventDefault();
|
||||
invalidInstance = !(await setInvidiousInstance(invidiousInstance));
|
||||
|
||||
await timeout(100);
|
||||
location.reload();
|
||||
}
|
||||
|
||||
async function setBackend(event: Event) {
|
||||
const select = event.target as HTMLSelectElement;
|
||||
backendInUseStore.set(select.value as 'ivg' | 'yt');
|
||||
|
||||
await timeout(100);
|
||||
location.reload();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { persistedStores } from './settings';
|
||||
import { isOwnBackend } from '$lib/shared';
|
||||
import { addOrUpdateKeyValue, getKeyValue } from '$lib/api/backend';
|
||||
import { rawMasterKeyStore } from '$lib/store';
|
||||
import { getPublicEnv } from '$lib/misc';
|
||||
|
||||
export async function syncSettingsToBackend() {
|
||||
if (!isOwnBackend() || !get(rawMasterKeyStore)) return;
|
||||
@@ -74,13 +75,9 @@ function setStores(toSet: Record<string, unknown>, overwriteExisting = false) {
|
||||
}
|
||||
|
||||
export function loadSettingsFromEnv() {
|
||||
if (
|
||||
typeof import.meta.env.VITE_DEFAULT_SETTINGS !== 'string' &&
|
||||
typeof env.PUBLIC_DEFAULT_SETTINGS !== 'string'
|
||||
)
|
||||
return;
|
||||
if (typeof getPublicEnv('DEFAULT_SETTINGS') !== 'string') return;
|
||||
|
||||
let raw = import.meta.env.VITE_DEFAULT_SETTINGS || env.PUBLIC_DEFAULT_SETTINGS;
|
||||
let raw = getPublicEnv('DEFAULT_SETTINGS');
|
||||
|
||||
// Docker wraps env vars in quotes
|
||||
if (raw.startsWith('"')) raw = raw.slice(1);
|
||||
|
||||
@@ -34,6 +34,10 @@ import { isOwnBackend } from './shared';
|
||||
import { Browser } from '@capacitor/browser';
|
||||
import { clearFeedYTjs } from './api/youtubejs/subscriptions';
|
||||
|
||||
export function getPublicEnv(envName: string): string | undefined {
|
||||
return env[`PUBLIC_${envName}`] ?? import.meta.env[`VITE_${envName}`];
|
||||
}
|
||||
|
||||
export function isMobile(): boolean {
|
||||
const userAgent = navigator.userAgent;
|
||||
|
||||
@@ -83,10 +87,9 @@ export interface PeerInstance {
|
||||
|
||||
export function determinePeerJsInstance(): PeerInstance {
|
||||
return {
|
||||
host:
|
||||
import.meta.env.VITE_DEFAULT_PEERJS_HOST || env.PUBLIC_DEFAULT_PEERJS_HOST || '0.peerjs.com',
|
||||
path: import.meta.env.VITE_DEFAULT_PEERJS_PATH || env.PUBLIC_DEFAULT_PEERJS_PATH || '/',
|
||||
port: import.meta.env.VITE_DEFAULT_PEERJS_PORT || env.PUBLIC_DEFAULT_PEERJS_PORT || 443
|
||||
host: getPublicEnv('DEFAULT_PEERJS_HOST') || '0.peerjs.com',
|
||||
path: getPublicEnv('DEFAULT_PEERJS_PATH') || '/',
|
||||
port: getPublicEnv('DEFAULT_PEERJS_PORT') ? Number(getPublicEnv('DEFAULT_PEERJS_PORT')) : 443
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import type {
|
||||
VideoPlay
|
||||
} from './api/model';
|
||||
import type { ParsedDescription } from './description';
|
||||
import { ensureNoTrailingSlash } from './misc';
|
||||
import { ensureNoTrailingSlash, getPublicEnv } from './misc';
|
||||
import type { EngineFallback } from './api/misc';
|
||||
|
||||
function createListenerFunctions(): {
|
||||
@@ -89,11 +89,9 @@ function ifNotWebDefault(givenValue: any, defaultValue: any): any {
|
||||
|
||||
export const invidiousInstanceStore: Writable<string | undefined> = persist(
|
||||
writable(
|
||||
!import.meta.env.VITE_DEFAULT_INVIDIOUS_INSTANCE || !env.PUBLIC_DEFAULT_INVIDIOUS_INSTANCE
|
||||
!getPublicEnv('DEFAULT_INVIDIOUS_INSTANCE')
|
||||
? undefined
|
||||
: ensureNoTrailingSlash(
|
||||
import.meta.env.VITE_DEFAULT_INVIDIOUS_INSTANCE || env.PUBLIC_DEFAULT_INVIDIOUS_INSTANCE
|
||||
)
|
||||
: ensureNoTrailingSlash(getPublicEnv('DEFAULT_INVIDIOUS_INSTANCE'))
|
||||
),
|
||||
createStorage(),
|
||||
'invidiousInstance'
|
||||
@@ -198,8 +196,7 @@ export const returnYtDislikesStore = persist(writable(false), createStorage(), '
|
||||
export const returnYTDislikesInstanceStore: Writable<string | null | undefined> = persist(
|
||||
writable(
|
||||
ifNotWebDefault(
|
||||
import.meta.env.VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE ||
|
||||
env.PUBLIC_DEFAULT_RETURNYTDISLIKES_INSTANCE,
|
||||
getPublicEnv('DEFAULT_RETURNYTDISLIKES_INSTANCE'),
|
||||
'https://ryd-proxy.materialio.us'
|
||||
)
|
||||
),
|
||||
@@ -211,9 +208,7 @@ export const synciousStore = persist(writable(false), createStorage(), 'syncious
|
||||
export const synciousInstanceStore: Writable<string | null | undefined> = persist(
|
||||
writable(
|
||||
ifNotWebDefault(
|
||||
import.meta.env.VITE_DEFAULT_SYNCIOUS_INSTANCE ||
|
||||
import.meta.env.VITE_DEFAULT_API_EXTENDED_INSTANCE ||
|
||||
env.PUBLIC_DEFAULT_RETURNYTDISLIKES_INSTANCE,
|
||||
getPublicEnv('DEFAULT_SYNCIOUS_INSTANCE') || getPublicEnv('DEFAULT_API_EXTENDED_INSTANCE'),
|
||||
'https://extended-api.materialio.us'
|
||||
)
|
||||
),
|
||||
@@ -286,11 +281,7 @@ export const interfaceAndroidUseNativeShare = persist(
|
||||
|
||||
export const sponsorBlockStore = persist(writable(true), createStorage(), 'sponsorBlock');
|
||||
export const sponsorBlockUrlStore: Writable<string | null | undefined> = persist(
|
||||
writable(
|
||||
import.meta.env.VITE_DEFAULT_SPONSERBLOCK_INSTANCE ||
|
||||
env.PUBLIC_DEFAULT_SPONSERBLOCK_INSTANCE ||
|
||||
'https://sponsor.ajay.app'
|
||||
),
|
||||
writable(getPublicEnv('DEFAULT_SPONSERBLOCK_INSTANCE') || 'https://sponsor.ajay.app'),
|
||||
createStorage(),
|
||||
'sponsorBlockUrl'
|
||||
);
|
||||
@@ -311,22 +302,14 @@ export const sponsorBlockTimelineStore: Writable<boolean> = persist(
|
||||
);
|
||||
|
||||
export const deArrowInstanceStore = persist(
|
||||
writable(
|
||||
import.meta.env.VITE_DEFAULT_DEARROW_INSTANCE ||
|
||||
env.PUBLIC_DEFAULT_DEARROW_INSTANCE ||
|
||||
'https://sponsor.ajay.app'
|
||||
),
|
||||
writable(getPublicEnv('DEFAULT_DEARROW_INSTANCE') || 'https://sponsor.ajay.app'),
|
||||
createStorage(),
|
||||
'deArrowInstance'
|
||||
);
|
||||
export const deArrowEnabledStore = persist(writable(false), createStorage(), 'deArrowEnabled');
|
||||
export const deArrowTitlesOnly = persist(writable(true), createStorage(), 'deArrowTitlesOnly');
|
||||
export const deArrowThumbnailInstanceStore = persist(
|
||||
writable(
|
||||
import.meta.env.VITE_DEFAULT_DEARROW_THUMBNAIL_INSTANCE ||
|
||||
env.PUBLIC_DEFAULT_DEARROW_THUMBNAIL_INSTANCE ||
|
||||
'https://dearrow-thumb.ajay.app'
|
||||
),
|
||||
writable(getPublicEnv('DEFAULT_DEARROW_THUMBNAIL_INSTANCE') || 'https://dearrow-thumb.ajay.app'),
|
||||
createStorage(),
|
||||
'deArrowThumbnailInstance'
|
||||
);
|
||||
|
||||
@@ -73,18 +73,7 @@ async function proxyRequest(
|
||||
}
|
||||
}
|
||||
|
||||
const requestHeaders = new Headers(request.headers);
|
||||
for (const key of [
|
||||
'referer',
|
||||
'x-forwarded-for',
|
||||
'x-requested-with',
|
||||
'sec-ch-ua-mobile',
|
||||
'sec-ch-ua',
|
||||
'sec-ch-ua-platform',
|
||||
'content-length'
|
||||
]) {
|
||||
requestHeaders.delete(key);
|
||||
}
|
||||
const requestHeaders = new Headers();
|
||||
|
||||
requestHeaders.set('host', urlToProxyObj.host);
|
||||
requestHeaders.set('origin', urlToProxyObj.origin);
|
||||
@@ -123,7 +112,7 @@ async function proxyRequest(
|
||||
throw error(500, errorMsg);
|
||||
}
|
||||
|
||||
const responseHeaders = new Headers(response.headers);
|
||||
const responseHeaders = new Headers();
|
||||
responseHeaders.set('transfer-encoding', 'chunked');
|
||||
responseHeaders.delete('content-encoding');
|
||||
responseHeaders.set('access-control-allow-origin', request.headers.get('origin') ?? '');
|
||||
|
||||
Reference in New Issue
Block a user