feat: add PUBLIC_INSTANCE_TYPE env var
This commit is contained in:
9 files changed
+37
-68
No files matched your search
+11
-4
@@ -1,13 +1,20 @@
|
||||
import { env } from '$env/dynamic/public'
|
||||
import * as types from './types'
|
||||
|
||||
export type ClientType =
|
||||
| { name: 'lemmy'; baseUrl: '/api/v3' }
|
||||
| { name: 'piefed'; baseUrl: '/api/alpha' }
|
||||
|
||||
export const DEFAULT_CLIENT_TYPE: ClientType = {
|
||||
name: 'lemmy',
|
||||
baseUrl: '/api/v3',
|
||||
}
|
||||
export const DEFAULT_CLIENT_TYPE: ClientType =
|
||||
env.PUBLIC_INSTANCE_TYPE == 'piefedalpha'
|
||||
? {
|
||||
name: 'piefed',
|
||||
baseUrl: '/api/alpha',
|
||||
}
|
||||
: {
|
||||
name: 'lemmy',
|
||||
baseUrl: '/api/v3',
|
||||
}
|
||||
|
||||
export abstract class BaseClient {
|
||||
abstract type: ClientType
|
||||
|
||||
@@ -119,34 +119,3 @@ export async function validateInstance(
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function mayBeIncompatible(
|
||||
minVersion: string,
|
||||
availableVersion: string,
|
||||
) {
|
||||
if (minVersion.valueOf() === availableVersion.valueOf()) return false
|
||||
|
||||
const versionFormatter = /[\d.]/
|
||||
if (
|
||||
!minVersion.match(versionFormatter) ||
|
||||
!availableVersion.match(availableVersion)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
const splitMinVersion = minVersion.split('.')
|
||||
const splitAvailableVersion = availableVersion.split('.')
|
||||
|
||||
if (splitMinVersion.length !== splitAvailableVersion.length) return true
|
||||
|
||||
for (let i = 0; i < splitMinVersion.length; ++i) {
|
||||
const minVersionDigit = parseInt(splitMinVersion[i])
|
||||
const availableVersionDigit = parseInt(splitAvailableVersion[i])
|
||||
|
||||
if (availableVersionDigit === undefined) return true
|
||||
if (minVersionDigit < availableVersionDigit) return false
|
||||
if (availableVersionDigit < minVersionDigit) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -62,7 +62,8 @@
|
||||
"moveUp": "Move up",
|
||||
"moveDown": "Move down",
|
||||
"guest": "Guest",
|
||||
"versionGate": "This version of Photon supports instances running {{version}} or higher."
|
||||
"versionGate": "This version of Photon supports instances running {{version}} or higher.",
|
||||
"piefedGate": "Piefed support is experimental. Some features are not supported."
|
||||
},
|
||||
"filter": {
|
||||
"location": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { site } from '$lib/client/lemmy.svelte'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
@@ -10,7 +11,6 @@
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { site } from '$lib/client/lemmy.svelte'
|
||||
import { postFeeds } from '$lib/lemmy/postfeed.svelte.js'
|
||||
import { settings, SSR_ENABLED } from '$lib/settings.svelte.js'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client, mayBeIncompatible, site } from '$lib/client/lemmy.svelte'
|
||||
import { DEFAULT_CLIENT_TYPE, type ClientType } from '$lib/client/base'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import ErrorContainer, {
|
||||
clearErrorScope,
|
||||
pushError,
|
||||
@@ -17,7 +16,6 @@
|
||||
} from '$lib/instance.svelte.js'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { DOMAIN_REGEX_FORMS } from '$lib/util.svelte.js'
|
||||
import { MINIMUM_VERSION } from '$lib/version.js'
|
||||
import { Button, Note, Option, Select, TextInput, toast } from 'mono-svelte'
|
||||
import {
|
||||
Icon,
|
||||
@@ -25,7 +23,6 @@
|
||||
QuestionMarkCircle,
|
||||
UserCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import { DEFAULT_CLIENT_TYPE, type ClientType } from '$lib/client/base'
|
||||
|
||||
interface Props {
|
||||
ref?: string
|
||||
@@ -110,19 +107,23 @@
|
||||
</svelte:head>
|
||||
|
||||
<div class="max-w-xl w-full mx-auto h-max my-auto">
|
||||
<form onsubmit={preventDefault(logIn)} class="flex flex-col gap-5">
|
||||
<form
|
||||
onsubmit={e => {
|
||||
e.preventDefault()
|
||||
logIn()
|
||||
}}
|
||||
class="flex flex-col gap-5"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
{@render children?.()}
|
||||
<Header>{$t('account.login')}</Header>
|
||||
{#if site.data && mayBeIncompatible(MINIMUM_VERSION, site.data.version.replace('v', ''))}
|
||||
<Note>
|
||||
{$t('account.versionGate', {
|
||||
version: `v${MINIMUM_VERSION}`,
|
||||
})}
|
||||
</Note>
|
||||
{/if}
|
||||
<ErrorContainer class="pt-2" scope={page.route.id} />
|
||||
</div>
|
||||
{#if data.client.name == 'piefed'}
|
||||
<Note>
|
||||
{$t('account.piefedGate')}
|
||||
</Note>
|
||||
{/if}
|
||||
<div class="flex flex-row w-full items-center gap-2">
|
||||
<TextInput
|
||||
id="username"
|
||||
|
||||
@@ -3,16 +3,14 @@
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { DEFAULT_CLIENT_TYPE, type ClientType } from '$lib/client/base'
|
||||
import { validateInstance } from '$lib/client/lemmy.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
import { mayBeIncompatible } from '$lib/client/lemmy.svelte'
|
||||
import { site, validateInstance } from '$lib/client/lemmy.svelte'
|
||||
import { DOMAIN_REGEX_FORMS } from '$lib/util.svelte'
|
||||
import { MINIMUM_VERSION } from '$lib/version'
|
||||
import { Button, Note, Option, Select, TextInput, toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { DEFAULT_CLIENT_TYPE, type ClientType } from '$lib/client/base'
|
||||
import { Button, Option, Select, TextInput, toast } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
ref?: string
|
||||
@@ -64,13 +62,6 @@
|
||||
<div class="flex flex-col gap-2">
|
||||
{@render children?.()}
|
||||
<Header>{$t('account.addGuest')}</Header>
|
||||
{#if site.data && mayBeIncompatible(MINIMUM_VERSION, site.data.version.replace('v', ''))}
|
||||
<Note>
|
||||
{$t('account.versionGate', {
|
||||
version: `v${MINIMUM_VERSION}`,
|
||||
})}
|
||||
</Note>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="inline-flex items-center gap-2">
|
||||
<TextInput
|
||||
|
||||
Reference in new issue
Block a user