diff --git a/oa/api/app/app.go b/oa/api/app/app.go index 45a9ea6..bd4730f 100644 --- a/oa/api/app/app.go +++ b/oa/api/app/app.go @@ -4,10 +4,9 @@ import ( "oa/cfg" "oa/libs/auth" M "oa/models" - "strings" - "github.com/google/uuid" "github.com/veypi/OneBD/rest" + "gorm.io/gorm" ) func useApp(r rest.Router) { @@ -52,7 +51,7 @@ func appList(x *rest.X) (any, error) { UserStatus string `json:"user_status"` }, 0, 10) - query := cfg.DB().Debug().Table("apps").Select("apps.*,app_users.status user_status") + query := cfg.DB().Table("apps").Select("apps.*,app_users.status user_status") uid := x.Request.Context().Value("uid").(string) if opts.Name != nil { query = query.Joins("LEFT JOIN app_users ON app_users.app_id = apps.id AND app_users.user_id = ? AND apps.name LIKE ?", uid, opts.Name) @@ -108,12 +107,24 @@ func appPost(x *rest.X) (any, error) { } data := &M.App{} - data.ID = strings.ReplaceAll(uuid.New().String(), "-", "") data.Name = opts.Name data.Icon = opts.Icon - data.Des = opts.Des data.Typ = opts.Typ - err = cfg.DB().Create(data).Error + if opts.Des != nil { + data.Des = *opts.Des + } + err = cfg.DB().Transaction(func(tx *gorm.DB) error { + err := tx.Create(data).Error + if err != nil { + return err + } + au := &M.AppUser{ + AppID: data.ID, + UserID: x.Request.Context().Value("uid").(string), + Status: M.AUSTATUS_OK, + } + return tx.Create(au).Error + }) return data, err } diff --git a/oa/models/app.gen.go b/oa/models/app.gen.go index 5da2484..27aa4a0 100644 --- a/oa/models/app.gen.go +++ b/oa/models/app.gen.go @@ -21,11 +21,11 @@ type AppDelete struct { } type AppPost struct { - Name string `json:"name" parse:"json"` - Icon string `json:"icon" parse:"json"` - Des string `json:"des" parse:"json"` - Typ string `json:"typ" gorm:"default:auto" parse:"json"` - Status string `json:"status" gorm:"default:ok" parse:"json"` + Name string `json:"name" parse:"json"` + Icon string `json:"icon" parse:"json"` + Des *string `json:"des" parse:"json"` + Typ string `json:"typ" gorm:"default:auto" parse:"json"` + Status string `json:"status" gorm:"default:ok" parse:"json"` } type AppList struct { diff --git a/oa/models/app.go b/oa/models/app.go index 8fecf97..6ca2d43 100644 --- a/oa/models/app.go +++ b/oa/models/app.go @@ -5,11 +5,16 @@ import ( "gorm.io/gorm" ) +const AUSTATUS_OK = "ok" +const AUSTATUS_NO = "no" +const AUSTATUS_APPLYING = "applying" +const AUSTATUS_REJECT = "reject" + type App struct { BaseModel Name string `json:"name" methods:"post,*patch,*list" parse:"json"` Icon string `json:"icon" methods:"post,*patch" parse:"json"` - Des string `json:"des" methods:"post,*patch" parse:"json"` + Des string `json:"des" methods:"*post,*patch" parse:"json"` Typ string `json:"typ" gorm:"default:public" methods:"post,*patch" parse:"json"` Status string `json:"status" gorm:"default:ok" methods:"post,*patch" parse:"json"` InitRoleID *string `json:"init_role_id" gorm:"index;type:varchar(32);default: null" methods:"*patch" parse:"json"` @@ -49,14 +54,14 @@ func (m *AppUser) onOk(tx *gorm.DB) (err error) { } func (m *AppUser) AfterCreate(tx *gorm.DB) error { - if m.Status == "ok" { + if m.Status == AUSTATUS_OK { logv.AssertError(m.onOk(tx)) } return tx.Model(&App{}).Where("id = ?", m.AppID).Update("user_count", gorm.Expr("user_count + ?", 1)).Error } func (m *AppUser) AfterUpdate(tx *gorm.DB) error { - if m.Status == "ok" { + if m.Status == AUSTATUS_OK { return m.onOk(tx) } return nil diff --git a/oaer/lib/fs.ts b/oaer/lib/fs.ts index cd80167..6fd81a9 100644 --- a/oaer/lib/fs.ts +++ b/oaer/lib/fs.ts @@ -49,7 +49,7 @@ class davWraper { } } } - putFileContents(filename: string, data: string, options?: webdav.PutFileContentsOptions) { + putFileContents(filename: string, data: string | webdav.BufferLike, options?: webdav.PutFileContentsOptions) { return this.retry(() => this.client.putFileContents(filename, data, options)) } getFileContents(filename: string, options?: webdav.GetFileContentsOptions) { @@ -118,8 +118,8 @@ const rename = (o: string, n?: string) => { if (n) { return n + ext } - let d = new Date().getTime() - return d + o + ext + const d = performance.now().toString(36); + return d + ext } diff --git a/oaweb/app.config.ts b/oaweb/app.config.ts index b7cbb56..f9dfb20 100644 --- a/oaweb/app.config.ts +++ b/oaweb/app.config.ts @@ -8,6 +8,10 @@ export default defineAppConfig({ // host: window.location.protocol + '//' + window.location.host, + ui: { + // primary: '#2196f3', + // gray: '#111' + }, host: '', id: 'tMRxWz77P9ABNZA3ZIuoNQILjVBBIUdf', layout: { diff --git a/oaweb/app.vue b/oaweb/app.vue index b7affe2..80621f9 100644 --- a/oaweb/app.vue +++ b/oaweb/app.vue @@ -1,11 +1,9 @@