Skip to content

Commit a677fbf

Browse files
author
Mirko Brombin
authored
Merge pull request #2 from imLinguin/hgrid_type
add horizontal grid type
2 parents 9a70a40 + b94f6cc commit a677fbf

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# steamgrid-proxy
2+
3+
## Building
4+
Assuming you have `go` installed, run following command in root directory of the project
5+
6+
```
7+
go build
8+
```
9+
10+
Setup config.json file
11+
12+
```
13+
cp config/config.example.json config/config.json
14+
```
15+
16+
Modify `config/config.json` accordingly
17+
You can generate API key [here](https://www.steamgriddb.com/profile/preferences/api)
18+
19+
Image URLs are cached in `cache` directory in subdirectories based on image type
20+
21+
Run the server
22+
23+
```
24+
./steamgrid-proxy
25+
```
26+
27+
## API
28+
29+
```
30+
/api/search/GAME TITLE/IMAGE_TYPE
31+
```
32+
33+
`GAME TITLE` - title of a game you are looking for
34+
`IMAGE_TYPE` - (optional default - grids)
35+
36+
37+
## Supported image types
38+
39+
- grids
40+
- hgrids
41+
- heroes
42+
- logos
43+
- icons

config/utils.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Config struct {
1717

1818
var Cnf *Config
1919
var ProcessPath string
20-
var ImageTypes []string = []string{"grids", "heroes", "logos", "icons"}
20+
var ImageTypes []string = []string{"grids", "hgrids", "heroes", "logos", "icons"}
2121

2222
func IsValidImageType(imageType string) bool {
2323
for _, v := range ImageTypes {
@@ -54,6 +54,12 @@ func init() {
5454

5555
path := "cache"
5656

57+
if _, err := os.Stat(filepath.Join(ProcessPath, path)); errors.Is(err, os.ErrNotExist) {
58+
err := os.Mkdir(filepath.Join(ProcessPath, path), os.ModePerm)
59+
if err != nil {
60+
log.Println(err)
61+
}
62+
}
5763
for _, imageType := range ImageTypes {
5864
if _, err := os.Stat(filepath.Join(ProcessPath, path, imageType)); errors.Is(err, os.ErrNotExist) {
5965
err := os.Mkdir(filepath.Join(ProcessPath, path, imageType), os.ModePerm)

proxy/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type GridData struct {
3636

3737
const BASE_URL = "https://www.steamgriddb.com/api/v2"
3838
const GRID_DIMENSIONS = "dimensions=600x900"
39+
const HGRID_DIMENSIONS = "dimensions=920x430"
3940
const HERO_DIMENSIONS = "dimensions=1920x620"
4041

4142
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) {
7879

7980
if s == "heroes" {
8081
dimensions = HERO_DIMENSIONS
82+
} else if s == "hgrids" {
83+
dimensions = HGRID_DIMENSIONS
8184
} else if s != "grids" {
8285
dimensions = "styles=official"
8386
}
8487

85-
res, err := callAPI(fmt.Sprintf("/%s/game/", s), fmt.Sprint(searchResponse.Data[0].Id), dimensions)
88+
var itype string = s
89+
if itype == "hgrids" {
90+
itype = "grids"
91+
}
92+
93+
res, err := callAPI(fmt.Sprintf("/%s/game/", itype), fmt.Sprint(searchResponse.Data[0].Id), dimensions)
8694

8795
if err != nil {
8896
return "", err

0 commit comments

Comments
 (0)