Skip to content

Commit

Permalink
Merge pull request #2 from imLinguin/hgrid_type
Browse files Browse the repository at this point in the history
add horizontal grid type
  • Loading branch information
mirkobrombin authored Aug 9, 2023
2 parents 9a70a40 + b94f6cc commit a677fbf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a677fbf

Please sign in to comment.