up
This commit is contained in:
@@ -67,6 +67,7 @@ func main() {
|
||||
//统一初始化
|
||||
models.ConfigAllInit()
|
||||
routers.ApiUserInit() //用户表先初始化这是必须的因为后面需要用到用户组
|
||||
routers.ApiFilesInit()
|
||||
routers.ApiScheduleInit()
|
||||
routers.ApiPurchaseInit()
|
||||
|
||||
|
||||
@@ -12,19 +12,6 @@ import (
|
||||
|
||||
var DB *gorm.DB
|
||||
|
||||
type TabFileInfo_ struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||
Name string `gorm:"not null;size:256;index"` // 前端报告的文件名
|
||||
Path string `gorm:"not null;size:300"` //
|
||||
Sha256 string `gorm:"not null;size:64;index"` //
|
||||
Mime string `gorm:"size:64;index"`
|
||||
Type string `gorm:"size:64;index"`
|
||||
Const uint `gorm:"default:1;index"`
|
||||
Per uint `gorm:"default:1"`
|
||||
UserID uint `gorm:"not null;index"`
|
||||
Date time.Time `gorm:"type:datetime;default:CURRENT_TIMESTAMP"` // 默认当前时间
|
||||
}
|
||||
|
||||
type TabUser_ struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement"` // 自增主键
|
||||
Name string `gorm:"size:100;uniqueIndex"` // 唯一约束索引
|
||||
@@ -126,8 +113,6 @@ func DatabaseInit() error {
|
||||
|
||||
DB.AutoMigrate(&TabCookie_{})
|
||||
|
||||
DB.AutoMigrate(&TabFileInfo_{})
|
||||
|
||||
DB.AutoMigrate(&APIRequestLog_{})
|
||||
|
||||
return nil
|
||||
|
||||
@@ -139,7 +139,7 @@ func ApiPurchase(r *gin.RouterGroup) {
|
||||
for _, b := range binds {
|
||||
fileIDs = append(fileIDs, b.FileID)
|
||||
}
|
||||
var files []models.TabFileInfo_
|
||||
var files []TabFileInfo_
|
||||
if len(fileIDs) > 0 {
|
||||
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
||||
}
|
||||
@@ -448,7 +448,7 @@ func ApiPurchase(r *gin.RouterGroup) {
|
||||
|
||||
//绑定文件
|
||||
for i := 0; i < len(jsondata.Photos); i++ {
|
||||
findFile := models.TabFileInfo_{
|
||||
findFile := TabFileInfo_{
|
||||
Sha256: jsondata.Photos[i],
|
||||
Type: "image",
|
||||
}
|
||||
@@ -588,7 +588,7 @@ func ApiPurchase(r *gin.RouterGroup) {
|
||||
// 重建图片绑定:先删旧,再插新
|
||||
models.DB.Where("order_id = ?", from.ID).Delete(&TabPurchaseFileBind{})
|
||||
for _, hash := range from.Photos {
|
||||
findFile := models.TabFileInfo_{Sha256: hash, Type: "image"}
|
||||
findFile := TabFileInfo_{Sha256: hash, Type: "image"}
|
||||
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
||||
models.DB.Create(&TabPurchaseFileBind{
|
||||
OrderID: from.ID,
|
||||
|
||||
@@ -6,14 +6,33 @@ import (
|
||||
"ops/models"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TabFileInfo_ struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||
Name string `gorm:"not null;size:256;index"` // 前端报告的文件名
|
||||
Path string `gorm:"not null;size:300"` //
|
||||
Sha256 string `gorm:"not null;size:64;index"` //
|
||||
Mime string `gorm:"size:64;index"`
|
||||
Type string `gorm:"size:64;index"`
|
||||
Const uint `gorm:"default:1;index"`
|
||||
Per uint `gorm:"default:1"`
|
||||
UserID uint `gorm:"not null;index"`
|
||||
Date time.Time `gorm:"type:datetime;default:CURRENT_TIMESTAMP"` // 默认当前时间
|
||||
}
|
||||
|
||||
func file_save() {
|
||||
|
||||
}
|
||||
|
||||
func ApiFilesInit() {
|
||||
|
||||
models.DB.AutoMigrate(&TabFileInfo_{})
|
||||
}
|
||||
|
||||
func ApiFiles(r *gin.RouterGroup) {
|
||||
|
||||
//getfile := r.Group("/get") //定义上传组
|
||||
@@ -35,7 +54,7 @@ func ApiFiles(r *gin.RouterGroup) {
|
||||
download = false
|
||||
}
|
||||
if isPartOK {
|
||||
file_info := models.TabFileInfo_{
|
||||
file_info := TabFileInfo_{
|
||||
Sha256: hash,
|
||||
}
|
||||
if models.DB.Where(&file_info).First(&file_info).Error == nil {
|
||||
@@ -107,14 +126,14 @@ func ApiFiles(r *gin.RouterGroup) {
|
||||
}
|
||||
//记录到数据库
|
||||
//先检查数据库有没有数据
|
||||
fund_file_info := models.TabFileInfo_{
|
||||
fund_file_info := TabFileInfo_{
|
||||
Name: filename,
|
||||
Sha256: hash_str,
|
||||
Mime: mimeType,
|
||||
Type: "image",
|
||||
UserID: user.ID,
|
||||
}
|
||||
fund_file_info2 := models.TabFileInfo_{}
|
||||
fund_file_info2 := TabFileInfo_{}
|
||||
|
||||
models.DB.Where(&fund_file_info).Find(&fund_file_info2)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package routers
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"ops/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -35,7 +34,7 @@ func ReturnJson(ctx *gin.Context, errMsg string, data map[string]interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func ReturnFile(ctx *gin.Context, file_info *models.TabFileInfo_, preview bool) {
|
||||
func ReturnFile(ctx *gin.Context, file_info *TabFileInfo_, preview bool) {
|
||||
if preview {
|
||||
ctx.File(file_info.Path)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user