2020-02-01 23:31:09 +00:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"time"
|
2020-03-28 14:29:17 +00:00
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
"github.com/ulule/deepcopier"
|
2020-02-01 23:31:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Account represents a remote service account for uploading, downloading or syncing media files.
|
|
|
|
type Account struct {
|
|
|
|
ID uint `gorm:"primary_key"`
|
2020-03-27 17:17:07 +00:00
|
|
|
AccName string `gorm:"type:varchar(128);"`
|
|
|
|
AccOwner string `gorm:"type:varchar(128);"`
|
|
|
|
AccURL string `gorm:"type:varbinary(512);"`
|
|
|
|
AccType string `gorm:"type:varbinary(256);"`
|
|
|
|
AccKey string `gorm:"type:varbinary(256);"`
|
|
|
|
AccUser string `gorm:"type:varbinary(256);"`
|
|
|
|
AccPass string `gorm:"type:varbinary(256);"`
|
|
|
|
AccError string `gorm:"type:varbinary(512);"`
|
2020-03-28 18:46:09 +00:00
|
|
|
AccShare bool
|
2020-03-27 17:17:07 +00:00
|
|
|
AccSync bool
|
|
|
|
RetryLimit uint
|
2020-03-28 18:46:09 +00:00
|
|
|
SharePath string `gorm:"type:varbinary(256);"`
|
|
|
|
ShareSize string `gorm:"type:varbinary(16);"`
|
|
|
|
ShareExpires uint
|
|
|
|
ShareExif bool
|
|
|
|
ShareSidecar bool
|
2020-03-27 17:17:07 +00:00
|
|
|
SyncPath string `gorm:"type:varbinary(256);"`
|
|
|
|
SyncInterval uint
|
|
|
|
SyncUpload bool
|
|
|
|
SyncDownload bool
|
|
|
|
SyncDelete bool
|
|
|
|
SyncRaw bool
|
|
|
|
SyncVideo bool
|
|
|
|
SyncSidecar bool
|
|
|
|
SyncStart sql.NullTime
|
2020-02-01 23:31:09 +00:00
|
|
|
SyncedAt sql.NullTime
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
DeletedAt *time.Time `sql:"index"`
|
|
|
|
}
|
2020-03-28 14:29:17 +00:00
|
|
|
|
|
|
|
// CreateAccount creates a new account entity in the database.
|
|
|
|
func CreateAccount(form form.Account, db *gorm.DB) (model *Account, err error) {
|
|
|
|
model = &Account{}
|
|
|
|
|
|
|
|
if err := deepcopier.Copy(&model).From(form); err != nil {
|
|
|
|
return model, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.Save(&model).Error
|
|
|
|
|
|
|
|
return model, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save updates the entity using form data and stores it in the database.
|
|
|
|
func (m *Account) Save(form form.Account, db *gorm.DB) error {
|
|
|
|
if err := deepcopier.Copy(m).From(form); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.Save(m).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete deletes the entity from the database.
|
|
|
|
func (m *Account) Delete(db *gorm.DB) error {
|
|
|
|
return db.Delete(m).Error
|
|
|
|
}
|