feat: implementar webapp app_compartir con visor universal, auth y purga 24h para guest
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Provider string `json:"provider"` // "webcontrol" | "google"
|
||||
ProviderID string `json:"provider_id"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
Token string `json:"token"`
|
||||
UserID *string `json:"user_id"`
|
||||
IsGuest bool `json:"is_guest"`
|
||||
GuestID string `json:"guest_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
User *User `json:"user,omitempty"`
|
||||
}
|
||||
|
||||
type Share struct {
|
||||
ID string `json:"id"`
|
||||
UserID *string `json:"user_id"`
|
||||
UserDisplay string `json:"user_display"`
|
||||
IsGuest bool `json:"is_guest"`
|
||||
Type string `json:"type"` // "file" | "text"
|
||||
Title string `json:"title"`
|
||||
StoredPath string `json:"stored_path"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
MimeType string `json:"mime_type"`
|
||||
TextContent string `json:"text_content"`
|
||||
ViewsCount int `json:"views_count"`
|
||||
DownloadsCount int `json:"downloads_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt *time.Time `json:"expires_at"` // NULL si registrado, NOW+24h si guest
|
||||
}
|
||||
|
||||
func (s *Share) FormattedSize() string {
|
||||
if s.FileSize == 0 {
|
||||
return "0 B"
|
||||
}
|
||||
const unit = 1024
|
||||
if s.FileSize < unit {
|
||||
return fmt.Sprintf("%d B", s.FileSize)
|
||||
}
|
||||
div, exp := int64(unit), 0
|
||||
for n := s.FileSize / unit; n >= unit; n /= unit {
|
||||
div *= unit
|
||||
exp++
|
||||
}
|
||||
units := []string{"KB", "MB", "GB", "TB"}
|
||||
return fmt.Sprintf("%.1f %s", float64(s.FileSize)/float64(div), units[exp])
|
||||
}
|
||||
Reference in New Issue
Block a user