mirror of https://github.com/synctv-org/synctv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package vendorBilibili
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/synctv-org/synctv/internal/db"
|
|
dbModel "github.com/synctv-org/synctv/internal/model"
|
|
"github.com/synctv-org/synctv/internal/op"
|
|
"github.com/synctv-org/synctv/internal/vendor"
|
|
"github.com/synctv-org/synctv/server/model"
|
|
"github.com/synctv-org/synctv/utils"
|
|
"github.com/synctv-org/vendors/api/bilibili"
|
|
)
|
|
|
|
func Me(ctx *gin.Context) {
|
|
user := ctx.MustGet("user").(*op.User)
|
|
v, err := db.FirstOrCreateVendorByUserIDAndVendor(user.ID, dbModel.StreamingVendorBilibili)
|
|
if err != nil {
|
|
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
|
|
return
|
|
}
|
|
if len(v.Cookies) == 0 {
|
|
ctx.JSON(http.StatusOK, model.NewApiDataResp(&bilibili.UserInfoResp{
|
|
IsLogin: false,
|
|
}))
|
|
return
|
|
}
|
|
resp, err := vendor.BilibiliClient("").UserInfo(ctx, &bilibili.UserInfoReq{
|
|
Cookies: utils.HttpCookieToMap(v.Cookies),
|
|
})
|
|
if err != nil {
|
|
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
|
|
return
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, model.NewApiDataResp(resp))
|
|
}
|