mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Merge pull request #1685 from appwrite/fix-realtime
Fix realtime on multi-region for backups
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
import { page } from '$app/stores';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
/**
|
||||
* Returns the current project ID.
|
||||
*
|
||||
* The function first checks for a `project` parameter in the Svelte `$page` store.
|
||||
* If not found, it extracts the project ID from the pathname.
|
||||
*
|
||||
* Supports:
|
||||
* - Legacy structure: `/project-{projectID}/`
|
||||
* - Multi-region structure: `/project-{region}-{projectID}/`
|
||||
*
|
||||
* Example:
|
||||
* - `/project-console/` → `console`
|
||||
* - `/project-fra-console/` → `console`
|
||||
* - `/project-nyc-console/` → `console`
|
||||
*/
|
||||
export function getProjectId() {
|
||||
// safety check!
|
||||
const projectFromParams = get(page)?.params?.project;
|
||||
if (projectFromParams) {
|
||||
return projectFromParams;
|
||||
}
|
||||
|
||||
const pathname = window.location.pathname + '/';
|
||||
const projectMatch = pathname.match(/\/project-(.*?)\//);
|
||||
const projectMatch = pathname.match(/\/project-(?:[a-z]{2,3}-)?([^/]+)/);
|
||||
|
||||
return projectMatch?.[1] || null;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
return realtime
|
||||
.forProject($page.params.region, $page.params.project)
|
||||
.subscribe(['project', 'console'], (response) => {
|
||||
console.log(response);
|
||||
if (response.events.includes('stats.connections')) {
|
||||
for (const [projectId, value] of Object.entries(response.payload)) {
|
||||
stats.add(projectId, [new Date(response.timestamp).toISOString(), value]);
|
||||
|
||||
@@ -6,6 +6,7 @@ test('getProjectId', () => {
|
||||
pathname: string;
|
||||
expected: string | null;
|
||||
}> = [
|
||||
// legacy
|
||||
{
|
||||
pathname: '/console/project-6374e9031588b25d1841/databases',
|
||||
expected: '6374e9031588b25d1841'
|
||||
@@ -34,6 +35,28 @@ test('getProjectId', () => {
|
||||
{
|
||||
pathname: '/console',
|
||||
expected: null
|
||||
},
|
||||
|
||||
// multi-region
|
||||
{
|
||||
pathname: '/console/project-fra-6374e9031588b25d1841/databases',
|
||||
expected: '6374e9031588b25d1841'
|
||||
},
|
||||
{
|
||||
pathname: '/console/project-/databases',
|
||||
expected: null
|
||||
},
|
||||
{
|
||||
pathname: '/console/project-nyc-project-project-abc/databases',
|
||||
expected: 'project-project-abc'
|
||||
},
|
||||
{
|
||||
pathname: '/console/project-fra-abc/databases',
|
||||
expected: 'abc'
|
||||
},
|
||||
{
|
||||
pathname: '/console/project-syd-abc/databases/project-123',
|
||||
expected: 'abc'
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user