-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking changes are independent of our work but is rather due to API inconsistencies in the CTFd update.
- Loading branch information
Showing
5 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package api | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
type ExportRawParams struct { | ||
// Type could be "csv" (which returns the table dump in csv) or | ||
// anything (returns a zip). | ||
Type string `json:"type"` | ||
|
||
// Args contains all the arguments to export specific content. | ||
Args ExportRawArgsParams `json:"args"` | ||
} | ||
|
||
type ExportRawArgsParams struct { | ||
// Table, if specified, exports the given table in the specified type. | ||
Table *string `json:"table,omitempty"` | ||
} | ||
|
||
func (client *Client) ExportRaw(params *ExportRawParams, opts ...Option) ([]byte, error) { | ||
if params == nil { | ||
params = &ExportRawParams{} | ||
} | ||
i, err := json.Marshal(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Build request and execute it manunally | ||
req, _ := http.NewRequest(http.MethodPost, "/api/v1/exports/raw", bytes.NewBuffer(i)) | ||
req.Header.Set("Content-Type", "application/json") | ||
res, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("CTFd responded with unexpected status code: got %d", res.StatusCode) | ||
} | ||
|
||
b, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return b, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters