Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
50 lines
2.7 KiB
Go
50 lines
2.7 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
// DirectUploadStatus constants for the staged upload process.
|
|
type DirectUploadStatus string
|
|
|
|
const (
|
|
DirectUploadStatusPending DirectUploadStatus = "pending" // File uploaded, awaiting attachment
|
|
DirectUploadStatusCompleted DirectUploadStatus = "completed" // File attached/processed
|
|
DirectUploadStatusExpired DirectUploadStatus = "expired" // Upload expired
|
|
)
|
|
|
|
// DirectUploadSource constants for the upload source.
|
|
type DirectUploadSource string
|
|
|
|
const (
|
|
DirectUploadSourceAccount DirectUploadSource = "account" // Account-level upload (dashboard agent)
|
|
DirectUploadSourceWidget DirectUploadSource = "widget" // Widget direct upload (visitor)
|
|
)
|
|
|
|
// DirectUpload stores metadata about a file uploaded through account API or widget direct upload.
|
|
// Reference: Chatwoot api/v1/accounts/:account_id/upload + /widget/direct_uploads
|
|
// Account uploads: agent attaches file to conversation from dashboard
|
|
// Widget direct uploads: visitor uploads file directly (staged flow similar to WidgetFileUpload)
|
|
type DirectUpload struct {
|
|
Base
|
|
UploadUUID string `gorm:"size:36;uniqueIndex;not null" json:"upload_uuid"` // UUID for public-facing tracking
|
|
AccountID uint `gorm:"index;not null" json:"account_id"` // Account this upload belongs to
|
|
Status DirectUploadStatus `gorm:"size:20;default:'pending';index" json:"status"` // "pending", "completed", "expired"
|
|
Source DirectUploadSource `gorm:"size:20;not null;index" json:"source"` // "account" or "widget"
|
|
|
|
// === File metadata ===
|
|
OriginalName string `gorm:"size:255;not null" json:"original_name"` // Original filename from user
|
|
FileType string `gorm:"size:50;not null" json:"file_type"` // Category: "image", "audio", "video", "file"
|
|
MimeType string `gorm:"size:100" json:"mime_type,omitempty"` // Full MIME type (e.g. "image/png")
|
|
FileSize int64 `gorm:"not null" json:"file_size"` // File size in bytes
|
|
FileURL string `gorm:"size:512" json:"file_url,omitempty"` // URL where file is stored
|
|
ThumbURL string `gorm:"size:512" json:"thumb_url,omitempty"` // Thumbnail URL (for images)
|
|
|
|
// === Processing ===
|
|
Metadata datatypes.JSON `gorm:"type:jsonb" json:"metadata,omitempty"` // Additional metadata (checksums, etc)
|
|
ExpiresAt time.Time `gorm:"index" json:"expires_at"` // Expiry timestamp for cleanup
|
|
}
|
|
|
|
func (DirectUpload) TableName() string { return "direct_uploads" } |