31 lines
849 B
Go
31 lines
849 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// CloudFileShare stores a temporary share link for a file
|
|
type CloudFileShare struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
|
FileID uuid.UUID `gorm:"type:uuid;not null" json:"file_id"`
|
|
Token string `gorm:"size:64;not null;uniqueIndex" json:"token"`
|
|
Permissions string `gorm:"size:20;not null;default:'read'" json:"permissions"`
|
|
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
|
|
File *UserFile `gorm:"foreignKey:FileID;constraint:OnDelete:CASCADE" json:"-"`
|
|
}
|
|
|
|
func (CloudFileShare) TableName() string {
|
|
return "cloud_file_shares"
|
|
}
|
|
|
|
func (m *CloudFileShare) BeforeCreate(tx *gorm.DB) error {
|
|
if m.ID == uuid.Nil {
|
|
m.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|