Skip to content

Commit

Permalink
api, extl: use ext url extractor in download method
Browse files Browse the repository at this point in the history
  • Loading branch information
celestix committed Mar 22, 2024
1 parent c05ede4 commit 183e247
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Once you have made the required changes, make sure you have tested your changes
- `docs` - For changes in the documentation.
- `api` - For changes in the API specifications.
- `daemon` - For changes in the daemon.

- `extl` - For changes in the extension loader.

**Note**: If your changes fall under multiple major areas, you can use multiple major areas separated by a comma.

Expand Down
4 changes: 4 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ func NewApi(l *log.Logger, elEngine *extloader.Engine) (*Api, error) {
}

func (s *Api) RegisterHandlers(server *server.Server) {
// downloader API methods
server.RegisterHandler(common.UPDATE_DOWNLOAD, s.downloadHandler)
server.RegisterHandler(common.UPDATE_RESUME, s.resumeHandler)
server.RegisterHandler(common.UPDATE_ATTACH, s.attachHandler)
server.RegisterHandler(common.UPDATE_FLUSH, s.flushHandler)
server.RegisterHandler(common.UPDATE_STOP, s.stopHandler)
server.RegisterHandler(common.UPDATE_LIST, s.listHandler)

// extension API methods
server.RegisterHandler(common.UPDATE_LOAD_EXT, s.loadExtHandler)
}

func (s *Api) Close() error {
Expand Down
10 changes: 7 additions & 3 deletions internal/api/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ func (s *Api) downloadHandler(sconn *server.SyncConn, pool *server.Pool, body js
return common.UPDATE_DOWNLOAD, nil, err
}
var (
d *warplib.Downloader
err error
d *warplib.Downloader
)
d, err = warplib.NewDownloader(s.client, m.Url, &warplib.DownloaderOpts{
url, err := s.elEngine.Extract(m.Url)
if err != nil {
s.log.Printf("failed to extract URL from extension: %s\n", err.Error())
url = m.Url
}
d, err = warplib.NewDownloader(s.client, url, &warplib.DownloaderOpts{
Headers: m.Headers,
ForceParts: m.ForceParts,
FileName: m.FileName,
Expand Down
5 changes: 4 additions & 1 deletion internal/extloader/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (e *Engine) Extract(url string) (string, error) {
}
}
}
return url, ErrNoMatchFound
// not able to find out any actual usecase of this error
// so commenting out for now.
// return url, ErrNoMatchFound
return url, nil
}

func (e *Engine) Save() error {
Expand Down

0 comments on commit 183e247

Please sign in to comment.