refactor: redirect code (#25054)

This commit is contained in:
Jason Rasmussen 2026-01-05 14:39:28 -05:00 committed by GitHub
parent 10989e6927
commit 4d32968f2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 23 additions and 23 deletions

View file

@ -59,11 +59,11 @@ export const authenticate = async (url: URL, options?: AuthOptions) => {
} }
if (!user) { if (!user) {
redirect(302, `${AppRoute.AUTH_LOGIN}?continue=${encodeURIComponent(url.pathname + url.search)}`); redirect(307, `${AppRoute.AUTH_LOGIN}?continue=${encodeURIComponent(url.pathname + url.search)}`);
} }
if (adminRoute && !user.isAdmin) { if (adminRoute && !user.isAdmin) {
redirect(302, AppRoute.PHOTOS); redirect(307, AppRoute.PHOTOS);
} }
}; };

View file

@ -10,7 +10,7 @@ export const load = (async ({ url }) => {
const { isElevated, pinCode } = await getAuthStatus(); const { isElevated, pinCode } = await getAuthStatus();
if (!isElevated || !pinCode) { if (!isElevated || !pinCode) {
redirect(302, `${AppRoute.AUTH_PIN_PROMPT}?continue=${encodeURIComponent(url.pathname + url.search)}`); redirect(307, `${AppRoute.AUTH_PIN_PROMPT}?continue=${encodeURIComponent(url.pathname + url.search)}`);
} }
const $t = await getFormatter(); const $t = await getFormatter();

View file

@ -9,12 +9,12 @@ export const load = (async ({ params, url }) => {
await authenticate(url); await authenticate(url);
if (!UUID_REGEX.test(params.id)) { if (!UUID_REGEX.test(params.id)) {
redirect(302, AppRoute.SHARED_LINKS); redirect(307, AppRoute.SHARED_LINKS);
} }
const [sharedLink] = await getAllSharedLinks({ id: params.id }); const [sharedLink] = await getAllSharedLinks({ id: params.id });
if (!sharedLink) { if (!sharedLink) {
redirect(302, AppRoute.SHARED_LINKS); redirect(307, AppRoute.SHARED_LINKS);
} }
const $t = await getFormatter(); const $t = await getFormatter();

View file

@ -4,5 +4,5 @@ import type { PageLoad } from './$types';
export const load = (({ params }) => { export const load = (({ params }) => {
const photoId = params.photoId; const photoId = params.photoId;
return redirect(302, `${AppRoute.PHOTOS}/${photoId}`); return redirect(307, `${AppRoute.PHOTOS}/${photoId}`);
}) satisfies PageLoad; }) satisfies PageLoad;

View file

@ -14,22 +14,22 @@ export const load = (async ({ fetch }) => {
await init(fetch); await init(fetch);
if (serverConfigManager.value.maintenanceMode) { if (serverConfigManager.value.maintenanceMode) {
redirect(302, AppRoute.MAINTENANCE); redirect(307, AppRoute.MAINTENANCE);
} }
const authenticated = await loadUser(); const authenticated = await loadUser();
if (authenticated) { if (authenticated) {
redirect(302, AppRoute.PHOTOS); redirect(307, AppRoute.PHOTOS);
} }
if (serverConfigManager.value.isInitialized) { if (serverConfigManager.value.isInitialized) {
// Redirect to login page if there exists an admin account (i.e. server is initialized) // Redirect to login page if there exists an admin account (i.e. server is initialized)
redirect(302, AppRoute.AUTH_LOGIN); redirect(307, AppRoute.AUTH_LOGIN);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (redirectError: any) { } catch (redirectError: any) {
if (redirectError?.status === 302) { if (redirectError?.status === 307) {
throw redirectError; throw redirectError;
} }
} }

View file

@ -3,5 +3,5 @@ import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (() => { export const load = (() => {
redirect(302, AppRoute.ADMIN_SETTINGS); redirect(307, AppRoute.ADMIN_SETTINGS);
}) satisfies PageLoad; }) satisfies PageLoad;

View file

@ -13,7 +13,7 @@ export const load = (async ({ params: { id }, url }) => {
try { try {
library = await getLibrary({ id }); library = await getLibrary({ id });
} catch { } catch {
redirect(302, AppRoute.ADMIN_LIBRARIES); redirect(307, AppRoute.ADMIN_LIBRARIES);
} }
const statistics = await getLibraryStatistics({ id }); const statistics = await getLibraryStatistics({ id });

View file

@ -12,7 +12,7 @@ export const load = (async ({ params, url }) => {
const name = fromQueueSlug(params.name); const name = fromQueueSlug(params.name);
if (!name) { if (!name) {
redirect(302, AppRoute.ADMIN_QUEUES); redirect(307, AppRoute.ADMIN_QUEUES);
} }
const [queue, failedJobs] = await Promise.all([ const [queue, failedJobs] = await Promise.all([

View file

@ -10,12 +10,12 @@ export const load = (async ({ params, url }) => {
await requestServerInfo(); await requestServerInfo();
if (!UUID_REGEX.test(params.id)) { if (!UUID_REGEX.test(params.id)) {
redirect(302, AppRoute.ADMIN_USERS); redirect(307, AppRoute.ADMIN_USERS);
} }
const [user] = await searchUsersAdmin({ id: params.id, withDeleted: true }).catch(() => []); const [user] = await searchUsersAdmin({ id: params.id, withDeleted: true }).catch(() => []);
if (!user) { if (!user) {
redirect(302, AppRoute.ADMIN_USERS); redirect(307, AppRoute.ADMIN_USERS);
} }
const [userPreferences, userStatistics, userSessions] = await Promise.all([ const [userPreferences, userStatistics, userSessions] = await Promise.all([

View file

@ -9,7 +9,7 @@ import type { PageLoad } from './$types';
export const load = (async ({ url }) => { export const load = (async ({ url }) => {
await authenticate(url); await authenticate(url);
if (!get(user).shouldChangePassword) { if (!get(user).shouldChangePassword) {
redirect(302, AppRoute.PHOTOS); redirect(307, AppRoute.PHOTOS);
} }
const $t = await getFormatter(); const $t = await getFormatter();

View file

@ -9,7 +9,7 @@ export const load = (async ({ parent, url }) => {
if (!serverConfigManager.value.isInitialized) { if (!serverConfigManager.value.isInitialized) {
// Admin not registered // Admin not registered
redirect(302, AppRoute.AUTH_REGISTER); redirect(307, AppRoute.AUTH_REGISTER);
} }
const $t = await getFormatter(); const $t = await getFormatter();

View file

@ -8,7 +8,7 @@ export const load = (async ({ parent }) => {
await parent(); await parent();
if (serverConfigManager.value.isInitialized) { if (serverConfigManager.value.isInitialized) {
// Admin has been registered, redirect to login // Admin has been registered, redirect to login
redirect(302, AppRoute.AUTH_LOGIN); redirect(307, AppRoute.AUTH_LOGIN);
} }
const $t = await getFormatter(); const $t = await getFormatter();

View file

@ -14,17 +14,17 @@ export const load = (({ url }) => {
const target = queryParams.get('target') as LinkTarget; const target = queryParams.get('target') as LinkTarget;
switch (target) { switch (target) {
case LinkTarget.HOME: { case LinkTarget.HOME: {
return redirect(302, AppRoute.PHOTOS); return redirect(307, AppRoute.PHOTOS);
} }
case LinkTarget.UNSUBSCRIBE: { case LinkTarget.UNSUBSCRIBE: {
return redirect(302, `${AppRoute.USER_SETTINGS}?isOpen=notifications`); return redirect(307, `${AppRoute.USER_SETTINGS}?isOpen=notifications`);
} }
case LinkTarget.VIEW_ASSET: { case LinkTarget.VIEW_ASSET: {
const id = queryParams.get('id'); const id = queryParams.get('id');
if (id) { if (id) {
return redirect(302, `${AppRoute.PHOTOS}/${id}`); return redirect(307, `${AppRoute.PHOTOS}/${id}`);
} }
break; break;
} }
@ -42,12 +42,12 @@ export const load = (({ url }) => {
redirectUrl.searchParams.append('activationKey', activationKey); redirectUrl.searchParams.append('activationKey', activationKey);
} }
return redirect(302, redirectUrl); return redirect(307, redirectUrl);
} }
break; break;
} }
} }
return redirect(302, AppRoute.PHOTOS); return redirect(307, AppRoute.PHOTOS);
}) satisfies PageLoad; }) satisfies PageLoad;