Skip to content

Commit

Permalink
fix: config not working (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wsine authored Jul 11, 2024
1 parent da22642 commit c3ad27a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c3ad27a

Please sign in to comment.