Files
yt-dlp-webui/server/rest/service.go
Marco 8327d1e94c Download REST API endpoints (#72)
* backend and frontend hotfixes, see message

Improved rendering on the frontend by cutting unecessary useStates.
Backend side, downloads now auto resume even on application kill.

* download rest api endpoints, general code refactor

* download request json mappings
2023-07-31 08:30:09 +02:00

39 lines
667 B
Go

package rest
import (
"context"
"errors"
"github.com/marcopeocchi/yt-dlp-web-ui/server/internal"
)
type Service struct {
db *internal.MemoryDB
mq *internal.MessageQueue
}
func (s *Service) Exec(req internal.DownloadRequest) (string, error) {
p := &internal.Process{
Url: req.URL,
Params: req.Params,
Output: internal.DownloadOutput{
Path: req.Path,
Filename: req.Rename,
},
}
id := s.db.Set(p)
s.mq.Publish(p)
return id, nil
}
func (s *Service) Running(ctx context.Context) (*[]internal.ProcessResponse, error) {
select {
case <-ctx.Done():
return nil, errors.New("context cancelled")
default:
return s.db.All(), nil
}
}