@@ -138,33 +138,38 @@ func Run(ctx context.Context, slug string, projectRef string, useLegacyBundle bo
138
138
139
139
func downloadOne (ctx context.Context , slug string , projectRef string , fsys afero.Fs ) (string , error ) {
140
140
fmt .Println ("Downloading " + utils .Bold (slug ))
141
- resp , err := utils .GetSupabase ().GetFunctionBodyWithResponse (ctx , projectRef , slug )
141
+ resp , err := utils .GetSupabase ().GetFunctionBody (ctx , projectRef , slug )
142
142
if err != nil {
143
143
return "" , errors .Errorf ("failed to get function body: %w" , err )
144
144
}
145
- if resp .StatusCode () != http .StatusOK {
146
- return "" , errors .New ("Unexpected error downloading Function: " + string (resp .Body ))
145
+ defer resp .Body .Close ()
146
+ if resp .StatusCode != http .StatusOK {
147
+ body , err := io .ReadAll (resp .Body )
148
+ if err != nil {
149
+ return "" , errors .Errorf ("Error status %d: unexpected error downloading Function" , resp .StatusCode )
150
+ }
151
+ return "" , errors .Errorf ("Error status %d: %s" , resp .StatusCode , string (body ))
147
152
}
148
-
149
153
// Create temp file to store downloaded eszip
150
- eszipFile , err := afero . TempFile ( fsys , " " , slug )
151
- if err != nil {
152
- return "" , errors . Errorf ( "failed to create temporary file: %w" , err )
154
+ eszipPath := filepath . Join ( utils . TempDir , fmt . Sprintf ( "output_%s.eszip " , slug ) )
155
+ if err := utils . MkdirIfNotExistFS ( fsys , utils . TempDir ); err != nil {
156
+ return "" , err
153
157
}
154
- defer eszipFile .Close ()
155
-
156
- body := bytes .NewReader (resp .Body )
157
- if _ , err = io .Copy (eszipFile , body ); err != nil {
158
+ if err := afero .WriteReader (fsys , eszipPath , resp .Body ); err != nil {
158
159
return "" , errors .Errorf ("failed to download file: %w" , err )
159
160
}
160
- return eszipFile . Name () , nil
161
+ return eszipPath , nil
161
162
}
162
163
163
- func extractOne (ctx context.Context , hostEszipPath string ) error {
164
+ func extractOne (ctx context.Context , eszipPath string ) error {
164
165
hostFuncDirPath , err := filepath .Abs (utils .FunctionsDir )
165
166
if err != nil {
166
167
return errors .Errorf ("failed to resolve absolute path: %w" , err )
167
168
}
169
+ hostEszipPath , err := filepath .Abs (eszipPath )
170
+ if err != nil {
171
+ return errors .Errorf ("failed to resolve eszip path: %w" , err )
172
+ }
168
173
169
174
dockerEszipPath := path .Join (dockerEszipDir , filepath .Base (hostEszipPath ))
170
175
binds := []string {
0 commit comments