fix(web): redirect to parent folder if asset viewer was open before reload (#2863)

* fix(web): redirect to parent folder if asset viewer was open before reload

* chore(web): use route constants in all routes
This commit is contained in:
Sophie 2023-06-20 04:06:08 +02:00 committed by GitHub
parent cc45564d84
commit c404ea20ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 83 additions and 27 deletions

View file

@ -18,6 +18,7 @@ export enum AppRoute {
SEARCH = '/search',
MAP = '/map',
USER_SETTINGS = '/user-settings',
MEMORY = '/memory',
AUTH_LOGIN = '/auth/login',
AUTH_LOGOUT = '/auth/logout',

View file

@ -1,18 +1,19 @@
import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageLoad = async ({ params, parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
const albumId = params['albumId'];
if (albumId) {
throw redirect(302, `/albums/${albumId}`);
throw redirect(302, `${AppRoute.ALBUMS}/${albumId}`);
} else {
throw redirect(302, `/photos`);
throw redirect(302, AppRoute.PHOTOS);
}
};

View file

@ -0,0 +1,13 @@
import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, AppRoute.AUTH_LOGIN);
}
throw redirect(302, AppRoute.ARCHIVE);
};

View file

@ -1,10 +1,11 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ locals, parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
const { data: items } = await locals.api.searchApi.getExploreData();

View file

@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageServerLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else {
throw redirect(302, '/favorites');
throw redirect(302, AppRoute.FAVORITES);
}
};

View file

@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageServerLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else {
throw redirect(302, '/memory');
throw redirect(302, AppRoute.MEMORY);
}
};

View file

@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageServerLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else {
throw redirect(302, '/memory');
throw redirect(302, AppRoute.MEMORY);
}
};

View file

@ -1,10 +1,11 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ locals, parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
const { data: people } = await locals.api.personApi.getAllPeople();

View file

@ -1,10 +1,11 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ locals, parent, params }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
const { data: person } = await locals.api.personApi.getPerson({ id: params.personId });

View file

@ -0,0 +1,14 @@
import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageLoad = async ({ params, parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, AppRoute.AUTH_LOGIN);
}
const personId = params['personId'];
throw redirect(302, `${AppRoute.PEOPLE}/${personId}`);
};

View file

@ -2,13 +2,14 @@ import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageServerLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else {
throw redirect(302, '/photos');
throw redirect(302, AppRoute.PHOTOS);
}
};

View file

@ -1,10 +1,11 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ locals, parent, url }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
const term = url.searchParams.get('q') || url.searchParams.get('query') || undefined;

View file

@ -0,0 +1,13 @@
import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, AppRoute.AUTH_LOGIN);
}
throw redirect(302, AppRoute.SEARCH);
};

View file

@ -2,18 +2,19 @@ export const prerender = false;
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ parent, locals: { api } }) => {
const { user } = await parent();
if (user) {
throw redirect(302, '/photos');
throw redirect(302, AppRoute.PHOTOS);
}
const { data } = await api.userApi.getUserCount({ admin: true });
if (data.userCount > 0) {
// Redirect to login page if an admin is already registered.
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
return {

View file

@ -1,14 +1,15 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageServerLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else if (!user.isAdmin) {
throw redirect(302, '/photos');
throw redirect(302, AppRoute.PHOTOS);
}
throw redirect(302, '/admin/user-management');
throw redirect(302, AppRoute.ADMIN_USER_MANAGEMENT);
};

View file

@ -1,13 +1,14 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ parent, locals: { api } }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else if (!user.isAdmin) {
throw redirect(302, '/photos');
throw redirect(302, AppRoute.PHOTOS);
}
const { data: stats } = await api.serverInfoApi.getStats();

View file

@ -1,13 +1,14 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load: PageServerLoad = async ({ parent }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else if (!user.isAdmin) {
throw redirect(302, '/photos');
throw redirect(302, AppRoute.PHOTOS);
}
return {

View file

@ -1,13 +1,14 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ parent, locals: { api } }) => {
const { user } = await parent();
if (!user) {
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
} else if (!user.isAdmin) {
throw redirect(302, '/photos');
throw redirect(302, AppRoute.PHOTOS);
}
const { data: allUsers } = await api.userApi.getAllUsers({ isAll: false });

View file

@ -1,11 +1,12 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { AppRoute } from '$lib/constants';
export const load = (async ({ locals: { api } }) => {
const { data } = await api.userApi.getUserCount({ admin: true });
if (data.userCount != 0) {
// Admin has been registered, redirect to login
throw redirect(302, '/auth/login');
throw redirect(302, AppRoute.AUTH_LOGIN);
}
return {