Skip to content

Commit

Permalink
feat: Fix user list for admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
IRONICBo committed Mar 1, 2024
2 parents e95ac6c + 81e3d1f commit 8a384ef
Show file tree
Hide file tree
Showing 21 changed files with 22,539 additions and 22,973 deletions.
77 changes: 40 additions & 37 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strconv"

"github.com/goplus/community/internal/core"
Expand Down Expand Up @@ -125,22 +126,22 @@ get "/article/:id", ctx => {
}
id := ctx.param("id")
article, err := community.Article(todo, id)
if err!=nil {
if err != nil {
xLog.Error("get article error:", err)
return
}
likeState,err := community.ArticleLikeState(todo,userId,id)
if err!=nil {
likeState, err := community.ArticleLikeState(todo, userId, id)
if err != nil {
xLog.Error("article state err:", err)
return
}
ip := community.GetClientIP(ctx.Request)
community.ArticleLView(todo,id,ip,userId)
community.ArticleLView(todo, id, ip, userId)
articleJson, _ := json.Marshal(&article)
ctx.yap "article", {
"UserId": userId,
"User": user,
"Article": string(articleJson),
"UserId": userId,
"User": user,
"Article": string(articleJson),
"LikeState": likeState,
}
}
Expand Down Expand Up @@ -355,6 +356,7 @@ post "/api/article/commit", ctx => {
},
Content: content,
Trans: trans,
Vtt_id: ctx.param("vtt_id"),
}

// if trans == true translate the article
Expand Down Expand Up @@ -472,7 +474,7 @@ get "/user/edit", ctx => {
// User
//
// User apis
put "/api/user", ctx => {
put "/api/update/user", ctx => {
token, err := core.GetToken(ctx)
uid, err := community.ParseJwtToken(token.Value)
user := &core.UserInfo{
Expand Down Expand Up @@ -740,16 +742,17 @@ get "/api/media/:id/url", ctx => {
get "/api/video/:id", ctx => {
id := ctx.param("id")
fileKey, err := community.GetMediaUrl(todo, id)
m := make(map[string]string, 2)
m := make(map[string]string, 3)
format, err := community.GetMediaType(todo, id)
if err != nil {
ctx.json {
"code": 500,
"err": err.Error(),
}
}
if format == "video/mp4" {
subtitle, err := community.GetVideoSubtitle(todo, id)
match, _ := regexp.MatchString("^video", format)
if match {
subtitle, status, err := community.GetVideoSubtitle(todo, id)
if err != nil {
if err != nil {
ctx.json {
Expand All @@ -760,6 +763,7 @@ get "/api/video/:id", ctx => {
return
}
m["subtitle"] = domain + subtitle
m["status"] = status
}
htmlUrl := fmt.Sprintf("%s%s", domain, fileKey)
if err != nil {
Expand Down Expand Up @@ -864,15 +868,15 @@ get "/login/callback", ctx => {
}

post "/api/article/like", ctx => {
articleId := ctx.param("articleId")
articleId := ctx.param("articleId")
articleIdInt, err := strconv.Atoi(articleId)
if err != nil {
ctx.json {
"code": 500,
"err": err.Error(),
}
}
token, err := core.GetToken(ctx)
if err != nil {
ctx.json {
"code": 500,
"err": err.Error(),
}
}
token, err := core.GetToken(ctx)
if err != nil {
xLog.Info("token", err)
ctx.json {
Expand All @@ -881,26 +885,25 @@ post "/api/article/like", ctx => {
}
}
uid, err := community.ParseJwtToken(token.Value)
if err != nil {
ctx.json {
"code": 0,
"err": err.Error(),
}
}
res, err := community.ArticleLike(todo, articleIdInt,uid)
if err!=nil {
ctx.json {
"code": 500,
"err": err.Error(),
}
}
ctx.json {
"code": 200,
"data": res,
}
if err != nil {
ctx.json {
"code": 0,
"err": err.Error(),
}
}
res, err := community.ArticleLike(todo, articleIdInt, uid)
if err != nil {
ctx.json {
"code": 500,
"err": err.Error(),
}
}
ctx.json {
"code": 200,
"data": res,
}
}


conf := &core.Config{}
community, _ = core.New(todo, conf)
core.CasdoorConfigInit()
Expand Down
Loading

0 comments on commit 8a384ef

Please sign in to comment.