feat: implement ufile sharing service
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
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"`
|
||||
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:"-"`
|
||||
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"`
|
||||
HasPickupCode bool `json:"hasPickupCode"`
|
||||
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, HasPickupCode: f.HasPickupCode(), CreatedAt: f.CreatedAt,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user