Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
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.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// WidgetFileUploadStatus constants for the staged upload process.
|
||||
type WidgetFileUploadStatus string
|
||||
|
||||
const (
|
||||
WidgetFileUploadStatusPending WidgetFileUploadStatus = "pending" // File uploaded, awaiting attachment to message
|
||||
WidgetFileUploadStatusAttached WidgetFileUploadStatus = "attached" // File attached to a message
|
||||
WidgetFileUploadStatusExpired WidgetFileUploadStatus = "expired" // Upload expired (not attached within timeout)
|
||||
)
|
||||
|
||||
// WidgetFileUpload stores metadata about a file uploaded through the web widget.
|
||||
// Reference: Chatwoot widget SDK file upload — attachment processing pipeline
|
||||
// Widget file uploads go through a staged process:
|
||||
// 1. Visitor selects file in widget
|
||||
// 2. File is uploaded to storage via /widget/uploads endpoint
|
||||
// 3. Upload record is created with status "pending"
|
||||
// 4. When message is sent with attachment, status changes to "attached"
|
||||
type WidgetFileUpload struct {
|
||||
Base
|
||||
UploadUUID string `gorm:"size:36;uniqueIndex;not null" json:"upload_uuid"` // UUID for public-facing tracking (website_token staging)
|
||||
WidgetToken string `gorm:"size:255;index" json:"widget_token,omitempty"` // Links to the widget session (widget_token auth)
|
||||
InboxID uint `gorm:"index;not null" json:"inbox_id"` // The inbox this upload belongs to
|
||||
ContactID uint `gorm:"index" json:"contact_id,omitempty"` // Contact who uploaded (may be 0 for anonymous)
|
||||
Status WidgetFileUploadStatus `gorm:"size:20;default:'pending';index" json:"status"` // "pending", "attached", "expired"
|
||||
|
||||
// === 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"` // MIME 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 (after upload)
|
||||
ThumbURL string `gorm:"size:512" json:"thumb_url,omitempty"` // Thumbnail URL (for images)
|
||||
|
||||
// === Dimensions (for images/videos) ===
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
|
||||
// === Processing ===
|
||||
Metadata datatypes.JSON `gorm:"type:jsonb" json:"metadata,omitempty"` // Additional metadata (checksums, etc)
|
||||
MessageID *uint `gorm:"index" json:"message_id,omitempty"` // Linked message (after attachment)
|
||||
ExpiresAt time.Time `gorm:"index" json:"expires_at"` // Expiry timestamp for cleanup
|
||||
|
||||
Inbox Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
|
||||
}
|
||||
|
||||
func (WidgetFileUpload) TableName() string { return "widget_file_uploads" }
|
||||
|
||||
// WidgetUploadAllowedTypes defines the allowed MIME types for widget uploads.
|
||||
// Reference: Chatwoot widget SDK config — allowed file types restriction
|
||||
var WidgetUploadAllowedTypes = map[string][]string{
|
||||
"image": {"image/png", "image/jpeg", "image/gif", "image/webp", "image/svg+xml"},
|
||||
"audio": {"audio/mp3", "audio/ogg", "audio/wav", "audio/webm", "audio/mpeg"},
|
||||
"video": {"video/mp4", "video/webm", "video/ogg"},
|
||||
"file": {"application/pdf", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"text/plain", "text/csv"},
|
||||
}
|
||||
|
||||
// WidgetUploadMaxSizeByType defines max file sizes per category.
|
||||
var WidgetUploadMaxSizeByType = map[string]int64{
|
||||
"image": 5 * 1024 * 1024, // 5MB for images
|
||||
"audio": 10 * 1024 * 1024, // 10MB for audio
|
||||
"video": 15 * 1024 * 1024, // 15MB for video
|
||||
"file": 10 * 1024 * 1024, // 10MB for documents
|
||||
}
|
||||
Reference in New Issue
Block a user