add: old to new redirects.

This commit is contained in:
Darshan
2025-06-18 18:55:21 +05:30
parent db802cc5f1
commit 4157d3cbee
2 changed files with 44 additions and 1 deletions
@@ -6,6 +6,7 @@
import { capitalize } from '$lib/helpers/string';
import { currentPlan } from '$lib/stores/organization';
import { wizard } from '$lib/stores/wizard';
function getResource(id: string) {
id = id.replace('/(console)/project-[region]-[project]/', '');
let parts = id.split('/');
@@ -39,6 +40,7 @@
>{'status' in page.error
? page.error.status || 'Invalid Argument'
: 'Invalid Argument'}</Typography.Title>
<p class="body-text-2 u-bold u-margin-block-start-4">{page.error.message}</p>
<Typography.Title>{page.error.message}</Typography.Title>
{/if}
</Container>
@@ -0,0 +1,41 @@
import { base } from '$app/paths';
import type { PageLoad } from './$types';
import { redirect } from '@sveltejs/kit';
import { AppwriteException } from '@appwrite.io/console';
const LEGACY_ROUTE_MAPPINGS = [
{ pattern: /^collection-([^/]+)/, replacement: 'table-$1' },
{ pattern: /^document-([^/]+)/, replacement: 'row-$1' },
{ pattern: /^attribute-([^/]+)/, replacement: 'column-$1' }
] as const;
function isLegacyRoute(segments: string[]): boolean {
return segments.some((segment) =>
LEGACY_ROUTE_MAPPINGS.some((mapping) => mapping.pattern.test(segment))
);
}
function rewriteLegacySegments(segments: string[]): string[] {
return segments.map((segment) => {
for (const mapping of LEGACY_ROUTE_MAPPINGS) {
if (mapping.pattern.test(segment)) {
return segment.replace(mapping.pattern, mapping.replacement);
}
}
return segment;
});
}
export const load: PageLoad = async ({ params, url }) => {
const restSegments = params.rest ? params.rest.split('/').filter(Boolean) : [];
const baseUrl = `${base}/project-${params.region}-${params.project}/databases/database-${params.database}`;
if (isLegacyRoute(restSegments)) {
const rewrittenSegments = rewriteLegacySegments(restSegments);
const newPath = `${baseUrl}/${rewrittenSegments.join('/')}`;
redirect(308, newPath + url.search);
}
throw new AppwriteException('Not Found', 404);
};