Redmage/api/download_subreddit_images.go

36 lines
919 B
Go
Raw Normal View History

2024-04-09 22:37:26 +07:00
package api
import (
"context"
"errors"
2024-04-10 17:13:07 +07:00
"net/http"
"github.com/tigorlazuardi/redmage/db/queries"
"github.com/tigorlazuardi/redmage/pkg/errs"
)
2024-04-09 22:37:26 +07:00
type DownloadSubredditParams struct {
Countback int
NSFW bool
Devices []queries.Device
2024-04-10 17:13:07 +07:00
Type int
2024-04-09 22:37:26 +07:00
}
var (
2024-04-10 17:13:07 +07:00
ErrNoDevices = errors.New("api: no devices set")
ErrDownloadDirNotSet = errors.New("api: download directory not set")
)
2024-04-09 22:37:26 +07:00
func (api *API) DownloadSubredditImages(ctx context.Context, subredditName string, params DownloadSubredditParams) error {
2024-04-10 17:13:07 +07:00
downloadDir := api.config.String("download.directory")
if downloadDir == "" {
return errs.Wrapw(ErrDownloadDirNotSet, "download directory must be set before images can be downloaded").Code(http.StatusBadRequest)
}
if len(params.Devices) == 0 {
2024-04-10 17:13:07 +07:00
return errs.Wrapw(ErrNoDevices, "downloading images requires at least one device configured").Code(http.StatusBadRequest)
}
2024-04-10 17:13:07 +07:00
2024-04-09 22:37:26 +07:00
return nil
}