mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
add: old to new redirects.
This commit is contained in:
@@ -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>
|
||||
|
||||
+41
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user