Files
loveuer 3907410354
Release / deploy (push) Successful in 2m26s
feat: add file management and branding
2026-09-10 20:40:57 -07:00

68 lines
2.8 KiB
Go

package main
import "time"
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"uniqueIndex;size:32;not null" json:"username"`
PasswordHash string `json:"-"`
CanManageUsers bool `json:"canManageUsers"`
CanManageFiles bool `json:"canManageFiles"`
CanUpload bool `json:"canUpload"`
CanAdvancedUpload bool `json:"canAdvancedUpload"`
MustChangePassword bool `json:"mustChangePassword"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type Session struct {
ID uint `gorm:"primaryKey"`
TokenHash string `gorm:"uniqueIndex;size:64;not null"`
UserID uint `gorm:"index;not null"`
ExpiresAt time.Time `gorm:"index;not null"`
CreatedAt time.Time
}
type SharedFile struct {
ID uint `gorm:"primaryKey" json:"id"`
Hash string `gorm:"uniqueIndex;size:8;not null" json:"hash"`
OriginalName string `gorm:"not null" json:"name"`
MimeType string `gorm:"not null" json:"mimeType"`
Size int64 `json:"size"`
OwnerID uint `gorm:"index;not null" json:"ownerId"`
ExpiresAt *time.Time `gorm:"index" json:"expiresAt"`
MaxDownloads *int `json:"maxDownloads"`
DownloadCount int `gorm:"not null;default:0" json:"downloadCount"`
PickupCodeHash string `json:"-"`
FailedCodeAttempts int `gorm:"not null;default:0" json:"-"`
Ready bool `gorm:"index;not null;default:false" json:"-"`
CreatedAt time.Time `json:"createdAt"`
}
func (f SharedFile) HasPickupCode() bool { return f.PickupCodeHash != "" }
type fileResponse struct {
ID uint `json:"id"`
Hash string `json:"hash"`
Name string `json:"name"`
MimeType string `json:"mimeType"`
Size int64 `json:"size"`
ExpiresAt *time.Time `json:"expiresAt"`
MaxDownloads *int `json:"maxDownloads"`
DownloadCount int `json:"downloadCount"`
OwnerID uint `json:"ownerId"`
OwnerUsername string `json:"ownerUsername,omitempty"`
HasPickupCode bool `json:"hasPickupCode"`
FailedCodeAttempts int `json:"failedCodeAttempts"`
CreatedAt time.Time `json:"createdAt"`
}
func presentFile(f SharedFile) fileResponse {
return fileResponse{
ID: f.ID, Hash: f.Hash, Name: f.OriginalName, MimeType: f.MimeType,
Size: f.Size, ExpiresAt: f.ExpiresAt, MaxDownloads: f.MaxDownloads,
DownloadCount: f.DownloadCount, OwnerID: f.OwnerID, HasPickupCode: f.HasPickupCode(),
FailedCodeAttempts: f.FailedCodeAttempts, CreatedAt: f.CreatedAt,
}
}