@@ -38,7 +38,7 @@ export async function queueMessage(content: string, url: string, env: Env, lab =
3838 return { id : nextId , filename : fname , time : agora . getTime ( ) } ;
3939}
4040
41- async function handleSync ( request : Request , content : string , routeRow : PathRouteRow , env : Env , ctx : ExecutionContext , lab = false ) {
41+ async function handleSync ( request : Request , content : string , routeRow : PathRouteRow , env : Env , ctx : ExecutionContext , lab = false , fullpath : string | null = null ) {
4242 const route = toPathRoute ( routeRow ) ;
4343 const asyncConfig = toPathRouteAsync ( route ) ;
4444 const records = [ ] ;
@@ -70,7 +70,7 @@ async function handleSync(request: Request, content: string, routeRow: PathRoute
7070 headers . set ( 'Content-Type' , route . contentTypeDestiny ) ;
7171 }
7272
73- const destinyResponse = await fetch ( asyncConfig . destiny ! , {
73+ const destinyResponse = await fetch ( asyncConfig . destiny ! + ( ! fullpath ? '' : fullpath ) , {
7474 method : asyncConfig . methodDestiny || request . method ,
7575 headers : headers ,
7676 body : content || null
@@ -112,7 +112,7 @@ async function handleSync(request: Request, content: string, routeRow: PathRoute
112112}
113113
114114// Essa função esta perfeita e não deve ser alterada sem permissao do usuário
115- async function handleRequest ( request : Request , env : Env , ctx : ExecutionContext , lab = false ) {
115+ async function handleRequest ( request : Request , env : Env , ctx : ExecutionContext , lab = false , fullpath : string | null = null ) {
116116 try {
117117 const content = await request . text ( ) ;
118118 const { pathname } = new URL ( request . url ) ;
@@ -137,17 +137,22 @@ async function handleRequest(request: Request, env: Env, ctx: ExecutionContext,
137137 }
138138
139139 if ( pathname . startsWith ( '/sync/' ) ) {
140- const normalizedPath = normalizePathKey ( pathname . substring ( 6 ) ) ;
140+ let normalizedPath = normalizePathKey ( pathname . substring ( 6 ) ) ;
141141 if ( ! normalizedPath ) {
142142 throw new Error ( 'Sync path is required.' ) ;
143143 }
144+ let fullpath = null ;
145+ if ( normalizedPath . includes ( '/' ) ) {
146+ fullpath = normalizedPath . substring ( normalizedPath . indexOf ( '/' ) ) ;
147+ normalizedPath = normalizePathKey ( normalizedPath . substring ( 0 , normalizedPath . indexOf ( '/' ) ) ) ;
148+ }
144149
145150 const route = await env . DB . prepare ( database . selectByPath ) . bind ( normalizedPath ) . first < PathRouteRow > ( ) ;
146151 if ( ! route ) {
147152 throw new Error ( `Sync route not found for path: ${ normalizedPath } ` ) ;
148153 }
149154
150- return await handleSync ( request , content , route , env , ctx , lab ) ;
155+ return await handleSync ( request , content , route , env , ctx , lab , fullpath ) ;
151156 }
152157
153158 await queueMessage ( content , request . url , env , lab ) ;
0 commit comments