@@ -3,6 +3,7 @@ import { get } from 'svelte/store';
33import { sdk } from '$lib/stores/sdk' ;
44import { projectRegion } from '$routes/(console)/project-[region]-[project]/store' ;
55import type { Models } from '@appwrite.io/console' ;
6+ import { error } from '@sveltejs/kit' ;
67
78/**
89 * Returns the current project ID.
@@ -45,5 +46,50 @@ export function getProjectEndpoint(): string {
4546}
4647
4748export function isProjectBlocked ( project : Models . Project | null | undefined ) : boolean {
48- return project ?. status !== 'paused' && ! ! project ?. blocks ?. length ;
49+ const hasGlobalProjectBlock = ( project ?. blocks ?? [ ] ) . some ( ( block ) => {
50+ const type = block . resourceType ?. trim ( ) . toLowerCase ( ) ;
51+ const id = block . resourceId ?. trim ( ) ;
52+
53+ // Global project block:
54+ // - legacy: both type and id empty
55+ // - new: resourceType === 'projects' with no specific resourceId
56+ const isLegacyGlobal = ! type && ! id ;
57+ const isProjectsGlobal = type === 'projects' && ! id ;
58+
59+ return isLegacyGlobal || isProjectsGlobal ;
60+ } ) ;
61+
62+ return project ?. status !== 'paused' && hasGlobalProjectBlock ;
63+ }
64+
65+ export function isResourceBlocked (
66+ project : Models . Project | null | undefined ,
67+ resourceType : string ,
68+ resourceId : string
69+ ) : boolean {
70+ const normalizedType = resourceType . trim ( ) . toLowerCase ( ) ;
71+ const normalizedId = resourceId . trim ( ) ;
72+
73+ return ( project ?. blocks ?? [ ] ) . some ( ( block ) => {
74+ const type = block . resourceType ?. trim ( ) . toLowerCase ( ) ;
75+ const id = block . resourceId ?. trim ( ) ;
76+
77+ return type === normalizedType && id === normalizedId ;
78+ } ) ;
79+ }
80+
81+ export function guardResourceBlock (
82+ project : Models . Project | null | undefined ,
83+ resourceType : string | string [ ] ,
84+ resourceId : string
85+ ) {
86+ const resourceTypes = Array . isArray ( resourceType ) ? resourceType : [ resourceType ] ;
87+ const isBlocked = resourceTypes . some ( ( type ) => isResourceBlocked ( project , type , resourceId ) ) ;
88+
89+ if ( isBlocked ) {
90+ error ( 403 , {
91+ type : 'general_resource_blocked' ,
92+ message : 'This resource page cannot be accessed.'
93+ } ) ;
94+ }
4995}
0 commit comments