From c3ad27a2de6ba07b9affed622d82760d14261268 Mon Sep 17 00:00:00 2001 From: Jankin Wei Date: Thu, 11 Jul 2024 13:44:40 +0800 Subject: [PATCH] fix: config not working (#128) --- cmd/download.go | 15 ++++++++------- core/config.go | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/download.go b/cmd/download.go index 86a29e3..64fac16 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -24,7 +24,7 @@ type DownloadOpts struct { var dlOpts = DownloadOpts{} var dlConfig core.Config -func downloadDocument(client *core.Client, ctx context.Context, url string, opts *DownloadOpts) error { +func downloadDocument(ctx context.Context, client *core.Client, url string, opts *DownloadOpts) error { // Validate the url to download docType, docToken, err := utils.ValidateDocumentURL(url) if err != nil { @@ -59,7 +59,7 @@ func downloadDocument(client *core.Client, ctx context.Context, url string, opts localLink, err := client.DownloadImage( ctx, imgToken, filepath.Join(opts.outputDir, dlConfig.Output.ImageDir), ) - if utils.CheckErr(err) != nil { + if err != nil { return err } markdown = strings.Replace(markdown, imgToken, localLink, 1) @@ -111,7 +111,7 @@ func downloadDocument(client *core.Client, ctx context.Context, url string, opts return nil } -func downloadDocuments(client *core.Client, ctx context.Context, url string) error { +func downloadDocuments(ctx context.Context, client *core.Client, url string) error { // Validate the url to download folderToken, err := utils.ValidateFolderURL(url) if err != nil { @@ -141,7 +141,7 @@ func downloadDocuments(client *core.Client, ctx context.Context, url string) err // concurrently download the document wg.Add(1) go func(_url string) { - if err := downloadDocument(client, ctx, _url, &opts); err != nil { + if err := downloadDocument(ctx, client, _url, &opts); err != nil { errChan <- err } wg.Done() @@ -171,10 +171,11 @@ func handleDownloadCommand(url string) error { if err != nil { return err } - dlConfig, err := core.ReadConfigFromFile(configPath) + config, err := core.ReadConfigFromFile(configPath) if err != nil { return err } + dlConfig = *config // Instantiate the client client := core.NewClient( @@ -183,8 +184,8 @@ func handleDownloadCommand(url string) error { ctx := context.Background() if dlOpts.batch { - return downloadDocuments(client, ctx, url) + return downloadDocuments(ctx, client, url) } - return downloadDocument(client, ctx, url, &dlOpts) + return downloadDocument(ctx, client, url, &dlOpts) } diff --git a/core/config.go b/core/config.go index 82943a9..c0aea08 100644 --- a/core/config.go +++ b/core/config.go @@ -53,12 +53,12 @@ func ReadConfigFromFile(configPath string) (*Config, error) { if err != nil { return nil, err } - config := Config{} + config := NewConfig("", "") err = json.Unmarshal([]byte(file), &config) if err != nil { return nil, err } - return &config, nil + return config, nil } func (conf *Config) WriteConfig2File(configPath string) error {