diff --git a/pkg/internal/models/release.go b/pkg/internal/models/release.go index 35f044e..2511d02 100644 --- a/pkg/internal/models/release.go +++ b/pkg/internal/models/release.go @@ -15,10 +15,11 @@ const ( type ProductRelease struct { cruda.BaseModel - Version string `json:"version"` - Type ProductReleaseType `json:"type"` - Channel string `json:"channel"` - Assets datatypes.JSONType[map[string]any] `json:"assets"` + Version string `json:"version"` + Type ProductReleaseType `json:"type"` + Channel string `json:"channel"` + Assets datatypes.JSONType[map[string]ReleaseAsset] `json:"assets"` + Installers datatypes.JSONType[map[string]ReleaseInstaller] `json:"installers"` ProductID uint `json:"product_id"` Meta ProductReleaseMeta `json:"meta" gorm:"foreignKey:ReleaseID"` @@ -33,3 +34,19 @@ type ProductReleaseMeta struct { Attachments datatypes.JSONSlice[string] `json:"attachments"` ReleaseID uint `json:"release_id"` } + +type ReleaseAsset struct { + URI string `json:"uri" validate:"required"` + ContentType string `json:"content_type" validate:"required"` +} + +type ReleaseInstaller struct { + Workdir string `json:"workdir"` + Script string `json:"script"` + Patches []ReleaseInstallerPatch `json:"patches"` +} + +type ReleaseInstallerPatch struct { + Action string `json:"action" validate:"required"` + Glob string `json:"glob" validate:"required"` +} diff --git a/pkg/internal/server/api/releases_api.go b/pkg/internal/server/api/releases_api.go index 00d65cf..6f16041 100644 --- a/pkg/internal/server/api/releases_api.go +++ b/pkg/internal/server/api/releases_api.go @@ -50,14 +50,15 @@ func createRelease(c *fiber.Ctx) error { productId, _ := c.ParamsInt("productId", 0) var data struct { - Version string `json:"version" validate:"required"` - Type int `json:"type"` - Channel string `json:"channel" validate:"required"` - Title string `json:"title" validate:"required,max=1024"` - Description string `json:"description" validate:"required,max=4096"` - Content string `json:"content" validate:"required"` - Assets map[string]any `json:"assets" validate:"required"` - Attachments []string `json:"attachments"` + Version string `json:"version" validate:"required"` + Type int `json:"type"` + Channel string `json:"channel" validate:"required"` + Title string `json:"title" validate:"required,max=1024"` + Description string `json:"description" validate:"required,max=4096"` + Content string `json:"content" validate:"required"` + Assets map[string]models.ReleaseAsset `json:"assets" validate:"required"` + Installers map[string]models.ReleaseInstaller `json:"installers" validate:"required"` + Attachments []string `json:"attachments"` } if err := exts.BindAndValidate(c, &data); err != nil { @@ -70,11 +71,12 @@ func createRelease(c *fiber.Ctx) error { } release := models.ProductRelease{ - Version: data.Version, - Type: models.ProductReleaseType(data.Type), - Channel: data.Channel, - Assets: datatypes.NewJSONType(data.Assets), - ProductID: product.ID, + Version: data.Version, + Type: models.ProductReleaseType(data.Type), + Channel: data.Channel, + Assets: datatypes.NewJSONType(data.Assets), + Installers: datatypes.NewJSONType(data.Installers), + ProductID: product.ID, Meta: models.ProductReleaseMeta{ Title: data.Title, Description: data.Description, @@ -100,14 +102,15 @@ func updateRelease(c *fiber.Ctx) error { id, _ := c.ParamsInt("releaseId", 0) var data struct { - Version string `json:"version" validate:"required"` - Type int `json:"type"` - Channel string `json:"channel" validate:"required"` - Title string `json:"title" validate:"required,max=1024"` - Description string `json:"description" validate:"required,max=4096"` - Content string `json:"content" validate:"required"` - Assets map[string]any `json:"assets" validate:"required"` - Attachments []string `json:"attachments"` + Version string `json:"version" validate:"required"` + Type int `json:"type"` + Channel string `json:"channel" validate:"required"` + Title string `json:"title" validate:"required,max=1024"` + Description string `json:"description" validate:"required,max=4096"` + Content string `json:"content" validate:"required"` + Assets map[string]models.ReleaseAsset `json:"assets" validate:"required"` + Installers map[string]models.ReleaseInstaller `json:"installers" validate:"required"` + Attachments []string `json:"attachments"` } if err := exts.BindAndValidate(c, &data); err != nil { @@ -128,6 +131,7 @@ func updateRelease(c *fiber.Ctx) error { release.Type = models.ProductReleaseType(data.Type) release.Channel = data.Channel release.Assets = datatypes.NewJSONType(data.Assets) + release.Installers = datatypes.NewJSONType(data.Installers) release.Meta.Title = data.Title release.Meta.Description = data.Description release.Meta.Content = data.Content