Skip to content

Commit

Permalink
feat: add rootpath filepath publicread
Browse files Browse the repository at this point in the history
  • Loading branch information
saltbo committed Jan 25, 2021
1 parent 2cf030b commit 3de132e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
30 changes: 16 additions & 14 deletions model/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ const (
)

type Storage struct {
Id int64 `json:"id"`
Mode int8 `json:"mode" gorm:"size:16;not null"`
Name string `json:"name" gorm:"size:16;not null"`
Title string `json:"title" gorm:"size:16;not null"`
Bucket string `json:"bucket" gorm:"size:32;not null"`
Provider string `json:"provider" gorm:"size:8;not null"`
Endpoint string `json:"endpoint" gorm:"size:128;not null"`
AccessKey string `json:"access_key" gorm:"size:64;not null"`
SecretKey string `json:"secret_key" gorm:"size:64;not null"`
CustomHost string `json:"custom_host" gorm:"size:128;not null"`
ObjectPattern string `json:"object_pattern" gorm:"size:64;not null"`
Created time.Time `json:"created" gorm:"column:created_at;not null"`
Updated time.Time `json:"updated" gorm:"column:updated_at;not null"`
Deleted *time.Time `json:"-" gorm:"column:deleted_at"`
Id int64 `json:"id"`
Mode int8 `json:"mode" gorm:"size:16;not null"`
Name string `json:"name" gorm:"size:16;not null"`
Title string `json:"title" gorm:"size:16;not null"`
Bucket string `json:"bucket" gorm:"size:32;not null"`
Provider string `json:"provider" gorm:"size:8;not null"`
Endpoint string `json:"endpoint" gorm:"size:128;not null"`
AccessKey string `json:"access_key" gorm:"size:64;not null"`
SecretKey string `json:"secret_key" gorm:"size:64;not null"`
CustomHost string `json:"custom_host" gorm:"size:128;not null"`
RootPath string `json:"root_path" gorm:"size:64;not null"`
FilePath string `json:"file_path" gorm:"size:1024;not null"`
PublicRead bool `json:"public_read" gorm:"size:1;not null"`
Created time.Time `json:"created" gorm:"column:created_at;not null"`
Updated time.Time `json:"updated" gorm:"column:updated_at;not null"`
Deleted *time.Time `json:"-" gorm:"column:deleted_at"`
}

func (Storage) TableName() string {
Expand Down
22 changes: 15 additions & 7 deletions rest/bind/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/saltbo/zpan/model"
)

var ts = strings.TrimSpace

type StorageBody struct {
Mode int8 `json:"mode" binding:"required"`
Name string `json:"name" binding:"required"`
Expand All @@ -16,19 +18,25 @@ type StorageBody struct {
AccessKey string `json:"access_key" binding:"required"`
SecretKey string `json:"secret_key" binding:"required"`
CustomHost string `json:"custom_host"`
RootPath string `json:"root_path"`
FilePath string `json:"file_path"`
PublicRead bool `json:"public_read"`
}

func (b *StorageBody) Model() *model.Storage {
return &model.Storage{
Mode: b.Mode,
Name: strings.TrimSpace(b.Name),
Title: strings.TrimSpace(b.Title),
Bucket: strings.TrimSpace(b.Bucket),
Name: ts(b.Name),
Title: ts(b.Title),
Bucket: ts(b.Bucket),
Provider: b.Provider,
Endpoint: strings.TrimSpace(b.Endpoint),
CustomHost: strings.TrimSpace(b.CustomHost),
AccessKey: strings.TrimSpace(b.AccessKey),
SecretKey: strings.TrimSpace(b.SecretKey),
Endpoint: ts(b.Endpoint),
CustomHost: ts(b.CustomHost),
AccessKey: ts(b.AccessKey),
SecretKey: ts(b.SecretKey),
RootPath: ts(b.RootPath),
FilePath: ts(b.FilePath),
PublicRead: b.PublicRead,
}
}

Expand Down

0 comments on commit 3de132e

Please sign in to comment.