feat: add PUBLIC_INSTANCE_TYPE env var
This commit is contained in:
9 files changed
+37
-68
No files matched your search
@@ -21,7 +21,6 @@ Jump to:
|
||||
<img width="3220" height="1800" alt="Photon dark theme compact" src="https://github.com/user-attachments/assets/76b5278b-e5f9-4c0c-81ec-0820d3261223" />
|
||||
<img width="3220" height="1800" alt="Photon light theme cozy" src="https://github.com/user-attachments/assets/41d205fe-7d32-4b83-bfef-6aa9dd63e074" />
|
||||
|
||||
|
||||
## Self-hosting
|
||||
|
||||
You selfhost a Photon frontend server for your Lemmy instance, or independently for any instance.
|
||||
@@ -39,6 +38,7 @@ To run an unconfigured Photon instance on port `8080`:
|
||||
```sh
|
||||
docker run -p 8080:3000 ghcr.io/xyphyn/photon:latest
|
||||
```
|
||||
|
||||
### Running natively
|
||||
|
||||
Clone the repo:
|
||||
@@ -80,8 +80,11 @@ Photon lets you configure the default client settings and more.
|
||||
If you're hosting Photon for a Lemmy instance, you' ll almost definitely want to set these:
|
||||
|
||||
- `PUBLIC_INSTANCE_URL` `string`: The domain which **the browser** will send API requests to.
|
||||
|
||||
- Example: `PUBLIC_INSTANCE_URL=fedi.phtn.app`
|
||||
|
||||
- `PUBLIC_INSTANCE_TYPE` `lemmyv3 | piefedalpha` (default: `lemmyv3`): If your instance is running Piefed, you must set this option to `piefedalpha`. Otherwise, you don't need to do anything.
|
||||
|
||||
- `PUBLIC_SSR_ENABLED` `boolean`: When enabled, will **make page requests be rendered server side first**, which allows search engine indexing, and basic non-js usage.
|
||||
|
||||
- `PUBLIC_INTERNAL_INSTANCE` `string`: Only relevant if `PUBLIC_SSR_ENABLED=true`. This is the domain that the **server will make API requests to.**
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "photon-lemmy",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.3",
|
||||
"license": "AGPL-3.0-only",
|
||||
"devDependencies": {
|
||||
"@dicebear/core": "^8.0.1",
|
||||
|
||||
+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