2021-10-11 09:18:28 +01:00
|
|
|
package thumbnail
|
|
|
|
|
|
|
|
import (
|
2022-01-03 11:21:20 +00:00
|
|
|
"go-micro.dev/v4/api/client"
|
2021-10-11 09:18:28 +01:00
|
|
|
)
|
|
|
|
|
2021-12-30 08:44:34 +00:00
|
|
|
type Thumbnail interface {
|
|
|
|
Screenshot(*ScreenshotRequest) (*ScreenshotResponse, error)
|
|
|
|
}
|
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
func NewThumbnailService(token string) *ThumbnailService {
|
|
|
|
return &ThumbnailService{
|
|
|
|
client: client.NewClient(&client.Options{
|
|
|
|
Token: token,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ThumbnailService struct {
|
|
|
|
client *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a thumbnail screenshot by passing in a url, height and width
|
|
|
|
func (t *ThumbnailService) Screenshot(request *ScreenshotRequest) (*ScreenshotResponse, error) {
|
2021-12-21 13:18:29 +00:00
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
rsp := &ScreenshotResponse{}
|
|
|
|
return rsp, t.client.Call("thumbnail", "Screenshot", request, rsp)
|
2021-12-21 13:18:29 +00:00
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ScreenshotRequest struct {
|
|
|
|
// height of the browser window, optional
|
|
|
|
Height int32 `json:"height"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
// width of the browser window. optional
|
|
|
|
Width int32 `json:"width"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ScreenshotResponse struct {
|
2021-12-21 13:18:29 +00:00
|
|
|
ImageUrl string `json:"imageURL"`
|
2021-10-11 09:18:28 +01:00
|
|
|
}
|