mirror of
https://git.fightbot.fun/hxuanyu/FileRelay.git
synced 2026-02-15 14:41:42 +08:00
Initial commit
This commit is contained in:
11
internal/model/admin.go
Normal file
11
internal/model/admin.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// AdminSession 管理员会话信息 (不再存库,仅用于 JWT 或 API 交互)
|
||||
type AdminSession struct {
|
||||
ID uint `json:"id"`
|
||||
LastLogin *time.Time `json:"last_login"`
|
||||
}
|
||||
22
internal/model/api_token.go
Normal file
22
internal/model/api_token.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ScopeUpload = "upload" // 上传权限
|
||||
ScopePickup = "pickup" // 取件/下载权限
|
||||
ScopeAdmin = "admin" // 管理权限
|
||||
)
|
||||
|
||||
type APIToken struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `json:"name"`
|
||||
TokenHash string `gorm:"uniqueIndex;not null" json:"-"`
|
||||
Scope string `json:"scope"`
|
||||
ExpireAt *time.Time `json:"expire_at"`
|
||||
LastUsedAt *time.Time `json:"last_used_at"`
|
||||
Revoked bool `gorm:"default:false" json:"revoked"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
24
internal/model/file_batch.go
Normal file
24
internal/model/file_batch.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FileBatch struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(36)" json:"id"`
|
||||
PickupCode string `gorm:"uniqueIndex;not null" json:"pickup_code"`
|
||||
Remark string `json:"remark"`
|
||||
ExpireType string `json:"expire_type"` // time / download / permanent
|
||||
ExpireAt *time.Time `json:"expire_at"`
|
||||
MaxDownloads int `json:"max_downloads"`
|
||||
DownloadCount int `gorm:"default:0" json:"download_count"`
|
||||
Status string `gorm:"default:'active'" json:"status"` // active / expired / deleted
|
||||
Type string `gorm:"default:'file'" json:"type"` // file / text
|
||||
Content string `json:"content,omitempty"`
|
||||
FileItems []FileItem `gorm:"foreignKey:BatchID" json:"file_items,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
16
internal/model/file_item.go
Normal file
16
internal/model/file_item.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type FileItem struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(36)" json:"id"`
|
||||
BatchID string `gorm:"index;not null;type:varchar(36)" json:"batch_id"`
|
||||
OriginalName string `json:"original_name"`
|
||||
StoragePath string `json:"storage_path"`
|
||||
Size int64 `json:"size"`
|
||||
MimeType string `json:"mime_type"`
|
||||
DownloadURL string `gorm:"-" json:"download_url,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
46
internal/model/response.go
Normal file
46
internal/model/response.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
// Response 统一响应模型
|
||||
type Response struct {
|
||||
Code int `json:"code" example:"200"`
|
||||
Msg string `json:"msg" example:"success"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// 错误码定义
|
||||
const (
|
||||
CodeSuccess = 200
|
||||
CodeBadRequest = 400
|
||||
CodeUnauthorized = 401
|
||||
CodeForbidden = 403
|
||||
CodeNotFound = 404
|
||||
CodeGone = 410
|
||||
CodeInternalError = 500
|
||||
CodeTooManyRequests = 429
|
||||
)
|
||||
|
||||
// NewResponse 创建响应
|
||||
func NewResponse(code int, msg string, data interface{}) Response {
|
||||
return Response{
|
||||
Code: code,
|
||||
Msg: msg,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// SuccessResponse 成功响应
|
||||
func SuccessResponse(data interface{}) Response {
|
||||
return Response{
|
||||
Code: CodeSuccess,
|
||||
Msg: "success",
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorResponse 错误响应
|
||||
func ErrorResponse(code int, msg string) Response {
|
||||
return Response{
|
||||
Code: code,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user