Skip to content

Commit

Permalink
bugfixed
Browse files Browse the repository at this point in the history
  • Loading branch information
zgwit committed Oct 30, 2024
1 parent 249a921 commit c11b4f7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 41 deletions.
1 change: 1 addition & 0 deletions admin/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package admin
import (
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/god-jason/bucket/api"
)

func logout(ctx *gin.Context) {
Expand Down
3 changes: 2 additions & 1 deletion export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/god-jason/bucket/api"
"github.com/god-jason/bucket/mongodb"
"go.mongodb.org/mongo-driver/bson"
)
Expand All @@ -18,7 +19,7 @@ func ApiExport(table, filename string) gin.HandlerFunc {

err := mongodb.Find(table, bson.D{{Key: "_id", Value: bson.E{Key: "$in", Value: ids}}}, nil, 0, 0, &datum)
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}

Expand Down
15 changes: 8 additions & 7 deletions export/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/zip"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/god-jason/bucket/api"
"github.com/god-jason/bucket/mongodb"
"go.mongodb.org/mongo-driver/bson/primitive"
"io"
Expand All @@ -13,20 +14,20 @@ func ApiImport(table string) gin.HandlerFunc {
return func(ctx *gin.Context) {
formFile, err := ctx.FormFile("file")
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}

file, err := formFile.Open()
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}
defer file.Close()

reader, err := zip.NewReader(file, formFile.Size)
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}

Expand All @@ -40,26 +41,26 @@ func ApiImport(table string) gin.HandlerFunc {
reader, err := file.Open()
buf, err := io.ReadAll(reader)
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}

var data []any
err = json.Unmarshal(buf, &data)
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}

ids, err := mongodb.InsertMany(table, data)
if err != nil {
Error(ctx, err)
api.Error(ctx, err)
return
}

idss = append(idss, ids...)
}

OK(ctx, idss)
api.OK(ctx, idss)
}
}
33 changes: 0 additions & 33 deletions export/reply.go

This file was deleted.

File renamed without changes.

0 comments on commit c11b4f7

Please sign in to comment.