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": {
|
||||
|
||||
Reference in new issue
Block a user