@@ -81,11 +81,15 @@ async function create(
8181 owner : 'workspace' | 'project' ,
8282 name : string ,
8383 contentType : string ,
84- content : string
84+ content : string ,
85+ folderId ?: string
8586) {
8687 const response = await request (
8788 `/api/${ owner === 'workspace' ? `workspaces/${ workspaceId } ` : `projects/${ projectId } ` } /files` ,
88- { method : 'POST' , body : JSON . stringify ( { name, contentType, content, encoding : 'utf-8' } ) }
89+ {
90+ method : 'POST' ,
91+ body : JSON . stringify ( { name, contentType, content, encoding : 'utf-8' , folderId } ) ,
92+ }
8993 )
9094 assert . ok ( response . ok , `Create returned ${ response . status } : ${ await response . clone ( ) . text ( ) } ` )
9195 return toRecord ( toRecord ( await response . json ( ) ) . file )
@@ -204,6 +208,31 @@ await check(
204208 }
205209 }
206210)
211+ await check ( 'v2 workspace download routes a %2F-encoded files/ VFS path to its file' , async ( ) => {
212+ const folderResponse = await request ( `/api/workspaces/${ workspaceId } /files/folders` , {
213+ method : 'POST' ,
214+ body : JSON . stringify ( { name : 'VfsDocs' } ) ,
215+ } )
216+ assert . ok ( folderResponse . ok , `Folder create returned ${ folderResponse . status } ` )
217+ const folderId = required ( toRecord ( toRecord ( await folderResponse . json ( ) ) . folder ) . id )
218+ await create ( 'workspace' , 'vfs-report.csv' , 'text/csv' , 'root copy' )
219+ await create ( 'workspace' , 'vfs-report.csv' , 'text/csv' , 'folder copy' , folderId )
220+ const download = ( path : string ) =>
221+ request (
222+ `/api/v2/files/${ encodeURIComponent ( path ) } ?workspaceId=${ workspaceId } ` ,
223+ { headers : { 'X-API-Key' : personalKey } } ,
224+ true
225+ )
226+ for ( const [ path , content ] of [
227+ [ 'files/VfsDocs/vfs-report.csv' , 'folder copy' ] ,
228+ [ 'files/vfs-report.csv' , 'root copy' ] ,
229+ ] ) {
230+ const response = await download ( path )
231+ assert . equal ( response . status , 200 , `${ path } returned ${ response . status } ` )
232+ assert . equal ( await response . text ( ) , content )
233+ }
234+ assert . equal ( ( await download ( 'files/VfsDocs/missing.csv' ) ) . status , 404 )
235+ } )
207236await check ( 'Workspace immutable URLs, authorized 304 and browser cache reuse' , async ( ) => {
208237 const file = await create ( 'workspace' , 'cache.txt' , 'text/plain' , 'workspace cache bytes' )
209238 const path = `/api/files/serve/${ required ( file . key ) } `
0 commit comments