/
account_bind.go
56 lines (49 loc) · 1.52 KB
/
account_bind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package v1
import (
"fmt"
"github.com/Crossbell-Box/OperatorSync/app/server/global"
"github.com/Crossbell-Box/OperatorSync/app/server/utils"
"github.com/gin-gonic/gin"
"net/http"
"strings"
"time"
)
func BindAccount(ctx *gin.Context) {
// Only accept when pass validate
reqCharacterID := ctx.Param("character") // ID
reqPlatform := ctx.Param("platform")
reqUsername := ctx.Param("username")
// User selectable start time
nowTimeStr := time.Unix(0, 0).Format(time.RFC3339)
startFromStr := ctx.DefaultQuery("from", nowTimeStr)
startFromTime, err := time.Parse(time.RFC3339, startFromStr)
if err != nil {
ctx.JSON(http.StatusOK, gin.H{
"ok": false,
"message": fmt.Sprintf("Failed to parse time with error (%s), please use RFC3339 format (%s)", err.Error(), nowTimeStr),
})
return
}
isAccountInherit := strings.Contains(strings.ToLower(ctx.DefaultQuery("inherit", "true")), "t")
props := utils.BindAccountProps{
CrossbellCharacterID: reqCharacterID,
Platform: reqPlatform,
Username: reqUsername,
StartFrom: startFromTime,
IsInherit: isAccountInherit,
}
result, message, err := utils.AccountBind(&props)
if err != nil {
global.Logger.Errorf("Failed to bind account %s (%s) for character #%s with error: %s", reqUsername, reqPlatform, reqCharacterID, err.Error())
ctx.JSON(http.StatusOK, gin.H{
"ok": false,
"message": message,
})
} else {
ctx.JSON(http.StatusOK, gin.H{
"ok": true,
"message": message,
"result": result,
})
}
}