From b2afa04e57e84f8d204eca593498471d0a6c8848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Wed, 26 Jul 2023 14:04:12 +0200 Subject: [PATCH 1/2] feat: add horizotal grid type as hgrid --- config/utils.go | 8 +++++++- proxy/client.go | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config/utils.go b/config/utils.go index 6f3d548..131b0d6 100644 --- a/config/utils.go +++ b/config/utils.go @@ -17,7 +17,7 @@ type Config struct { var Cnf *Config var ProcessPath string -var ImageTypes []string = []string{"grids", "heroes", "logos", "icons"} +var ImageTypes []string = []string{"grids", "hgrids", "heroes", "logos", "icons"} func IsValidImageType(imageType string) bool { for _, v := range ImageTypes { @@ -54,6 +54,12 @@ func init() { path := "cache" + if _, err := os.Stat(filepath.Join(ProcessPath, path)); errors.Is(err, os.ErrNotExist) { + err := os.Mkdir(filepath.Join(ProcessPath, path), os.ModePerm) + if err != nil { + log.Println(err) + } + } for _, imageType := range ImageTypes { if _, err := os.Stat(filepath.Join(ProcessPath, path, imageType)); errors.Is(err, os.ErrNotExist) { err := os.Mkdir(filepath.Join(ProcessPath, path, imageType), os.ModePerm) diff --git a/proxy/client.go b/proxy/client.go index bdc7b02..4f791de 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -36,6 +36,7 @@ type GridData struct { const BASE_URL = "https://www.steamgriddb.com/api/v2" const GRID_DIMENSIONS = "dimensions=600x900" +const HGRID_DIMENSIONS = "dimensions=920x430" const HERO_DIMENSIONS = "dimensions=1920x620" func callAPI(e string, t string, p string) (r *http.Response, err error) { @@ -78,11 +79,18 @@ func Search(t string, s string) (m string, err error) { if s == "heroes" { dimensions = HERO_DIMENSIONS + } else if s == "hgrids" { + dimensions = HGRID_DIMENSIONS } else if s != "grids" { dimensions = "styles=official" } - res, err := callAPI(fmt.Sprintf("/%s/game/", s), fmt.Sprint(searchResponse.Data[0].Id), dimensions) + var itype string = s + if itype == "hgrids" { + itype = "grids" + } + + res, err := callAPI(fmt.Sprintf("/%s/game/", itype), fmt.Sprint(searchResponse.Data[0].Id), dimensions) if err != nil { return "", err From b94f6cc57bb377ba573ae40c32a4b081b8bcc894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Wed, 26 Jul 2023 14:28:50 +0200 Subject: [PATCH 2/2] add readme --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2912dc --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# steamgrid-proxy + +## Building +Assuming you have `go` installed, run following command in root directory of the project + +``` +go build +``` + +Setup config.json file + +``` +cp config/config.example.json config/config.json +``` + +Modify `config/config.json` accordingly +You can generate API key [here](https://www.steamgriddb.com/profile/preferences/api) + +Image URLs are cached in `cache` directory in subdirectories based on image type + +Run the server + +``` +./steamgrid-proxy +``` + +## API + +``` +/api/search/GAME TITLE/IMAGE_TYPE +``` + +`GAME TITLE` - title of a game you are looking for +`IMAGE_TYPE` - (optional default - grids) + + +## Supported image types + +- grids +- hgrids +- heroes +- logos +- icons