Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fields and features for dedicated server support #28

Merged
merged 25 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
70f8b40
fix: update converter_windows to match linux counterpart
mircearoata May 6, 2023
ace91c3
feat: validate multi-target plugin, detect targets and plugin type
mircearoata May 8, 2023
4bdfce8
fix: keep the original uploaded file, remove "combined" arch
mircearoata May 8, 2023
022aeed
refactor: separate ModArch creation from storage
mircearoata May 8, 2023
40ca1d0
chore: rename all "arch/platform" consistently, remove ID from Versio…
mircearoata May 8, 2023
0e7f9a5
feat: backwards compatibility for Version fields Link, Hash and Size
mircearoata May 8, 2023
d33815d
chore: lint
mircearoata May 8, 2023
e5a8fd5
fix: update a missed target->target_name
mircearoata May 11, 2023
1925d55
chore: update more missed link->target
mircearoata May 11, 2023
cc9bc62
feat: VirusTotal parallelization
porisius May 29, 2023
a042c4d
chore: rename WindowsNoEditor to Windows
mircearoata Aug 19, 2023
66ee7db
fix: don't automatically preload version targets
mircearoata Aug 20, 2023
2eb0263
chore: simplify Version.Link resolver
mircearoata Aug 20, 2023
9bd70d2
feat: return error message when uploading legacy mod formats
mircearoata Aug 20, 2023
24c46ee
feat: enum for TargetName
mircearoata Aug 19, 2023
ecf604a
fix: delete SML version targets when removed
mircearoata Aug 19, 2023
7d39754
chore: lint
mircearoata Aug 20, 2023
6d7c4f3
feat: migrate existing mods to use targets
mircearoata Aug 20, 2023
295fa9f
fix: skip migrating versions that already have targets
mircearoata Aug 21, 2023
1c4ce32
chore: remove some debug code
mircearoata Aug 21, 2023
4a45e6e
chore: temporarily require single-target format
mircearoata Sep 19, 2023
b9ca8cf
feat: new metadata parser, sml engine versions, minimal mod version R…
Vilsol Oct 19, 2023
c13a52b
chore: reorder go generate steps
Vilsol Oct 19, 2023
5505067
chore: download protoc dependencies
Vilsol Oct 19, 2023
86bc1f8
chore: field alignment
Vilsol Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
16 changes: 13 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
uses: actions/checkout@v3

- name: Download dependencies
run: sudo apt update && sudo apt install -y build-essential libpng-dev
run: |
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]

- name: Go Generate
run: go generate -tags tools -x ./...
Expand All @@ -39,14 +42,18 @@ jobs:
uses: actions/checkout@v3

- name: Download dependencies
run: sudo apt update && sudo apt install -y build-essential libpng-dev
run: |
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]

- name: Go Generate
run: go generate -tags tools -x ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0
skip-pkg-cache: true
skip-build-cache: true
args: --timeout 5m
Expand All @@ -64,7 +71,10 @@ jobs:
uses: actions/checkout@v3

- name: Download dependencies
run: sudo apt update && sudo apt install -y build-essential libpng-dev
run: |
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]

- name: Go Generate
run: go generate -tags tools -x ./...
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ jobs:
fetch-depth: 0

- name: Download dependencies
run: sudo apt update && sudo apt install -y build-essential libpng-dev
run: |
sudo apt update && sudo apt install -y build-essential libpng-dev protobuf-compiler
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM golang:1.18-alpine AS builder
FROM golang:1.19-alpine3.18 AS builder

RUN apk add --no-cache git build-base libpng-dev
RUN apk add --no-cache git build-base libpng-dev protoc
RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN go install google.golang.org/grpc/cmd/[email protected]

WORKDIR $GOPATH/src/github.com/satisfactorymodding/smr-api/

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ Main configuration options:

The config format can be seen in `config/config.go` (each dot means a new level of nesting).

After startup requires the following minio commands to be executed:

```shell
mc alias set local http://localhost:9000 minio minio123
mc admin user svcacct add local minio --access-key REPLACE_ME_KEY --secret-key REPLACE_ME_SECRET
mc anonymous set public local/smr
```

## Contributing

Before contributing, please run the [linter](https://golangci-lint.run/) to ensure the code is clean and well-formed:
Expand Down
7 changes: 6 additions & 1 deletion config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"key": "REPLACE_ME_KEY",
"secret": "REPLACE_ME_SECRET",
"endpoint": "http://localhost:9000",
"base_url": "http://localhost:9000"
"base_url": "http://localhost:9000",
"keypath": "%s/%s/%s"
},

