1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00

fix(web): i18n race condition in load function (#10693)

This commit is contained in:
Michel Heusschen 2024-06-29 18:29:56 +02:00 committed by GitHub
parent 24c1855899
commit 8f553ddb39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 74 additions and 89 deletions

13
web/src/lib/utils/i18n.ts Normal file
View file

@ -0,0 +1,13 @@
import { locale, t, waitLocale } from 'svelte-i18n';
import { get, type Unsubscriber } from 'svelte/store';
export async function getFormatter() {
let unsubscribe: Unsubscriber | undefined;
await new Promise((resolve) => {
unsubscribe = locale.subscribe((value) => value && resolve(value));
});
unsubscribe?.();
await waitLocale();
return get(t);
}

View file

@ -1,14 +1,13 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAllAlbums } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate();
const sharedAlbums = await getAllAlbums({ shared: true });
const albums = await getAllAlbums({});
const $t = get(t);
const $t = await getFormatter();
return {
albums,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAllPeople, getExploreData } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate();
const [items, response] = await Promise.all([getExploreData(), getAllPeople({ withHidden: false })]);
const $t = get(t);
const $t = await getFormatter();
return {
items,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
const user = await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
user,

View file

@ -1,8 +1,7 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getUser } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
@ -10,7 +9,7 @@ export const load = (async ({ params }) => {
const partner = await getUser({ id: params.userId });
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,14 +1,13 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAllPeople } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate();
const people = await getAllPeople({ withHidden: true });
const $t = get(t);
const $t = await getFormatter();
return {
people,

View file

@ -1,8 +1,7 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getPerson, getPersonStatistics } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
@ -13,7 +12,7 @@ export const load = (async ({ params }) => {
getPersonStatistics({ id: params.personId }),
getAssetInfoFromParam(params),
]);
const $t = get(t);
const $t = await getFormatter();
return {
person,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetsByCity } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate();
const items = await getAssetsByCity();
const $t = get(t);
const $t = await getFormatter();
return {
items,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,22 +1,21 @@
import { getAssetThumbnailUrl, setSharedLink } from '$lib/utils';
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getMySharedLink, isHttpError } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
const { key } = params;
await authenticate({ public: true });
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
try {
const sharedLink = await getMySharedLink({ key });
setSharedLink(sharedLink);
const assetCount = sharedLink.assets.length;
const assetId = sharedLink.album?.albumThumbnailAssetId || sharedLink.assets[0]?.id;
const $t = await getFormatter();
return {
sharedLink,
@ -30,6 +29,7 @@ export const load = (async ({ params }) => {
};
} catch (error) {
if (isHttpError(error) && error.data.message === 'Invalid password') {
const $t = await getFormatter();
return {
passwordRequired: true,
sharedLinkKey: key,

View file

@ -1,14 +1,13 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAllAlbums, getPartners } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate();
const sharedAlbums = await getAllAlbums({ shared: true });
const partners = await getPartners({ direction: 'shared-with' });
const $t = get(t);
const $t = await getFormatter();
return {
sharedAlbums,

View file

@ -1,11 +1,10 @@
import { authenticate } from '$lib/utils/auth';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import { getFormatter } from '$lib/utils/i18n';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate();
const $t = get(t);
const $t = await getFormatter();
return {
meta: {

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,7 +1,6 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getApiKeys, getSessions } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
@ -9,7 +8,7 @@ export const load = (async () => {
const keys = await getApiKeys();
const sessions = await getSessions();
const $t = get(t);
const $t = await getFormatter();
return {
keys,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,15 +1,14 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getAssetDuplicates } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params }) => {
await authenticate();
const asset = await getAssetInfoFromParam(params);
const duplicates = await getAssetDuplicates();
const $t = get(t);
const $t = await getFormatter();
return {
asset,

View file

@ -1,8 +1,7 @@
import { AppRoute } from '$lib/constants';
import { getFormatter } from '$lib/utils/i18n';
import { getServerConfig } from '@immich/sdk';
import { redirect } from '@sveltejs/kit';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import { loadUser } from '../lib/utils/auth';
import type { PageLoad } from './$types';
@ -21,7 +20,7 @@ export const load = (async () => {
redirect(302, AppRoute.AUTH_LOGIN);
}
const $t = get(t);
const $t = await getFormatter();
return {
meta: {

View file

@ -1,14 +1,13 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAllJobsStatus } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
const jobs = await getAllJobsStatus();
const $t = get(t);
const $t = await getFormatter();
return {
jobs,

View file

@ -1,14 +1,13 @@
import { authenticate, requestServerInfo } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { searchUsersAdmin } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
await requestServerInfo();
const allUsers = await searchUsersAdmin({ withDeleted: false });
const $t = get(t);
const $t = await getFormatter();
return {
allUsers,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAuditFiles } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
const { orphans, extras } = await getAuditFiles();
const $t = get(t);
const $t = await getFormatter();
return {
orphans,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getServerStatistics } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
const stats = await getServerStatistics();
const $t = get(t);
const $t = await getFormatter();
return {
stats,

View file

@ -1,13 +1,12 @@
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getConfig } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
const configs = await getConfig();
const $t = get(t);
const $t = await getFormatter();
return {
configs,

View file

@ -1,14 +1,13 @@
import { authenticate, requestServerInfo } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { searchUsersAdmin } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
await requestServerInfo();
const allUsers = await searchUsersAdmin({ withDeleted: true });
const $t = get(t);
const $t = await getFormatter();
return {
allUsers,

View file

@ -1,8 +1,8 @@
import { AppRoute } from '$lib/constants';
import { user } from '$lib/stores/user.store';
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { redirect } from '@sveltejs/kit';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
@ -12,7 +12,7 @@ export const load = (async () => {
redirect(302, AppRoute.PHOTOS);
}
const $t = get(t);
const $t = await getFormatter();
return {
meta: {

View file

@ -1,8 +1,7 @@
import { AppRoute } from '$lib/constants';
import { getFormatter } from '$lib/utils/i18n';
import { defaults, getServerConfig } from '@immich/sdk';
import { redirect } from '@sveltejs/kit';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ fetch }) => {
@ -13,7 +12,7 @@ export const load = (async ({ fetch }) => {
redirect(302, AppRoute.AUTH_REGISTER);
}
const $t = get(t);
const $t = await getFormatter();
return {
meta: {
title: $t('login'),

View file

@ -1,14 +1,13 @@
import { loadConfig } from '$lib/stores/server-config.store';
import { authenticate } from '$lib/utils/auth';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import { getFormatter } from '$lib/utils/i18n';
import type { PageLoad } from './$types';
export const load = (async () => {
await authenticate({ admin: true });
await loadConfig();
const $t = get(t);
const $t = await getFormatter();
return {
meta: {

View file

@ -1,8 +1,7 @@
import { AppRoute } from '$lib/constants';
import { getFormatter } from '$lib/utils/i18n';
import { getServerConfig } from '@immich/sdk';
import { redirect } from '@sveltejs/kit';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async () => {
@ -12,7 +11,7 @@ export const load = (async () => {
redirect(302, AppRoute.AUTH_LOGIN);
}
const $t = get(t);
const $t = await getFormatter();
return {
meta: {