Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed Aug 1, 2019
1 parent 9468b97 commit 9d582b6
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 77 deletions.
7 changes: 7 additions & 0 deletions backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 后端API更新日志
## v0.3.0 2019-08-02
### 修复
1. `DELETE /content` 删除单独content file已可使用

### 新增
1. message相关功能已可以使用

## v0.2.2 2019-08-01
### 禁用
1. `DELETE /content` 删除单独content file暂不可用
Expand Down
1 change: 0 additions & 1 deletion backend/api/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func getAuth(c *gin.Context) {
return
}

utils.Error(rsp2.User.Status)
// sign token
if rsp2.User.Status == user.UserInfo_NORMAL {
if rsp2.User.Role == user.UserInfo_USER {
Expand Down
2 changes: 2 additions & 0 deletions backend/api/content/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func deleteContent(c *gin.Context) {
type param struct {
ContentID string `form:"contentID" binding:"required"`
ContentToken string `form:"contentToken" binding:"required"`
FileID string `form:"fileID"`
}
var p param
role := utils.GetRole(c)
Expand All @@ -115,6 +116,7 @@ func deleteContent(c *gin.Context) {
rsp, err := srv.Delete(context.TODO(), &content.ContentDeleteRequest{
ContentID: p.ContentID,
ContentToken: p.ContentToken,
FileID: p.FileID,
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
Expand Down
4 changes: 2 additions & 2 deletions backend/doc/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ define({ "api": [
"type": "int32",
"optional": false,
"field": "status",
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 2 for invalid type</p>"
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 3 for invalid type</p>"
},
{
"group": "Success 200",
Expand Down Expand Up @@ -1639,7 +1639,7 @@ define({ "api": [
"type": "int32",
"optional": false,
"field": "status",
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 2 for invalid type</p>"
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 3 for invalid type</p>"
},
{
"group": "Success 200",
Expand Down
4 changes: 2 additions & 2 deletions backend/doc/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@
"type": "int32",
"optional": false,
"field": "status",
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 2 for invalid type</p>"
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 3 for invalid type</p>"
},
{
"group": "Success 200",
Expand Down Expand Up @@ -1639,7 +1639,7 @@
"type": "int32",
"optional": false,
"field": "status",
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 2 for invalid type</p>"
"description": "<p>-1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 3 for invalid type</p>"
},
{
"group": "Success 200",
Expand Down
2 changes: 1 addition & 1 deletion backend/doc/api_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-08-01T17:54:38.573Z",
"time": "2019-08-01T18:33:38.978Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
2 changes: 1 addition & 1 deletion backend/doc/api_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-08-01T17:54:38.573Z",
"time": "2019-08-01T18:33:38.978Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
82 changes: 61 additions & 21 deletions backend/srv/content/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type srv struct{}
* @apiParam {string} [contentToken] content token, left empty for first upload
* @apiParam {bytes} content binary bytes, file accept [image](https://github.com/h2non/filetype#image) and [video](https://github.com/h2non/filetype#video)
* @apiParam {int32} type 1 for picture <br> 2 for video
* @apiSuccess {int32} status -1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 2 for invalid type
* @apiSuccess {int32} status -1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 3 for invalid type
* @apiSuccess {string} contentID 24 bytes contentID
* @apiSuccess {string} contentToken random uuid content token
* @apiSuccess {string} fileID 24 bytes fileID
Expand Down Expand Up @@ -81,7 +81,7 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp
token := uuid.NewV4().String()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
res, err := collection.InsertOne(ctx, bson.M{
"token": token,
"files": bson.A{
Expand Down Expand Up @@ -111,7 +111,7 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
rid, _ := primitive.ObjectIDFromHex(req.ContentID)
_, err = collection.UpdateOne(ctx, bson.D{
{"_id", rid},
Expand Down Expand Up @@ -147,7 +147,7 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp
* @apiParam {string} [contentID] 24 bytes content id, left empty for first upload
* @apiParam {string} [contentToken] content token, left empty for first upload
* @apiParam {list} tags {string} tag
* @apiSuccess {int32} status -1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 2 for invalid type
* @apiSuccess {int32} status -1 for invalid param <br> 1 for success <br> 2 for invalid token <br> 3 for invalid type
* @apiSuccess {string} contentID 24 bytes contentID
* @apiSuccess {string} contentToken random uuid content token
* @apiUse DBServerDown
Expand All @@ -163,7 +163,7 @@ func (a *srv) CreateTag(ctx context.Context, req *content.ContentCreateTagReques
token := uuid.NewV4().String()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
res, err := collection.InsertOne(ctx, bson.M{
"token": token,
"tags": req.Tags,
Expand All @@ -183,7 +183,7 @@ func (a *srv) CreateTag(ctx context.Context, req *content.ContentCreateTagReques

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
rid, err := primitive.ObjectIDFromHex(req.ContentID)
if utils.LogContinue(err, utils.Warning) {
rsp.Status = content.ContentCreateTagResponse_INVALID_TOKEN
Expand Down Expand Up @@ -242,7 +242,7 @@ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp
// check id
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
rid, _ := primitive.ObjectIDFromHex(req.ContentID)
oldFid, err := primitive.ObjectIDFromHex(req.FileID)
if utils.LogContinue(err, utils.Warning) {
Expand Down Expand Up @@ -328,27 +328,42 @@ func (a *srv) Delete(ctx context.Context, req *content.ContentDeleteRequest, rsp

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
rid, err := primitive.ObjectIDFromHex(req.ContentID)
if utils.LogContinue(err, utils.Warning) {
rsp.Status = content.ContentDeleteResponse_INVALID_TOKEN
return nil
}
var res result
err = collection.FindOneAndDelete(ctx, bson.D{
{"_id", rid},
{"token", req.ContentToken},
}).Decode(&res)
if utils.LogContinue(err, utils.Warning) {
rsp.Status = content.ContentDeleteResponse_INVALID_TOKEN
return nil
}

srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) },
func() interface{} { return mock.NewFileService() }).(file.FileService)
for _, v := range res.Files {
if utils.RequireParam(req.FileID) { // delete single file
fid, err := primitive.ObjectIDFromHex(req.FileID)
if utils.LogContinue(err, utils.Warning) {
rsp.Status = content.ContentDeleteResponse_NOT_FOUND
return nil
}

res, err := collection.UpdateOne(ctx, bson.D{
{"_id", rid},
{"token", req.ContentToken},
}, bson.D{
{"$pull", bson.D{
{"files", bson.D{
{"fileID", fid},
}},
}},
})
if utils.LogContinue(err, utils.Error) {
return err
}
if res.ModifiedCount == 0 {
rsp.Status = content.ContentDeleteResponse_NOT_FOUND
return nil
}

microRsp, err := srv.Delete(context.TODO(), &file.FileRequest{
FileID: v.FileID.Hex(),
FileID: req.FileID,
})
if utils.LogContinue(err, utils.Error) {
return err
Expand All @@ -357,6 +372,31 @@ func (a *srv) Delete(ctx context.Context, req *content.ContentDeleteRequest, rsp
_, s := utils.LogContinueS("File delete return "+microRsp.Status.String(), utils.Error)
return errors.New(s)
}
} else {
var res result
err = collection.FindOneAndDelete(ctx, bson.D{
{"_id", rid},
{"token", req.ContentToken},
}).Decode(&res)
if utils.LogContinue(err, utils.Warning) {
rsp.Status = content.ContentDeleteResponse_INVALID_TOKEN
return nil
}

srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) },
func() interface{} { return mock.NewFileService() }).(file.FileService)
for _, v := range res.Files {
microRsp, err := srv.Delete(context.TODO(), &file.FileRequest{
FileID: v.FileID.Hex(),
})
if utils.LogContinue(err, utils.Error) {
return err
}
if microRsp.Status != file.FileDeleteResponse_SUCCESS {
_, s := utils.LogContinueS("File delete return "+microRsp.Status.String(), utils.Error)
return errors.New(s)
}
}
}
rsp.Status = content.ContentDeleteResponse_SUCCESS
return nil
Expand Down Expand Up @@ -394,7 +434,7 @@ func (a *srv) Query(ctx context.Context, req *content.ContentQueryRequest, rsp *

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
rid, err := primitive.ObjectIDFromHex(req.ContentID)
if utils.LogContinue(err, utils.Warning) {
rsp.Status = content.ContentQueryResponse_INVALID_PARAM
Expand Down Expand Up @@ -454,7 +494,7 @@ func validCheck(contentID string, contentToken string) bool {

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDatabase.Collection("sellinfo")
collection := db.MongoDatabase.Collection("content")
rid, err := primitive.ObjectIDFromHex(contentID)
if utils.LogContinue(err, utils.Warning) {
return false
Expand Down
94 changes: 51 additions & 43 deletions backend/srv/content/proto/content.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9d582b6

Please sign in to comment.