@@ -683,30 +683,6 @@ export async function uploadFile(args = []) {
683683 }
684684}
685685
686- /**
687- * Get a temporary CSRF Token
688- * @returns The CSRF token
689- */
690- async function getCsrfToken ( ) {
691- const csrfResponse = await fetch ( `${ BASE_URL } /get-anticsrf-token` , {
692- method : 'GET' ,
693- headers : getHeaders ( )
694- } ) ;
695-
696- if ( ! csrfResponse . ok ) {
697- console . error ( chalk . red ( 'Failed to fetch CSRF token.' ) ) ;
698- return ;
699- }
700-
701- const csrfData = await csrfResponse . json ( ) ;
702- if ( ! csrfData || ! csrfData . token ) {
703- console . error ( chalk . red ( 'Failed to fetch anti-CSRF token.' ) ) ;
704- return ;
705- }
706-
707- return csrfData . token ;
708- }
709-
710686/**
711687 * Download a file from the Puter server to the host machine
712688 * @param {Array } args - The arguments passed to the command (remote file path, Optional: local path).
@@ -751,18 +727,8 @@ export async function downloadFile(args = []) {
751727
752728 console . log ( chalk . green ( `Downloading file "${ remoteFilePath } " to "${ localFilePath } "...` ) ) ;
753729
754- // Fetch the anti-CSRF token
755- const antiCsrfToken = await getCsrfToken ( ) ;
756-
757- const downloadResponse = await fetch ( `${ BASE_URL } /down?path=${ remoteFilePath } ` , {
758- method : 'POST' ,
759- headers : {
760- ...getHeaders ( 'application/x-www-form-urlencoded' ) ,
761- "cookie" : `puter_auth_token=${ getAuthToken ( ) } ;`
762- } ,
763- "referrerPolicy" : "strict-origin-when-cross-origin" ,
764- body : `anti_csrf=${ antiCsrfToken } `
765- } ) ;
730+ const fileUrl = await puter . fs . getReadURL ( remoteFilePath ) ;
731+ const downloadResponse = await fetch ( fileUrl ) ;
766732
767733 if ( ! downloadResponse . ok ) {
768734 console . error ( chalk . red ( `Failed to download file "${ remoteFilePath } ". Server response: ${ downloadResponse . statusText } ` ) ) ;
0 commit comments