mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor(web): routes (#25313)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { Route } from '$lib/route';
|
||||
import { user } from '$lib/stores/user.store';
|
||||
import { authenticate } from '$lib/utils/auth';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
@@ -9,7 +9,7 @@ import type { PageLoad } from './$types';
|
||||
export const load = (async ({ url }) => {
|
||||
await authenticate(url);
|
||||
if (!get(user).shouldChangePassword) {
|
||||
redirect(307, AppRoute.PHOTOS);
|
||||
redirect(307, Route.photos());
|
||||
}
|
||||
|
||||
const $t = await getFormatter();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import AuthPageLayout from '$lib/components/layouts/AuthPageLayout.svelte';
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
|
||||
import { serverConfigManager } from '$lib/managers/server-config-manager.svelte';
|
||||
import { Route } from '$lib/route';
|
||||
import { oauth } from '$lib/utils';
|
||||
import { getServerErrorMessage, handleError } from '$lib/utils/handle-error';
|
||||
import { login, type LoginResponseDto } from '@immich/sdk';
|
||||
@@ -33,8 +33,8 @@
|
||||
eventManager.emit('AuthLogin', user);
|
||||
};
|
||||
|
||||
const onFirstLogin = () => goto(AppRoute.AUTH_CHANGE_PASSWORD);
|
||||
const onOnboarding = () => goto(AppRoute.AUTH_ONBOARDING);
|
||||
const onFirstLogin = () => goto(Route.changePassword());
|
||||
const onOnboarding = () => goto(Route.onboarding());
|
||||
|
||||
onMount(async () => {
|
||||
if (!featureFlagsManager.value.oauth) {
|
||||
@@ -66,7 +66,7 @@
|
||||
(featureFlagsManager.value.oauthAutoLaunch && !oauth.isAutoLaunchDisabled(globalThis.location)) ||
|
||||
oauth.isAutoLaunchEnabled(globalThis.location)
|
||||
) {
|
||||
await goto(`${AppRoute.AUTH_LOGIN}?autoLaunch=0`, { replaceState: true });
|
||||
await goto(Route.login({ autoLaunch: 0 }), { replaceState: true });
|
||||
await oauth.authorize(globalThis.location);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { serverConfigManager } from '$lib/managers/server-config-manager.svelte';
|
||||
import { Route } from '$lib/route';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageLoad } from './$types';
|
||||
@@ -9,7 +9,7 @@ export const load = (async ({ parent, url }) => {
|
||||
|
||||
if (!serverConfigManager.value.isInitialized) {
|
||||
// Admin not registered
|
||||
redirect(307, AppRoute.AUTH_REGISTER);
|
||||
redirect(307, Route.register());
|
||||
}
|
||||
|
||||
const $t = await getFormatter();
|
||||
@@ -17,6 +17,6 @@ export const load = (async ({ parent, url }) => {
|
||||
meta: {
|
||||
title: $t('login'),
|
||||
},
|
||||
continueUrl: url.searchParams.get('continue') || AppRoute.PHOTOS,
|
||||
continueUrl: url.searchParams.get('continue') || Route.photos(),
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
import OnboardingStorageTemplate from '$lib/components/onboarding-page/onboarding-storage-template.svelte';
|
||||
import OnboardingTheme from '$lib/components/onboarding-page/onboarding-theme.svelte';
|
||||
import OnboardingUserPrivacy from '$lib/components/onboarding-page/onboarding-user-privacy.svelte';
|
||||
import { AppRoute, QueryParameter } from '$lib/constants';
|
||||
import { serverConfigManager } from '$lib/managers/server-config-manager.svelte';
|
||||
import { systemConfigManager } from '$lib/managers/system-config-manager.svelte';
|
||||
import { Route } from '$lib/route';
|
||||
import { user } from '$lib/stores/user.store';
|
||||
import { OnboardingRole } from '$lib/types';
|
||||
import { setUserOnboarding, updateAdminOnboarding } from '@immich/sdk';
|
||||
@@ -137,11 +137,9 @@
|
||||
onboardingDto: { isOnboarded: true },
|
||||
});
|
||||
|
||||
await goto(AppRoute.PHOTOS);
|
||||
await goto(Route.photos());
|
||||
} else {
|
||||
await goto(
|
||||
`${AppRoute.AUTH_ONBOARDING}?${QueryParameter.ONBOARDING_STEP}=${onboardingSteps[nextStepIndex].name}`,
|
||||
);
|
||||
await goto(Route.onboarding({ step: onboardingSteps[nextStepIndex].name }));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,9 +148,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
await goto(
|
||||
`${AppRoute.AUTH_ONBOARDING}?${QueryParameter.ONBOARDING_STEP}=${onboardingSteps[previousStepIndex].name}`,
|
||||
);
|
||||
await goto(Route.onboarding({ step: onboardingSteps[previousStepIndex].name }));
|
||||
};
|
||||
|
||||
const OnboardingStep = $derived(onboardingSteps[index].component);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import AuthPageLayout from '$lib/components/layouts/AuthPageLayout.svelte';
|
||||
import PinCodeCreateForm from '$lib/components/user-settings-page/PinCodeCreateForm.svelte';
|
||||
import PincodeInput from '$lib/components/user-settings-page/PinCodeInput.svelte';
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { Route } from '$lib/route';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { unlockAuthSession } from '@immich/sdk';
|
||||
import { Button, Icon } from '@immich/ui';
|
||||
@@ -65,7 +65,7 @@
|
||||
onFilled={handleUnlockSession}
|
||||
/>
|
||||
|
||||
<Button type="button" color="secondary" onclick={() => goto(AppRoute.PHOTOS)}>{$t('cancel')}</Button>
|
||||
<Button type="button" color="secondary" onclick={() => goto(Route.photos())}>{$t('cancel')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { Route } from '$lib/route';
|
||||
import { authenticate } from '$lib/utils/auth';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
import { getAuthStatus } from '@immich/sdk';
|
||||
@@ -16,6 +16,6 @@ export const load = (async ({ url }) => {
|
||||
title: $t('pin_verification'),
|
||||
},
|
||||
hasPinCode: !!pinCode,
|
||||
continueUrl: url.searchParams.get('continue') || AppRoute.LOCKED,
|
||||
continueUrl: url.searchParams.get('continue') || Route.locked(),
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import AuthPageLayout from '$lib/components/layouts/AuthPageLayout.svelte';
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { serverConfigManager } from '$lib/managers/server-config-manager.svelte';
|
||||
import { Route } from '$lib/route';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { signUpAdmin } from '@immich/sdk';
|
||||
import { Alert, Button, Field, Input, PasswordInput, Text } from '@immich/ui';
|
||||
@@ -38,7 +38,7 @@
|
||||
try {
|
||||
await signUpAdmin({ signUpDto: { email, password, name } });
|
||||
await serverConfigManager.loadServerConfig();
|
||||
await goto(AppRoute.AUTH_LOGIN);
|
||||
await goto(Route.login());
|
||||
} catch (error) {
|
||||
handleError(error, $t('errors.unable_to_create_admin_account'));
|
||||
errorMessage = $t('errors.unable_to_create_admin_account');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { serverConfigManager } from '$lib/managers/server-config-manager.svelte';
|
||||
import { Route } from '$lib/route';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageLoad } from './$types';
|
||||
@@ -8,7 +8,7 @@ export const load = (async ({ parent }) => {
|
||||
await parent();
|
||||
if (serverConfigManager.value.isInitialized) {
|
||||
// Admin has been registered, redirect to login
|
||||
redirect(307, AppRoute.AUTH_LOGIN);
|
||||
redirect(307, Route.login());
|
||||
}
|
||||
|
||||
const $t = await getFormatter();
|
||||
|
||||
Reference in New Issue
Block a user