@@ -3,6 +3,7 @@ package oneclickexport
3
3
import (
4
4
"archive/zip"
5
5
"bytes"
6
+ "context"
6
7
"io"
7
8
"io/ioutil"
8
9
"os"
@@ -14,7 +15,7 @@ import (
14
15
type Exporter interface {
15
16
// Export function accepts an ExportRequest and returns bytes of a zip archive
16
17
// with requested data
17
- Export (request * ExportRequest ) ([]byte , error )
18
+ Export (ctx context. Context , request * ExportRequest ) ([]byte , error )
18
19
}
19
20
20
21
var _ Exporter = & OneClickExporter {}
@@ -25,15 +26,16 @@ type OneClickExporter struct {
25
26
}
26
27
27
28
type ExportRequest struct {
28
- IncludeSiteConfig bool `json:"includeSiteConfig"`
29
+ IncludeSiteConfig bool `json:"includeSiteConfig"`
30
+ IncludeCodeHostConfig bool `json:"includeCodeHostConfig"`
29
31
}
30
32
31
33
// Export generates and returns a ZIP archive with the data, specified in request.
32
34
// It works like this:
33
35
// 1) tmp directory is created (exported files will end up in this directory and this directory is zipped in the end)
34
36
// 2) ExportRequest is read and each corresponding processor is invoked
35
37
// 3) Tmp directory is zipped after all the Processors finished their job
36
- func (e * OneClickExporter ) Export (request * ExportRequest ) ([]byte , error ) {
38
+ func (e * OneClickExporter ) Export (ctx context. Context , request * ExportRequest ) ([]byte , error ) {
37
39
// 1) creating a tmp dir
38
40
dir , err := ioutil .TempDir (os .TempDir (), "export-*" )
39
41
if err != nil {
@@ -43,7 +45,10 @@ func (e *OneClickExporter) Export(request *ExportRequest) ([]byte, error) {
43
45
44
46
// 2) tmp dir is passed to every processor
45
47
if request .IncludeSiteConfig {
46
- e .cfgProcessors ["siteConfig" ].Process (& ConfigRequest {}, dir )
48
+ e .cfgProcessors ["siteConfig" ].Process (ctx , & ConfigRequest {}, dir )
49
+ }
50
+ if request .IncludeCodeHostConfig {
51
+ e .cfgProcessors ["codeHostConfig" ].Process (ctx , & ConfigRequest {}, dir )
47
52
}
48
53
49
54
// 3) after all request parts are processed, zip the tmp dir and return its bytes
0 commit comments