mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-11-14 11:45:29 +08:00
36 lines
828 B
Go
36 lines
828 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/divyam234/teldrive/utils"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type User struct {
|
|
UserId int `gorm:"type:int;primaryKey"`
|
|
Name string `gorm:"type:text"`
|
|
UserName string `gorm:"type:text"`
|
|
IsPremium bool `gorm:"type:bool"`
|
|
TgSession string `gorm:"type:text"`
|
|
UpdatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
|
|
CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
|
|
}
|
|
|
|
func (u *User) AfterCreate(tx *gorm.DB) (err error) {
|
|
//create too folder on first signIn
|
|
if u.UserId != 0 {
|
|
file := File{
|
|
Name: "root",
|
|
Type: "folder",
|
|
MimeType: "drive/folder",
|
|
Path: "/",
|
|
Depth: utils.IntPointer(0),
|
|
UserID: u.UserId,
|
|
Status: "active",
|
|
ParentID: "root",
|
|
}
|
|
tx.Model(&File{}).Create(&file)
|
|
}
|
|
return
|
|
}
|