mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
chore: update Go modules to version 1.25.5, restructure models into pkg/models, and remove unused model files for improved organization and dependency management
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
module backend
|
||||
|
||||
go 1.24.0
|
||||
|
||||
toolchain go1.24.3
|
||||
go 1.25.5
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.2
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/golang-jwt/jwt/v5 v5.3.0
|
||||
github.com/gorilla/sessions v1.4.0
|
||||
@@ -13,7 +10,7 @@ require (
|
||||
github.com/labstack/echo-contrib v0.17.4
|
||||
github.com/labstack/echo/v4 v4.13.4
|
||||
github.com/matoous/go-nanoid/v2 v2.1.0
|
||||
github.com/redis/go-redis/v9 v9.14.0
|
||||
github.com/redis/go-redis/v9 v9.17.2
|
||||
github.com/samber/lo v1.51.0
|
||||
github.com/spf13/cast v1.10.0
|
||||
github.com/spf13/viper v1.21.0
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
|
||||
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
@@ -54,8 +52,8 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/redis/go-redis/v9 v9.14.0 h1:u4tNCjXOyzfgeLN+vAZaW1xUooqWDqVEsZN0U01jfAE=
|
||||
github.com/redis/go-redis/v9 v9.14.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI=
|
||||
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
"pkg/models"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/samber/lo"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/utils"
|
||||
"backend/middleware"
|
||||
"errors"
|
||||
"fmt"
|
||||
"pkg/models"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/services"
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
@@ -10,6 +9,7 @@ import (
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pkg/models"
|
||||
"time"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/utils"
|
||||
"backend/middleware"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"pkg/models"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/utils"
|
||||
"backend/middleware"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"pkg/models"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
"pkg/models"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
|
||||
"dario.cat/mergo"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
FileSize int64 `json:"size"`
|
||||
MimeType string `json:"mime_type"`
|
||||
FileHash string `json:"hash"`
|
||||
ChunkSize int64 `json:"chunk_size"`
|
||||
}
|
||||
|
||||
type FileType string
|
||||
|
||||
const (
|
||||
FileTypeInit FileType = "init"
|
||||
FileTypeUpload FileType = "already"
|
||||
)
|
||||
|
||||
type RedisFileInfo struct {
|
||||
FileInfo
|
||||
FileType FileType `json:"type"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
Expire int64 `json:"expire"` // 只有上传文件(init)的时候有这个字段
|
||||
}
|
||||
|
||||
func GetRedisFileInfo(fileId string) (*RedisFileInfo, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
fileInfoUnmarshalData, err := rdb.HGet(ctx, "015:fileInfoMap", fileId).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fileInfoData RedisFileInfo
|
||||
if err := json.Unmarshal([]byte(fileInfoUnmarshalData), &fileInfoData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fileInfoData, nil
|
||||
}
|
||||
|
||||
func SetRedisFileInfo(fileId string, fileInfo RedisFileInfo) error {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
old_fileInfo, err := GetRedisFileInfo(fileId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if old_fileInfo != nil {
|
||||
mergo.Merge(&fileInfo, old_fileInfo)
|
||||
}
|
||||
jsonData, _ := json.Marshal(fileInfo)
|
||||
_, err = rdb.HSet(ctx, "015:fileInfoMap", fileId, string(jsonData)).Result()
|
||||
return err
|
||||
}
|
||||
|
||||
func GetRedisFileInfoAll() (map[string]string, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
return rdb.HGetAll(ctx, "015:fileInfoMap").Result()
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func GetRedisFileShareRelational(fileId string) ([]string, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
fileShareRelationalUnmarshalData, err := rdb.HGet(ctx, "015:fileShareRelational", fileId).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var shareIDs []string
|
||||
if err := json.Unmarshal([]byte(fileShareRelationalUnmarshalData), &shareIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return shareIDs, nil
|
||||
}
|
||||
|
||||
func SetRedisFileShareRelational(fileId string, shareIDs []string) error {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
jsonData, _ := json.Marshal(shareIDs)
|
||||
_, err := rdb.HSet(ctx, "015:fileShareRelational", fileId, string(jsonData)).Result()
|
||||
return err
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func GetRedisPickupData(pickupCode string) (string, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
ShareId, err := rdb.Get(ctx, fmt.Sprintf("015:pickupCode:%s", pickupCode)).Result()
|
||||
if err == redis.Nil {
|
||||
return "", nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return ShareId, nil
|
||||
}
|
||||
|
||||
func SetRedisPickupData(pickupCode string, shareId string) (bool, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
ok, err := rdb.SetNX(ctx, fmt.Sprintf("015:pickupCode:%s", pickupCode), shareId, time.Until(time.Now().Add(24*time.Hour))).Result()
|
||||
return ok, err
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"dario.cat/mergo"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type RedisShareInfo struct {
|
||||
// Id string `json:"id"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
Owner string `json:"owner"`
|
||||
Type ShareType `json:"type"`
|
||||
Data string `json:"data"` // 分享数据 文件分享为文件id 文本分享为文本内容
|
||||
ExpireAt int64 `json:"expire_time"`
|
||||
ViewNum int64 `json:"download_nums"`
|
||||
Password string `json:"password"`
|
||||
NotifyEmail []string `json:"notify_email"`
|
||||
FileName string `json:"file_name"`
|
||||
// PickupCode bool `json:"pickup_code"`
|
||||
}
|
||||
|
||||
type ShareType string
|
||||
|
||||
const (
|
||||
ShareTypeFile ShareType = "file"
|
||||
ShareTypeText ShareType = "text"
|
||||
)
|
||||
|
||||
func GetRedisShareInfo(shareId string) (*RedisShareInfo, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
shareInfo := rdb.Get(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId))
|
||||
shareInfoUnmarshalData, err := shareInfo.Result()
|
||||
ttl, _ := rdb.TTL(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId)).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var shareInfoData RedisShareInfo
|
||||
|
||||
if err := json.Unmarshal([]byte(shareInfoUnmarshalData), &shareInfoData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shareInfoData.ExpireAt = time.Now().Add(ttl).Unix()
|
||||
return &shareInfoData, nil
|
||||
}
|
||||
|
||||
func SetRedisShareInfo(shareId string, shareInfo RedisShareInfo) error {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
old_shareInfo, err := GetRedisShareInfo(shareId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if old_shareInfo != nil {
|
||||
mergo.Merge(&shareInfo, old_shareInfo)
|
||||
}
|
||||
jsonData, _ := json.Marshal(shareInfo)
|
||||
_, err = rdb.Set(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId), string(jsonData), time.Until(time.Unix(shareInfo.ExpireAt, 0))).Result()
|
||||
return err
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
|
||||
"dario.cat/mergo"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// 统计数据结构
|
||||
type StatData struct {
|
||||
FileSize int64 `json:"file_size"` // 文件大小
|
||||
FileNum int64 `json:"file_num"` // 文件数量
|
||||
ShareNum int64 `json:"share_num"` // 分享数量
|
||||
DownloadNum int64 `json:"download_num"` // 下载数量
|
||||
}
|
||||
|
||||
func GetRedisStat(key string) (*StatData, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
statUnmarshalData, err := rdb.HGet(ctx, "015:stat", key).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var stat StatData
|
||||
if err := json.Unmarshal([]byte(statUnmarshalData), &stat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &stat, nil
|
||||
}
|
||||
|
||||
func SetRedisStat(key string, stat StatData) error {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
old_stat, err := GetRedisStat(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if old_stat != nil {
|
||||
mergo.Merge(&stat, old_stat)
|
||||
}
|
||||
jsonData, _ := json.Marshal(stat)
|
||||
_, err = rdb.HSet(ctx, "015:stat", key, string(jsonData)).Result()
|
||||
return err
|
||||
}
|
||||
|
||||
func GetRedisStatAll() (map[string]string, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
return rdb.HGetAll(ctx, "015:stat").Result()
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func GetRedisTaskInfo(taskId string) (*map[string]any, error) {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
taskInfo := rdb.Get(ctx, fmt.Sprintf("015:taskInfoMap:%s", taskId))
|
||||
taskInfoUnmarshalData, err := taskInfo.Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var taskInfoData map[string]any
|
||||
|
||||
if err := json.Unmarshal([]byte(taskInfoUnmarshalData), &taskInfoData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &taskInfoData, nil
|
||||
}
|
||||
|
||||
func SetRedisTaskInfo(taskId string, taskInfo map[string]any) error {
|
||||
rdb, ctx := utils.GetRedisClient()
|
||||
jsonData, _ := json.Marshal(taskInfo)
|
||||
_, err := rdb.Set(ctx, fmt.Sprintf("015:taskInfoMap:%s", taskId), jsonData, time.Hour).Result()
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user