fix: add client-specific constants, close #664
This commit is contained in:
4 files changed
+22
-5
No files matched your search
+9
-2
@@ -1,5 +1,5 @@
|
|||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public'
|
||||||
import * as types from './types';
|
import * as types from './types'
|
||||||
|
|
||||||
export type ClientType =
|
export type ClientType =
|
||||||
| { name: 'lemmy'; baseUrl: '/api/v3' }
|
| { name: 'lemmy'; baseUrl: '/api/v3' }
|
||||||
@@ -19,6 +19,13 @@ export const DEFAULT_CLIENT_TYPE: ClientType =
|
|||||||
export abstract class BaseClient {
|
export abstract class BaseClient {
|
||||||
abstract type: ClientType
|
abstract type: ClientType
|
||||||
|
|
||||||
|
static constants: {
|
||||||
|
password: {
|
||||||
|
minLength: number
|
||||||
|
maxLength: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract getSite(): Promise<types.GetSiteResponse>
|
abstract getSite(): Promise<types.GetSiteResponse>
|
||||||
abstract editSite(form: types.EditSite): Promise<types.SiteResponse>
|
abstract editSite(form: types.EditSite): Promise<types.SiteResponse>
|
||||||
abstract generateTotpSecret(): Promise<types.GenerateTotpSecretResponse>
|
abstract generateTotpSecret(): Promise<types.GenerateTotpSecretResponse>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { fromGetPosts, toListingType } from './rewrite'
|
|||||||
export class LemmyClient implements BaseClient {
|
export class LemmyClient implements BaseClient {
|
||||||
type: ClientType = { name: 'lemmy', baseUrl: '/api/v3' }
|
type: ClientType = { name: 'lemmy', baseUrl: '/api/v3' }
|
||||||
|
|
||||||
|
static constants = { password: { minLength: 8, maxLength: 60 } }
|
||||||
|
|
||||||
#client: LemmyHttp
|
#client: LemmyHttp
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import type { paths } from './schema'
|
|||||||
export class PiefedClient implements BaseClient {
|
export class PiefedClient implements BaseClient {
|
||||||
type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' }
|
type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' }
|
||||||
|
|
||||||
|
static constants = { password: { minLength: 6, maxLength: 128 } }
|
||||||
|
|
||||||
#client: ReturnType<typeof createClient<paths>>
|
#client: ReturnType<typeof createClient<paths>>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
import { type ClientType, DEFAULT_CLIENT_TYPE } from '$lib/api/base'
|
import { type ClientType, DEFAULT_CLIENT_TYPE } from '$lib/api/base'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
|
import { LemmyClient } from '$lib/api/lemmy/adapter'
|
||||||
|
import { PiefedClient } from '$lib/api/piefed/adapter'
|
||||||
import { profile } from '$lib/app/auth.svelte'
|
import { profile } from '$lib/app/auth.svelte'
|
||||||
import { errorMessage } from '$lib/app/error'
|
import { errorMessage } from '$lib/app/error'
|
||||||
import { t } from '$lib/app/i18n'
|
import { t } from '$lib/app/i18n'
|
||||||
@@ -171,14 +173,18 @@
|
|||||||
</TextInput>
|
</TextInput>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row gap-2">
|
<div role="presentation" class="flex flex-row gap-2">
|
||||||
<TextInput
|
<TextInput
|
||||||
id="password"
|
id="password"
|
||||||
bind:value={data.password}
|
bind:value={data.password}
|
||||||
label={$t('form.password')}
|
label={$t('form.password')}
|
||||||
type="password"
|
type="password"
|
||||||
minlength={10}
|
minlength={data.client.name == 'piefed'
|
||||||
maxlength={60}
|
? PiefedClient.constants.password.minLength
|
||||||
|
: LemmyClient.constants.password.minLength}
|
||||||
|
maxlength={data.client.name == 'piefed'
|
||||||
|
? PiefedClient.constants.password.maxLength
|
||||||
|
: LemmyClient.constants.password.maxLength}
|
||||||
required
|
required
|
||||||
class="w-full"
|
class="w-full"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user