"oauth": {
Expand All @@ -52,5 +53,9 @@

"frontend": {
"url": "http://localhost:4200"
},

"feature_flags": {
"allow_multi_target_upload": false
}
}
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ func initializeDefaults() {
viper.SetDefault("frontend.url", "")

viper.SetDefault("virustotal.key", "")

viper.SetDefault("feature_flags.allow_multi_target_upload", false)
}
4 changes: 2 additions & 2 deletions dataloader/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func Middleware() func(handlerFunc echo.HandlerFunc) echo.HandlerFunc {

var entities []postgres.Version
reqCtx := c.Request().Context()
postgres.DBCtx(reqCtx).Preload("Arch").Where("approved = ? AND denied = ? AND mod_id IN ?", true, false, fetchIds).Order("created_at desc").Find(&entities)
postgres.DBCtx(reqCtx).Preload("Targets").Where("approved = ? AND denied = ? AND mod_id IN ?", true, false, fetchIds).Order("created_at desc").Find(&entities)

for _, entity := range entities {
byID[entity.ModID] = append(byID[entity.ModID], entity)
Expand Down Expand Up @@ -145,7 +145,7 @@ func Middleware() func(handlerFunc echo.HandlerFunc) echo.HandlerFunc {

var entities []postgres.Version
reqCtx := c.Request().Context()
postgres.DBCtx(reqCtx).Preload("Arch").Select(
postgres.DBCtx(reqCtx).Preload("Targets").Select(
"id",
"created_at",
"updated_at",
Expand Down
8 changes: 4 additions & 4 deletions db/postgres/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetModByID(ctx context.Context, modID string) *Mod {

func GetModByIDNoCache(ctx context.Context, modID string) *Mod {
var mod Mod
DBCtx(ctx).Preload("Tags").Preload("Versions.Arch").Find(&mod, "id = ?", modID)
DBCtx(ctx).Preload("Tags").Preload("Versions.Targets").Find(&mod, "id = ?", modID)

if mod.ID == "" {
return nil
Expand All @@ -44,7 +44,7 @@ func GetModByReference(ctx context.Context, modReference string) *Mod {
}

var mod Mod
DBCtx(ctx).Preload("Tags").Preload("Versions.Arch").Find(&mod, "mod_reference = ?", modReference)
DBCtx(ctx).Preload("Tags").Preload("Versions.Targets").Find(&mod, "mod_reference = ?", modReference)

if mod.ID == "" {
return nil
Expand Down Expand Up @@ -213,7 +213,7 @@ func NewModQuery(ctx context.Context, filter *models.ModFilter, unapproved bool,
}

query = query.Where("approved = ? AND denied = ?", !unapproved, false)
query = query.Preload("Tags").Preload("Versions.Arch")
query = query.Preload("Tags").Preload("Versions.Targets")
if filter != nil {
if filter.Search != nil && *filter.Search != "" {
cleanSearch := strings.ReplaceAll(strings.TrimSpace(*filter.Search), " ", " & ")
Expand Down Expand Up @@ -270,7 +270,7 @@ func GetModByIDOrReference(ctx context.Context, modIDOrReference string) *Mod {
}

var mod Mod
DBCtx(ctx).Preload("Tags").Preload("Versions.Arch").Find(&mod, "mod_reference = ? OR id = ?", modIDOrReference, modIDOrReference)
DBCtx(ctx).Preload("Tags").Preload("Versions.Targets").Find(&mod, "mod_reference = ? OR id = ?", modIDOrReference, modIDOrReference)

if mod.ID == "" {
return nil
Expand Down
122 changes: 0 additions & 122 deletions db/postgres/mod_archs.go

This file was deleted.

49 changes: 27 additions & 22 deletions db/postgres/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,27 @@ type Version struct {
SMLVersion string `gorm:"type:varchar(16)"`
Version string `gorm:"type:varchar(16)"`
ModID string
Arch []ModArch `gorm:"foreignKey:ModVersionID;preload:true"`
Targets []VersionTarget `gorm:"foreignKey:VersionID"`
Hotness uint
Downloads uint
Denied bool `gorm:"default:false;not null"`
Approved bool `gorm:"default:false;not null"`
}

type TinyVersion struct {
Hash *string
Size *int64
SMRModel
SMLVersion string `gorm:"type:varchar(16)"`
Version string `gorm:"type:varchar(16)"`
Targets []VersionTarget `gorm:"foreignKey:VersionID;preload:true"`
Dependencies []VersionDependency `gorm:"foreignKey:VersionID"`
}

func (TinyVersion) TableName() string {
return "versions"
}

type Guide struct {
SMRModel
Name string `gorm:"type:varchar(50)"`
Expand All @@ -120,7 +134,8 @@ type SMLVersion struct {
Stability string `sql:"type:version_stability"`
Link string
Changelog string
Arch []SMLArch `gorm:"foreignKey:SMLVersionID;preload:true"`
EngineVersion string
Targets []SMLVersionTarget `gorm:"foreignKey:VersionID"`
SatisfactoryVersion int
}

Expand Down Expand Up @@ -179,26 +194,16 @@ type Compatibility struct {
Note string
}

type ModArch struct {
ID string `gorm:"primary_key;type:varchar(16)"`
ModVersionID string `gorm:"column:mod_version_arch_id"`
Platform string
Key string
Hash string
Size int64
}

func (ModArch) TableName() string {
return "mod_archs"
}

type SMLArch struct {
ID string `gorm:"primary_key;type:varchar(14)"`
SMLVersionID string `gorm:"column:sml_version_arch_id"`
Platform string
Link string
type VersionTarget struct {
VersionID string `gorm:"primary_key;type:varchar(14)"`
TargetName string `gorm:"primary_key;type:varchar(16)"`
Key string
Hash string
Size int64
}

func (SMLArch) TableName() string {
return "sml_archs"
type SMLVersionTarget struct {
VersionID string `gorm:"primary_key;type:varchar(14)"`
TargetName string `gorm:"primary_key;type:varchar(16)"`
Link string
}
Loading
Loading