From c0d695675ac04dbc82ca674db27d8727277092df Mon Sep 17 00:00:00 2001 From: Xhy <1416318023@qq.com> Date: Tue, 27 Feb 2024 21:56:06 +0800 Subject: [PATCH] feat: article-view and page view --- cmd/gopcomm/community_yap.gox | 14 +- cmd/gopcomm/gop_autogen.go | 704 ++++++++++++++++--------------- cmd/gopcomm/yap/article_yap.html | 18 +- cmd/gopcomm/yap/home_yap.html | 4 +- internal/core/community.go | 54 ++- internal/core/community_test.go | 10 + 6 files changed, 433 insertions(+), 371 deletions(-) diff --git a/cmd/gopcomm/community_yap.gox b/cmd/gopcomm/community_yap.gox index 0a413a9..f0cd2b0 100644 --- a/cmd/gopcomm/community_yap.gox +++ b/cmd/gopcomm/community_yap.gox @@ -125,14 +125,18 @@ get "/article/:id", ctx => { } id := ctx.param("id") article, err := community.Article(todo, id) - likeState,_:= community.ArticleLikeState(todo,userId,id) - if err != nil { + if err!=nil { xLog.Error("get article error:", err) + return } - articleJson, err := json.Marshal(&article) - if err != nil { - xLog.Error("json marshal error:", err) + 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) + articleJson, _ := json.Marshal(&article) ctx.yap "article", { "UserId": userId, "User": user, diff --git a/cmd/gopcomm/gop_autogen.go b/cmd/gopcomm/gop_autogen.go index c2e89d3..cac984e 100644 --- a/cmd/gopcomm/gop_autogen.go +++ b/cmd/gopcomm/gop_autogen.go @@ -163,810 +163,818 @@ func (this *community) MainEntry() { //line cmd/gopcomm/community_yap.gox:127:1 article, err := this.community.Article(todo, id) //line cmd/gopcomm/community_yap.gox:128:1 - likeState, _ := this.community.ArticleLikeState(todo, userId, id) -//line cmd/gopcomm/community_yap.gox:129:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:130:1 +//line cmd/gopcomm/community_yap.gox:129:1 xLog.Error("get article error:", err) +//line cmd/gopcomm/community_yap.gox:130:1 + return } //line cmd/gopcomm/community_yap.gox:132:1 - articleJson, err := json.Marshal(&article) + likeState, err := this.community.ArticleLikeState(todo, userId, id) //line cmd/gopcomm/community_yap.gox:133:1 if err != nil { //line cmd/gopcomm/community_yap.gox:134:1 - xLog.Error("json marshal error:", err) + xLog.Error("article state err:", err) +//line cmd/gopcomm/community_yap.gox:135:1 + return } -//line cmd/gopcomm/community_yap.gox:136:1 +//line cmd/gopcomm/community_yap.gox:137:1 + ip := this.community.GetClientIP(ctx.Request) +//line cmd/gopcomm/community_yap.gox:138:1 + this.community.ArticleLView(todo, id, ip, userId) +//line cmd/gopcomm/community_yap.gox:139:1 + articleJson, _ := json.Marshal(&article) +//line cmd/gopcomm/community_yap.gox:140:1 ctx.Yap__1("article", map[string]interface{}{"UserId": userId, "User": user, "Article": string(articleJson), "LikeState": likeState}) }) -//line cmd/gopcomm/community_yap.gox:144:1 +//line cmd/gopcomm/community_yap.gox:148:1 this.Get("/add", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:145:1 +//line cmd/gopcomm/community_yap.gox:149:1 var user *core.User -//line cmd/gopcomm/community_yap.gox:146:1 +//line cmd/gopcomm/community_yap.gox:150:1 userId := "" -//line cmd/gopcomm/community_yap.gox:147:1 +//line cmd/gopcomm/community_yap.gox:151:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:148:1 +//line cmd/gopcomm/community_yap.gox:152:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:149:1 +//line cmd/gopcomm/community_yap.gox:153:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:150:1 +//line cmd/gopcomm/community_yap.gox:154:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:151:1 +//line cmd/gopcomm/community_yap.gox:155:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:153:1 +//line cmd/gopcomm/community_yap.gox:157:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:156:1 +//line cmd/gopcomm/community_yap.gox:160:1 ctx.Yap__1("edit", map[string]interface{}{"User": user, "UserId": userId}) }) -//line cmd/gopcomm/community_yap.gox:162:1 +//line cmd/gopcomm/community_yap.gox:166:1 this.Get("/edit/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:163:1 +//line cmd/gopcomm/community_yap.gox:167:1 var user *core.User -//line cmd/gopcomm/community_yap.gox:164:1 +//line cmd/gopcomm/community_yap.gox:168:1 userId := "" -//line cmd/gopcomm/community_yap.gox:165:1 +//line cmd/gopcomm/community_yap.gox:169:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:166:1 +//line cmd/gopcomm/community_yap.gox:170:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:167:1 +//line cmd/gopcomm/community_yap.gox:171:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:168:1 +//line cmd/gopcomm/community_yap.gox:172:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:169:1 +//line cmd/gopcomm/community_yap.gox:173:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:171:1 +//line cmd/gopcomm/community_yap.gox:175:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:175:1 +//line cmd/gopcomm/community_yap.gox:179:1 uid := user.Id -//line cmd/gopcomm/community_yap.gox:176:1 +//line cmd/gopcomm/community_yap.gox:180:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:177:1 +//line cmd/gopcomm/community_yap.gox:181:1 if id != "" { -//line cmd/gopcomm/community_yap.gox:178:1 +//line cmd/gopcomm/community_yap.gox:182:1 editable, err := this.community.CanEditable(todo, uid, id) -//line cmd/gopcomm/community_yap.gox:179:1 +//line cmd/gopcomm/community_yap.gox:183:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:180:1 +//line cmd/gopcomm/community_yap.gox:184:1 xLog.Error("can editable error:", err) -//line cmd/gopcomm/community_yap.gox:181:1 +//line cmd/gopcomm/community_yap.gox:185:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:183:1 +//line cmd/gopcomm/community_yap.gox:187:1 if !editable { -//line cmd/gopcomm/community_yap.gox:184:1 +//line cmd/gopcomm/community_yap.gox:188:1 xLog.Error("no permissions") -//line cmd/gopcomm/community_yap.gox:185:1 +//line cmd/gopcomm/community_yap.gox:189:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:187:1 +//line cmd/gopcomm/community_yap.gox:191:1 article, err := this.community.Article(todo, id) -//line cmd/gopcomm/community_yap.gox:188:1 +//line cmd/gopcomm/community_yap.gox:192:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:189:1 +//line cmd/gopcomm/community_yap.gox:193:1 xLog.Error("get article error:", err) -//line cmd/gopcomm/community_yap.gox:190:1 +//line cmd/gopcomm/community_yap.gox:194:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:192:1 +//line cmd/gopcomm/community_yap.gox:196:1 articleJson, err := json.Marshal(&article) -//line cmd/gopcomm/community_yap.gox:193:1 +//line cmd/gopcomm/community_yap.gox:197:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:194:1 +//line cmd/gopcomm/community_yap.gox:198:1 xLog.Error("json marshal error:", err) -//line cmd/gopcomm/community_yap.gox:195:1 +//line cmd/gopcomm/community_yap.gox:199:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:197:1 +//line cmd/gopcomm/community_yap.gox:201:1 ctx.Yap__1("edit", map[string]interface{}{"UserId": userId, "User": user, "Article": string(articleJson)}) } }) -//line cmd/gopcomm/community_yap.gox:205:1 +//line cmd/gopcomm/community_yap.gox:209:1 this.Get("/search", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:206:1 +//line cmd/gopcomm/community_yap.gox:210:1 searchValue := ctx.Param("value") -//line cmd/gopcomm/community_yap.gox:207:1 +//line cmd/gopcomm/community_yap.gox:211:1 label := ctx.Param("label") -//line cmd/gopcomm/community_yap.gox:208:1 +//line cmd/gopcomm/community_yap.gox:212:1 if label == "" { -//line cmd/gopcomm/community_yap.gox:209:1 +//line cmd/gopcomm/community_yap.gox:213:1 label = "article" } -//line cmd/gopcomm/community_yap.gox:212:1 +//line cmd/gopcomm/community_yap.gox:216:1 // todo middleware var user *core.User -//line cmd/gopcomm/community_yap.gox:214:1 +//line cmd/gopcomm/community_yap.gox:218:1 userId := "" -//line cmd/gopcomm/community_yap.gox:215:1 +//line cmd/gopcomm/community_yap.gox:219:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:216:1 +//line cmd/gopcomm/community_yap.gox:220:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:217:1 +//line cmd/gopcomm/community_yap.gox:221:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:218:1 +//line cmd/gopcomm/community_yap.gox:222:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:219:1 +//line cmd/gopcomm/community_yap.gox:223:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:221:1 +//line cmd/gopcomm/community_yap.gox:225:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:225:1 +//line cmd/gopcomm/community_yap.gox:229:1 articles, next, err := this.community.ListArticle(todo, core.MarkBegin, limitConst, searchValue, label) -//line cmd/gopcomm/community_yap.gox:226:1 +//line cmd/gopcomm/community_yap.gox:230:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:227:1 +//line cmd/gopcomm/community_yap.gox:231:1 xLog.Error("get article error:", err) } -//line cmd/gopcomm/community_yap.gox:229:1 +//line cmd/gopcomm/community_yap.gox:233:1 articlesJson, err := json.Marshal(&articles) -//line cmd/gopcomm/community_yap.gox:230:1 +//line cmd/gopcomm/community_yap.gox:234:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:231:1 +//line cmd/gopcomm/community_yap.gox:235:1 xLog.Error("json marshal error:", err) } -//line cmd/gopcomm/community_yap.gox:233:1 +//line cmd/gopcomm/community_yap.gox:237:1 ctx.Yap__1("home", map[string]interface{}{"UserId": userId, "User": user, "Items": string(articlesJson), "Value": searchValue, "Next": next, "Tab": label}) }) -//line cmd/gopcomm/community_yap.gox:246:1 +//line cmd/gopcomm/community_yap.gox:250:1 this.Get("/api/article/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:247:1 +//line cmd/gopcomm/community_yap.gox:251:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:248:1 +//line cmd/gopcomm/community_yap.gox:252:1 article, err := this.community.Article(todo, id) -//line cmd/gopcomm/community_yap.gox:249:1 +//line cmd/gopcomm/community_yap.gox:253:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:250:1 +//line cmd/gopcomm/community_yap.gox:254:1 xLog.Error("get article error:", err) -//line cmd/gopcomm/community_yap.gox:251:1 +//line cmd/gopcomm/community_yap.gox:255:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "get article failed"}) } -//line cmd/gopcomm/community_yap.gox:256:1 +//line cmd/gopcomm/community_yap.gox:260:1 ctx.Json__1(map[string]interface{}{"code": 200, "data": article}) }) -//line cmd/gopcomm/community_yap.gox:262:1 +//line cmd/gopcomm/community_yap.gox:266:1 this.Delete("/api/article/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:263:1 +//line cmd/gopcomm/community_yap.gox:267:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:264:1 +//line cmd/gopcomm/community_yap.gox:268:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:265:1 +//line cmd/gopcomm/community_yap.gox:269:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:266:1 +//line cmd/gopcomm/community_yap.gox:270:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:267:1 +//line cmd/gopcomm/community_yap.gox:271:1 xLog.Error("token parse error") -//line cmd/gopcomm/community_yap.gox:268:1 +//line cmd/gopcomm/community_yap.gox:272:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:273:1 +//line cmd/gopcomm/community_yap.gox:277:1 err = this.community.DeleteArticle(todo, uid, id) -//line cmd/gopcomm/community_yap.gox:274:1 +//line cmd/gopcomm/community_yap.gox:278:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:275:1 +//line cmd/gopcomm/community_yap.gox:279:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "delete failed"}) } else { -//line cmd/gopcomm/community_yap.gox:280:1 +//line cmd/gopcomm/community_yap.gox:284:1 ctx.Json__1(map[string]interface{}{"code": 200, "msg": "delete success"}) } }) -//line cmd/gopcomm/community_yap.gox:287:1 +//line cmd/gopcomm/community_yap.gox:291:1 this.Get("/api/articles", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:288:1 +//line cmd/gopcomm/community_yap.gox:292:1 from := ctx.Param("from") -//line cmd/gopcomm/community_yap.gox:289:1 +//line cmd/gopcomm/community_yap.gox:293:1 limit := ctx.Param("limit") -//line cmd/gopcomm/community_yap.gox:290:1 +//line cmd/gopcomm/community_yap.gox:294:1 searchValue := ctx.Param("value") -//line cmd/gopcomm/community_yap.gox:291:1 +//line cmd/gopcomm/community_yap.gox:295:1 label := ctx.Param("label") -//line cmd/gopcomm/community_yap.gox:293:1 +//line cmd/gopcomm/community_yap.gox:297:1 limitInt, err := strconv.Atoi(limit) -//line cmd/gopcomm/community_yap.gox:294:1 +//line cmd/gopcomm/community_yap.gox:298:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:295:1 +//line cmd/gopcomm/community_yap.gox:299:1 limitInt = limitConst } -//line cmd/gopcomm/community_yap.gox:298:1 +//line cmd/gopcomm/community_yap.gox:302:1 articles, next, err := this.community.ListArticle(todo, from, limitInt, searchValue, label) -//line cmd/gopcomm/community_yap.gox:299:1 +//line cmd/gopcomm/community_yap.gox:303:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:300:1 +//line cmd/gopcomm/community_yap.gox:304:1 xLog.Error("get article error:", err) -//line cmd/gopcomm/community_yap.gox:301:1 +//line cmd/gopcomm/community_yap.gox:305:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "get article failed"}) } -//line cmd/gopcomm/community_yap.gox:306:1 +//line cmd/gopcomm/community_yap.gox:310:1 ctx.Json__1(map[string]interface{}{"code": 200, "items": articles, "next": next, "value": searchValue}) }) -//line cmd/gopcomm/community_yap.gox:314:1 +//line cmd/gopcomm/community_yap.gox:318:1 this.Post("/api/article/commit", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:315:1 +//line cmd/gopcomm/community_yap.gox:319:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:316:1 +//line cmd/gopcomm/community_yap.gox:320:1 content := ctx.Param("content") -//line cmd/gopcomm/community_yap.gox:317:1 +//line cmd/gopcomm/community_yap.gox:321:1 title := ctx.Param("title") -//line cmd/gopcomm/community_yap.gox:318:1 +//line cmd/gopcomm/community_yap.gox:322:1 tags := ctx.Param("tags") -//line cmd/gopcomm/community_yap.gox:319:1 +//line cmd/gopcomm/community_yap.gox:323:1 abstract := ctx.Param("abstract") -//line cmd/gopcomm/community_yap.gox:320:1 +//line cmd/gopcomm/community_yap.gox:324:1 label := ctx.Param("label") -//line cmd/gopcomm/community_yap.gox:321:1 +//line cmd/gopcomm/community_yap.gox:325:1 trans, err := strconv.ParseBool(ctx.Param("trans")) -//line cmd/gopcomm/community_yap.gox:322:1 +//line cmd/gopcomm/community_yap.gox:326:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:323:1 +//line cmd/gopcomm/community_yap.gox:327:1 xLog.Error("parse bool error:", err) } -//line cmd/gopcomm/community_yap.gox:326:1 +//line cmd/gopcomm/community_yap.gox:330:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:327:1 +//line cmd/gopcomm/community_yap.gox:331:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:328:1 +//line cmd/gopcomm/community_yap.gox:332:1 xLog.Info("token", err) -//line cmd/gopcomm/community_yap.gox:329:1 +//line cmd/gopcomm/community_yap.gox:333:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "no token"}) } -//line cmd/gopcomm/community_yap.gox:334:1 +//line cmd/gopcomm/community_yap.gox:338:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:335:1 +//line cmd/gopcomm/community_yap.gox:339:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:336:1 +//line cmd/gopcomm/community_yap.gox:340:1 xLog.Info("uid", err) -//line cmd/gopcomm/community_yap.gox:337:1 +//line cmd/gopcomm/community_yap.gox:341:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:342:1 +//line cmd/gopcomm/community_yap.gox:346:1 article := &core.Article{ArticleEntry: core.ArticleEntry{ID: id, Title: title, UId: uid, Cover: ctx.Param("cover"), Tags: tags, Abstract: abstract, Label: label}, Content: content, Trans: trans} -//line cmd/gopcomm/community_yap.gox:357:1 +//line cmd/gopcomm/community_yap.gox:361:1 if trans { -//line cmd/gopcomm/community_yap.gox:358:1 +//line cmd/gopcomm/community_yap.gox:362:1 article, _ = this.community.TranslateArticle(todo, article) } -//line cmd/gopcomm/community_yap.gox:361:1 +//line cmd/gopcomm/community_yap.gox:365:1 id, err = this.community.PutArticle(todo, uid, article) -//line cmd/gopcomm/community_yap.gox:362:1 +//line cmd/gopcomm/community_yap.gox:366:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:363:1 +//line cmd/gopcomm/community_yap.gox:367:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "add failed"}) } -//line cmd/gopcomm/community_yap.gox:368:1 +//line cmd/gopcomm/community_yap.gox:372:1 ctx.Json__1(map[string]interface{}{"code": 200, "data": id}) }) -//line cmd/gopcomm/community_yap.gox:377:1 +//line cmd/gopcomm/community_yap.gox:381:1 this.Get("/user/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:378:1 +//line cmd/gopcomm/community_yap.gox:382:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:380:1 +//line cmd/gopcomm/community_yap.gox:384:1 userClaim, err := this.community.GetUserClaim(id) -//line cmd/gopcomm/community_yap.gox:381:1 +//line cmd/gopcomm/community_yap.gox:385:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:382:1 +//line cmd/gopcomm/community_yap.gox:386:1 xLog.Error("get current user error:", err) } -//line cmd/gopcomm/community_yap.gox:384:1 +//line cmd/gopcomm/community_yap.gox:388:1 // get user by token var user *core.User -//line cmd/gopcomm/community_yap.gox:386:1 +//line cmd/gopcomm/community_yap.gox:390:1 userId := "" -//line cmd/gopcomm/community_yap.gox:387:1 +//line cmd/gopcomm/community_yap.gox:391:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:388:1 +//line cmd/gopcomm/community_yap.gox:392:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:389:1 +//line cmd/gopcomm/community_yap.gox:393:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:390:1 +//line cmd/gopcomm/community_yap.gox:394:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:391:1 +//line cmd/gopcomm/community_yap.gox:395:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:393:1 +//line cmd/gopcomm/community_yap.gox:397:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:397:1 - items, next, err := this.community.GetArticlesByUid(todo, id, core.MarkBegin, limitConst) -//line cmd/gopcomm/community_yap.gox:398:1 - if err != nil { -//line cmd/gopcomm/community_yap.gox:399:1 - xLog.Error("get article list error:", err) - } //line cmd/gopcomm/community_yap.gox:401:1 - userClaimJson, err := json.Marshal(&userClaim) + items, next, err := this.community.GetArticlesByUid(todo, id, core.MarkBegin, limitConst) //line cmd/gopcomm/community_yap.gox:402:1 if err != nil { //line cmd/gopcomm/community_yap.gox:403:1 - xLog.Error("json marshal error:", err) + xLog.Error("get article list error:", err) } //line cmd/gopcomm/community_yap.gox:405:1 - itemsJson, err := json.Marshal(&items) + userClaimJson, err := json.Marshal(&userClaim) //line cmd/gopcomm/community_yap.gox:406:1 if err != nil { //line cmd/gopcomm/community_yap.gox:407:1 xLog.Error("json marshal error:", err) } //line cmd/gopcomm/community_yap.gox:409:1 + itemsJson, err := json.Marshal(&items) +//line cmd/gopcomm/community_yap.gox:410:1 + if err != nil { +//line cmd/gopcomm/community_yap.gox:411:1 + xLog.Error("json marshal error:", err) + } +//line cmd/gopcomm/community_yap.gox:413:1 ctx.Yap__1("user", map[string]interface{}{"Id": id, "CurrentUser": string(userClaimJson), "User": user, "Items": string(itemsJson), "UserId": userId, "Next": next}) }) -//line cmd/gopcomm/community_yap.gox:419:1 +//line cmd/gopcomm/community_yap.gox:423:1 this.Get("/user/edit", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:420:1 - token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:421:1 - if err != nil { -//line cmd/gopcomm/community_yap.gox:422:1 - http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) - } //line cmd/gopcomm/community_yap.gox:424:1 - gac, err := gopaccountsdk.GetClient(token.Value) + token, err := core.GetToken(ctx) //line cmd/gopcomm/community_yap.gox:425:1 if err != nil { //line cmd/gopcomm/community_yap.gox:426:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } //line cmd/gopcomm/community_yap.gox:428:1 - fullUser, err := gac.GetUser() + gac, err := gopaccountsdk.GetClient(token.Value) //line cmd/gopcomm/community_yap.gox:429:1 if err != nil { //line cmd/gopcomm/community_yap.gox:430:1 - xLog.Error("get user error:", err) -//line cmd/gopcomm/community_yap.gox:431:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } +//line cmd/gopcomm/community_yap.gox:432:1 + fullUser, err := gac.GetUser() //line cmd/gopcomm/community_yap.gox:433:1 - appInfo, err := this.community.GetApplicationInfo() -//line cmd/gopcomm/community_yap.gox:434:1 if err != nil { +//line cmd/gopcomm/community_yap.gox:434:1 + xLog.Error("get user error:", err) //line cmd/gopcomm/community_yap.gox:435:1 - xLog.Error("get application info error:", err) -//line cmd/gopcomm/community_yap.gox:436:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } +//line cmd/gopcomm/community_yap.gox:437:1 + appInfo, err := this.community.GetApplicationInfo() //line cmd/gopcomm/community_yap.gox:438:1 - appInfoStr, err := json.Marshal(*appInfo) -//line cmd/gopcomm/community_yap.gox:439:1 if err != nil { +//line cmd/gopcomm/community_yap.gox:439:1 + xLog.Error("get application info error:", err) //line cmd/gopcomm/community_yap.gox:440:1 - xLog.Error("json marshal error:", err) -//line cmd/gopcomm/community_yap.gox:441:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } +//line cmd/gopcomm/community_yap.gox:442:1 + appInfoStr, err := json.Marshal(*appInfo) //line cmd/gopcomm/community_yap.gox:443:1 - binds, err := json.Marshal(gac.GetProviderBindStatus()) -//line cmd/gopcomm/community_yap.gox:444:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:445:1 +//line cmd/gopcomm/community_yap.gox:444:1 xLog.Error("json marshal error:", err) -//line cmd/gopcomm/community_yap.gox:446:1 +//line cmd/gopcomm/community_yap.gox:445:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } +//line cmd/gopcomm/community_yap.gox:447:1 + binds, err := json.Marshal(gac.GetProviderBindStatus()) //line cmd/gopcomm/community_yap.gox:448:1 - currentUser, err := json.Marshal(fullUser) -//line cmd/gopcomm/community_yap.gox:449:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:450:1 +//line cmd/gopcomm/community_yap.gox:449:1 xLog.Error("json marshal error:", err) -//line cmd/gopcomm/community_yap.gox:451:1 +//line cmd/gopcomm/community_yap.gox:450:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } +//line cmd/gopcomm/community_yap.gox:452:1 + currentUser, err := json.Marshal(fullUser) //line cmd/gopcomm/community_yap.gox:453:1 - user := gac.GetUserSimple() + if err != nil { //line cmd/gopcomm/community_yap.gox:454:1 + xLog.Error("json marshal error:", err) +//line cmd/gopcomm/community_yap.gox:455:1 + http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) + } +//line cmd/gopcomm/community_yap.gox:457:1 + user := gac.GetUserSimple() +//line cmd/gopcomm/community_yap.gox:458:1 ctx.Yap__1("user_edit", map[string]interface{}{"UserId": user.Id, "User": user, "CurrentUser": string(currentUser), "Application": string(appInfoStr), "Binds": string(binds)}) }) -//line cmd/gopcomm/community_yap.gox:466:1 +//line cmd/gopcomm/community_yap.gox:470:1 this.Put("/api/user", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:467:1 +//line cmd/gopcomm/community_yap.gox:471:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:468:1 +//line cmd/gopcomm/community_yap.gox:472:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:469:1 +//line cmd/gopcomm/community_yap.gox:473:1 user := &core.UserInfo{Id: uid, Name: ctx.Param("name"), Birthday: ctx.Param("birthday"), Gender: ctx.Param("gender"), Phone: ctx.Param("phone"), Email: ctx.Param("email"), Avatar: ctx.Param("avatar"), Owner: ctx.Param("owner"), DisplayName: ctx.Param("name")} -//line cmd/gopcomm/community_yap.gox:480:1 +//line cmd/gopcomm/community_yap.gox:484:1 _, err = this.community.UpdateUserById(fmt.Sprintf("%s/%s", user.Owner, user.Name), user) -//line cmd/gopcomm/community_yap.gox:481:1 +//line cmd/gopcomm/community_yap.gox:485:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:482:1 +//line cmd/gopcomm/community_yap.gox:486:1 xLog.Info(err) -//line cmd/gopcomm/community_yap.gox:483:1 +//line cmd/gopcomm/community_yap.gox:487:1 ctx.Json__1(map[string]interface{}{"code": 0, "msg": "update failed"}) } -//line cmd/gopcomm/community_yap.gox:488:1 +//line cmd/gopcomm/community_yap.gox:492:1 ctx.Json__1(map[string]int{"code": 200}) }) -//line cmd/gopcomm/community_yap.gox:493:1 +//line cmd/gopcomm/community_yap.gox:497:1 this.Get("/api/user/unlink", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:494:1 +//line cmd/gopcomm/community_yap.gox:498:1 pv := ctx.Param("pv") -//line cmd/gopcomm/community_yap.gox:495:1 +//line cmd/gopcomm/community_yap.gox:499:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:496:1 +//line cmd/gopcomm/community_yap.gox:500:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:497:1 +//line cmd/gopcomm/community_yap.gox:501:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/login", http.StatusTemporaryRedirect) -//line cmd/gopcomm/community_yap.gox:498:1 +//line cmd/gopcomm/community_yap.gox:502:1 return } -//line cmd/gopcomm/community_yap.gox:500:1 +//line cmd/gopcomm/community_yap.gox:504:1 switch pv { -//line cmd/gopcomm/community_yap.gox:501:1 +//line cmd/gopcomm/community_yap.gox:505:1 case "Twitter": -//line cmd/gopcomm/community_yap.gox:502:1 +//line cmd/gopcomm/community_yap.gox:506:1 case "Facebook": -//line cmd/gopcomm/community_yap.gox:503:1 +//line cmd/gopcomm/community_yap.gox:507:1 case "Github": -//line cmd/gopcomm/community_yap.gox:504:1 +//line cmd/gopcomm/community_yap.gox:508:1 case "WeChat": -//line cmd/gopcomm/community_yap.gox:505:1 +//line cmd/gopcomm/community_yap.gox:509:1 default: -//line cmd/gopcomm/community_yap.gox:506:1 +//line cmd/gopcomm/community_yap.gox:510:1 pv = "" } -//line cmd/gopcomm/community_yap.gox:508:1 +//line cmd/gopcomm/community_yap.gox:512:1 gac, err := gopaccountsdk.GetClient(token.Value) -//line cmd/gopcomm/community_yap.gox:509:1 +//line cmd/gopcomm/community_yap.gox:513:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:510:1 +//line cmd/gopcomm/community_yap.gox:514:1 gac.UnLink(pv) } -//line cmd/gopcomm/community_yap.gox:512:1 +//line cmd/gopcomm/community_yap.gox:516:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/user/edit", http.StatusTemporaryRedirect) }) -//line cmd/gopcomm/community_yap.gox:515:1 +//line cmd/gopcomm/community_yap.gox:519:1 this.Get("/api/user/:id/articles", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:516:1 +//line cmd/gopcomm/community_yap.gox:520:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:517:1 +//line cmd/gopcomm/community_yap.gox:521:1 from := ctx.Param("from") -//line cmd/gopcomm/community_yap.gox:518:1 +//line cmd/gopcomm/community_yap.gox:522:1 limit := ctx.Param("limit") -//line cmd/gopcomm/community_yap.gox:520:1 +//line cmd/gopcomm/community_yap.gox:524:1 limitInt, err := strconv.Atoi(limit) -//line cmd/gopcomm/community_yap.gox:521:1 +//line cmd/gopcomm/community_yap.gox:525:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:522:1 +//line cmd/gopcomm/community_yap.gox:526:1 limitInt = limitConst } -//line cmd/gopcomm/community_yap.gox:524:1 +//line cmd/gopcomm/community_yap.gox:528:1 items, next, err := this.community.GetArticlesByUid(todo, id, from, limitInt) -//line cmd/gopcomm/community_yap.gox:525:1 +//line cmd/gopcomm/community_yap.gox:529:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:526:1 +//line cmd/gopcomm/community_yap.gox:530:1 xLog.Error("get article list error:", err) -//line cmd/gopcomm/community_yap.gox:527:1 +//line cmd/gopcomm/community_yap.gox:531:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": err.Error(), "total": 0}) } -//line cmd/gopcomm/community_yap.gox:533:1 +//line cmd/gopcomm/community_yap.gox:537:1 ctx.Json__1(map[string]interface{}{"code": 200, "items": items, "next": next}) }) -//line cmd/gopcomm/community_yap.gox:540:1 +//line cmd/gopcomm/community_yap.gox:544:1 this.Get("/api/user/:id/medias", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:541:1 +//line cmd/gopcomm/community_yap.gox:545:1 format := ctx.Param("format") -//line cmd/gopcomm/community_yap.gox:542:1 +//line cmd/gopcomm/community_yap.gox:546:1 uid := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:543:1 +//line cmd/gopcomm/community_yap.gox:547:1 page := ctx.Param("page") -//line cmd/gopcomm/community_yap.gox:544:1 +//line cmd/gopcomm/community_yap.gox:548:1 limit := ctx.Param("limit") -//line cmd/gopcomm/community_yap.gox:546:1 +//line cmd/gopcomm/community_yap.gox:550:1 limitInt, err := strconv.Atoi(limit) -//line cmd/gopcomm/community_yap.gox:547:1 +//line cmd/gopcomm/community_yap.gox:551:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:548:1 +//line cmd/gopcomm/community_yap.gox:552:1 limitInt = limitConst } -//line cmd/gopcomm/community_yap.gox:550:1 +//line cmd/gopcomm/community_yap.gox:554:1 pageInt, err := strconv.Atoi(page) -//line cmd/gopcomm/community_yap.gox:551:1 +//line cmd/gopcomm/community_yap.gox:555:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:552:1 +//line cmd/gopcomm/community_yap.gox:556:1 ctx.Json__1(map[string]interface{}{"code": 400, "total": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:558:1 +//line cmd/gopcomm/community_yap.gox:562:1 files, total, err := this.community.ListMediaByUserId(todo, uid, format, pageInt, limitInt) -//line cmd/gopcomm/community_yap.gox:559:1 +//line cmd/gopcomm/community_yap.gox:563:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:560:1 +//line cmd/gopcomm/community_yap.gox:564:1 ctx.Json__1(map[string]interface{}{"code": 0, "total": total, "err": err.Error()}) } else { -//line cmd/gopcomm/community_yap.gox:566:1 +//line cmd/gopcomm/community_yap.gox:570:1 ctx.Json__1(map[string]interface{}{"code": 200, "total": total, "items": files}) } }) -//line cmd/gopcomm/community_yap.gox:577:1 +//line cmd/gopcomm/community_yap.gox:581:1 this.Delete("/api/media/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:578:1 +//line cmd/gopcomm/community_yap.gox:582:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:579:1 +//line cmd/gopcomm/community_yap.gox:583:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:580:1 +//line cmd/gopcomm/community_yap.gox:584:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:581:1 +//line cmd/gopcomm/community_yap.gox:585:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:582:1 +//line cmd/gopcomm/community_yap.gox:586:1 xLog.Error("token parse error") -//line cmd/gopcomm/community_yap.gox:583:1 +//line cmd/gopcomm/community_yap.gox:587:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:588:1 +//line cmd/gopcomm/community_yap.gox:592:1 err = this.community.DelMedia(todo, uid, id) -//line cmd/gopcomm/community_yap.gox:589:1 +//line cmd/gopcomm/community_yap.gox:593:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:590:1 +//line cmd/gopcomm/community_yap.gox:594:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "delete failed"}) } else { -//line cmd/gopcomm/community_yap.gox:595:1 +//line cmd/gopcomm/community_yap.gox:599:1 ctx.Json__1(map[string]interface{}{"code": 200, "msg": "delete success"}) } }) -//line cmd/gopcomm/community_yap.gox:602:1 +//line cmd/gopcomm/community_yap.gox:606:1 this.Get("/api/translation/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:603:1 +//line cmd/gopcomm/community_yap.gox:607:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:604:1 +//line cmd/gopcomm/community_yap.gox:608:1 article, err := this.community.GetTranslateArticle(todo, id) -//line cmd/gopcomm/community_yap.gox:605:1 +//line cmd/gopcomm/community_yap.gox:609:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:606:1 +//line cmd/gopcomm/community_yap.gox:610:1 ctx.Json__1(map[string]int{"code": 0}) } -//line cmd/gopcomm/community_yap.gox:610:1 +//line cmd/gopcomm/community_yap.gox:614:1 ctx.Json__1(map[string]interface{}{"code": 200, "content": article.Content, "tags": article.Tags, "title": article.Title}) }) -//line cmd/gopcomm/community_yap.gox:618:1 +//line cmd/gopcomm/community_yap.gox:622:1 this.Post("/api/translation", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:619:1 +//line cmd/gopcomm/community_yap.gox:623:1 mdData := ctx.Param("content") -//line cmd/gopcomm/community_yap.gox:620:1 +//line cmd/gopcomm/community_yap.gox:624:1 transData, err := this.community.TranslateMarkdownText(todo, mdData, "auto", language.English) -//line cmd/gopcomm/community_yap.gox:621:1 +//line cmd/gopcomm/community_yap.gox:625:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:622:1 +//line cmd/gopcomm/community_yap.gox:626:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:627:1 +//line cmd/gopcomm/community_yap.gox:631:1 ctx.Json__1(map[string]interface{}{"code": 200, "data": transData}) }) -//line cmd/gopcomm/community_yap.gox:633:1 +//line cmd/gopcomm/community_yap.gox:637:1 this.Get("/api/media/:id/url", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:634:1 +//line cmd/gopcomm/community_yap.gox:638:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:635:1 +//line cmd/gopcomm/community_yap.gox:639:1 fileKey, err := this.community.GetMediaUrl(todo, id) -//line cmd/gopcomm/community_yap.gox:636:1 +//line cmd/gopcomm/community_yap.gox:640:1 htmlUrl := fmt.Sprintf("%s%s", domain, fileKey) -//line cmd/gopcomm/community_yap.gox:637:1 +//line cmd/gopcomm/community_yap.gox:641:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:638:1 +//line cmd/gopcomm/community_yap.gox:642:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": "have no html media"}) } -//line cmd/gopcomm/community_yap.gox:643:1 +//line cmd/gopcomm/community_yap.gox:647:1 ctx.Json__1(map[string]interface{}{"code": 200, "url": htmlUrl}) }) -//line cmd/gopcomm/community_yap.gox:649:1 +//line cmd/gopcomm/community_yap.gox:653:1 this.Get("/api/video/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:650:1 +//line cmd/gopcomm/community_yap.gox:654:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:651:1 +//line cmd/gopcomm/community_yap.gox:655:1 fileKey, err := this.community.GetMediaUrl(todo, id) -//line cmd/gopcomm/community_yap.gox:652:1 +//line cmd/gopcomm/community_yap.gox:656:1 m := make(map[string]string, 2) -//line cmd/gopcomm/community_yap.gox:653:1 +//line cmd/gopcomm/community_yap.gox:657:1 format, err := this.community.GetMediaType(todo, id) -//line cmd/gopcomm/community_yap.gox:654:1 +//line cmd/gopcomm/community_yap.gox:658:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:655:1 +//line cmd/gopcomm/community_yap.gox:659:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:660:1 +//line cmd/gopcomm/community_yap.gox:664:1 if format == "video/mp4" { -//line cmd/gopcomm/community_yap.gox:661:1 +//line cmd/gopcomm/community_yap.gox:665:1 subtitle, err := this.community.GetVideoSubtitle(todo, id) -//line cmd/gopcomm/community_yap.gox:662:1 +//line cmd/gopcomm/community_yap.gox:666:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:663:1 +//line cmd/gopcomm/community_yap.gox:667:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:664:1 +//line cmd/gopcomm/community_yap.gox:668:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:669:1 +//line cmd/gopcomm/community_yap.gox:673:1 return } -//line cmd/gopcomm/community_yap.gox:671:1 +//line cmd/gopcomm/community_yap.gox:675:1 m["subtitle"] = domain + subtitle } -//line cmd/gopcomm/community_yap.gox:673:1 +//line cmd/gopcomm/community_yap.gox:677:1 htmlUrl := fmt.Sprintf("%s%s", domain, fileKey) -//line cmd/gopcomm/community_yap.gox:674:1 +//line cmd/gopcomm/community_yap.gox:678:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:675:1 +//line cmd/gopcomm/community_yap.gox:679:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": "have no html media"}) } -//line cmd/gopcomm/community_yap.gox:680:1 +//line cmd/gopcomm/community_yap.gox:684:1 m["fileKey"] = htmlUrl -//line cmd/gopcomm/community_yap.gox:681:1 +//line cmd/gopcomm/community_yap.gox:685:1 ctx.Json__1(map[string]interface{}{"code": 200, "url": m}) }) -//line cmd/gopcomm/community_yap.gox:687:1 +//line cmd/gopcomm/community_yap.gox:691:1 this.Post("/api/media", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:688:1 +//line cmd/gopcomm/community_yap.gox:692:1 this.community.UploadFile(ctx) }) -//line cmd/gopcomm/community_yap.gox:691:1 +//line cmd/gopcomm/community_yap.gox:695:1 this.Post("/api/caption/task", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:692:1 +//line cmd/gopcomm/community_yap.gox:696:1 uid := ctx.Param("uid") -//line cmd/gopcomm/community_yap.gox:693:1 +//line cmd/gopcomm/community_yap.gox:697:1 vid := ctx.Param("vid") -//line cmd/gopcomm/community_yap.gox:695:1 +//line cmd/gopcomm/community_yap.gox:699:1 if uid == "" || vid == "" { -//line cmd/gopcomm/community_yap.gox:696:1 +//line cmd/gopcomm/community_yap.gox:700:1 ctx.Json__1(map[string]interface{}{"code": 200, "msg": "Invalid param"}) } -//line cmd/gopcomm/community_yap.gox:702:1 +//line cmd/gopcomm/community_yap.gox:706:1 if -//line cmd/gopcomm/community_yap.gox:702:1 +//line cmd/gopcomm/community_yap.gox:706:1 err := this.community.RetryCaptionGenerate(todo, uid, vid); err != nil { -//line cmd/gopcomm/community_yap.gox:703:1 +//line cmd/gopcomm/community_yap.gox:707:1 ctx.Json__1(map[string]interface{}{"code": 200, "msg": "Request task error"}) } -//line cmd/gopcomm/community_yap.gox:709:1 +//line cmd/gopcomm/community_yap.gox:713:1 ctx.Json__1(map[string]interface{}{"code": 200, "msg": "Ok"}) }) -//line cmd/gopcomm/community_yap.gox:718:1 +//line cmd/gopcomm/community_yap.gox:722:1 this.Get("/login", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:723:1 +//line cmd/gopcomm/community_yap.gox:727:1 refererURL, err := url.Parse(ctx.Request.Referer()) -//line cmd/gopcomm/community_yap.gox:724:1 +//line cmd/gopcomm/community_yap.gox:728:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:725:1 +//line cmd/gopcomm/community_yap.gox:729:1 xLog.Info("Error parsing Referer: %v", err) -//line cmd/gopcomm/community_yap.gox:726:1 +//line cmd/gopcomm/community_yap.gox:730:1 return } -//line cmd/gopcomm/community_yap.gox:729:1 +//line cmd/gopcomm/community_yap.gox:733:1 refererPath := refererURL.Path -//line cmd/gopcomm/community_yap.gox:730:1 +//line cmd/gopcomm/community_yap.gox:734:1 if refererURL.RawQuery != "" { -//line cmd/gopcomm/community_yap.gox:731:1 +//line cmd/gopcomm/community_yap.gox:735:1 refererPath = fmt.Sprintf("%s?%s", refererURL.Path, refererURL.RawQuery) } -//line cmd/gopcomm/community_yap.gox:734:1 +//line cmd/gopcomm/community_yap.gox:738:1 redirectURL := fmt.Sprintf("%s://%s/%s?origin_path=%s", refererURL.Scheme, refererURL.Host, "login/callback", url.QueryEscape(refererPath)) -//line cmd/gopcomm/community_yap.gox:736:1 +//line cmd/gopcomm/community_yap.gox:740:1 loginURL := this.community.RedirectToCasdoor(redirectURL) -//line cmd/gopcomm/community_yap.gox:737:1 +//line cmd/gopcomm/community_yap.gox:741:1 ctx.Redirect(loginURL, http.StatusFound) }) -//line cmd/gopcomm/community_yap.gox:740:1 +//line cmd/gopcomm/community_yap.gox:744:1 this.Get("/logout", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:741:1 +//line cmd/gopcomm/community_yap.gox:745:1 err := core.RemoveToken(ctx) -//line cmd/gopcomm/community_yap.gox:742:1 +//line cmd/gopcomm/community_yap.gox:746:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:743:1 +//line cmd/gopcomm/community_yap.gox:747:1 xLog.Error("remove token error:", err) } -//line cmd/gopcomm/community_yap.gox:746:1 +//line cmd/gopcomm/community_yap.gox:750:1 refererURL, err := url.Parse(ctx.Request.Referer()) -//line cmd/gopcomm/community_yap.gox:747:1 +//line cmd/gopcomm/community_yap.gox:751:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:748:1 +//line cmd/gopcomm/community_yap.gox:752:1 xLog.Info("Error parsing Referer: %v", err) -//line cmd/gopcomm/community_yap.gox:749:1 +//line cmd/gopcomm/community_yap.gox:753:1 return } -//line cmd/gopcomm/community_yap.gox:752:1 +//line cmd/gopcomm/community_yap.gox:756:1 refererPath := refererURL.Path -//line cmd/gopcomm/community_yap.gox:753:1 +//line cmd/gopcomm/community_yap.gox:757:1 if refererURL.RawQuery != "" { -//line cmd/gopcomm/community_yap.gox:754:1 +//line cmd/gopcomm/community_yap.gox:758:1 refererPath = fmt.Sprintf("%s?%s", refererURL.Path, refererURL.RawQuery) } -//line cmd/gopcomm/community_yap.gox:757:1 +//line cmd/gopcomm/community_yap.gox:761:1 http.Redirect(ctx.ResponseWriter, ctx.Request, refererPath, http.StatusFound) }) -//line cmd/gopcomm/community_yap.gox:760:1 +//line cmd/gopcomm/community_yap.gox:764:1 this.Get("/login/callback", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:761:1 +//line cmd/gopcomm/community_yap.gox:765:1 err := core.SetToken(ctx) -//line cmd/gopcomm/community_yap.gox:762:1 +//line cmd/gopcomm/community_yap.gox:766:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:763:1 +//line cmd/gopcomm/community_yap.gox:767:1 xLog.Error("set token error:", err) } -//line cmd/gopcomm/community_yap.gox:765:1 +//line cmd/gopcomm/community_yap.gox:769:1 origin_path := ctx.URL.Query().Get("origin_path") -//line cmd/gopcomm/community_yap.gox:766:1 +//line cmd/gopcomm/community_yap.gox:770:1 unurl, err := url.QueryUnescape(origin_path) -//line cmd/gopcomm/community_yap.gox:767:1 +//line cmd/gopcomm/community_yap.gox:771:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:768:1 +//line cmd/gopcomm/community_yap.gox:772:1 xLog.Info("Unurl error", err) -//line cmd/gopcomm/community_yap.gox:769:1 +//line cmd/gopcomm/community_yap.gox:773:1 unurl = "/" } -//line cmd/gopcomm/community_yap.gox:772:1 +//line cmd/gopcomm/community_yap.gox:776:1 http.Redirect(ctx.ResponseWriter, ctx.Request, unurl, http.StatusFound) }) -//line cmd/gopcomm/community_yap.gox:775:1 +//line cmd/gopcomm/community_yap.gox:779:1 this.Post("/api/article/like", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:776:1 +//line cmd/gopcomm/community_yap.gox:780:1 articleId := ctx.Param("articleId") -//line cmd/gopcomm/community_yap.gox:777:1 +//line cmd/gopcomm/community_yap.gox:781:1 articleIdInt, err := strconv.Atoi(articleId) -//line cmd/gopcomm/community_yap.gox:778:1 +//line cmd/gopcomm/community_yap.gox:782:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:779:1 +//line cmd/gopcomm/community_yap.gox:783:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:784:1 +//line cmd/gopcomm/community_yap.gox:788:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:785:1 +//line cmd/gopcomm/community_yap.gox:789:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:786:1 +//line cmd/gopcomm/community_yap.gox:790:1 xLog.Info("token", err) -//line cmd/gopcomm/community_yap.gox:787:1 +//line cmd/gopcomm/community_yap.gox:791:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": "no token"}) } -//line cmd/gopcomm/community_yap.gox:792:1 +//line cmd/gopcomm/community_yap.gox:796:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:793:1 +//line cmd/gopcomm/community_yap.gox:797:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:794:1 +//line cmd/gopcomm/community_yap.gox:798:1 ctx.Json__1(map[string]interface{}{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:799:1 +//line cmd/gopcomm/community_yap.gox:803:1 res, err := this.community.ArticleLike(todo, articleIdInt, uid) -//line cmd/gopcomm/community_yap.gox:800:1 +//line cmd/gopcomm/community_yap.gox:804:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:801:1 +//line cmd/gopcomm/community_yap.gox:805:1 ctx.Json__1(map[string]interface{}{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:806:1 +//line cmd/gopcomm/community_yap.gox:810:1 ctx.Json__1(map[string]interface{}{"code": 200, "data": res}) }) -//line cmd/gopcomm/community_yap.gox:813:1 +//line cmd/gopcomm/community_yap.gox:817:1 conf := &core.Config{} -//line cmd/gopcomm/community_yap.gox:814:1 +//line cmd/gopcomm/community_yap.gox:818:1 this.community, _ = core.New(todo, conf) -//line cmd/gopcomm/community_yap.gox:815:1 +//line cmd/gopcomm/community_yap.gox:819:1 core.CasdoorConfigInit() -//line cmd/gopcomm/community_yap.gox:818:1 +//line cmd/gopcomm/community_yap.gox:822:1 this.Handle("/", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:819:1 +//line cmd/gopcomm/community_yap.gox:823:1 ctx.Yap__1("4xx", map[string]interface{}{}) }) -//line cmd/gopcomm/community_yap.gox:822:1 +//line cmd/gopcomm/community_yap.gox:826:1 xLog.Info("Started in endpoint: ", endpoint) -//line cmd/gopcomm/community_yap.gox:825:1 +//line cmd/gopcomm/community_yap.gox:829:1 this.Run(endpoint, func(h http.Handler) http.Handler { -//line cmd/gopcomm/community_yap.gox:827:1 +//line cmd/gopcomm/community_yap.gox:831:1 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -//line cmd/gopcomm/community_yap.gox:828:1 +//line cmd/gopcomm/community_yap.gox:832:1 defer func() { -//line cmd/gopcomm/community_yap.gox:829:1 +//line cmd/gopcomm/community_yap.gox:833:1 if -//line cmd/gopcomm/community_yap.gox:829:1 +//line cmd/gopcomm/community_yap.gox:833:1 err := recover(); err != nil { -//line cmd/gopcomm/community_yap.gox:830:1 +//line cmd/gopcomm/community_yap.gox:834:1 xLog.Error(err) -//line cmd/gopcomm/community_yap.gox:831:1 +//line cmd/gopcomm/community_yap.gox:835:1 http.Redirect(w, r, "/failed", http.StatusFound) } }() -//line cmd/gopcomm/community_yap.gox:835:1 +//line cmd/gopcomm/community_yap.gox:839:1 h.ServeHTTP(w, r) }) }) diff --git a/cmd/gopcomm/yap/article_yap.html b/cmd/gopcomm/yap/article_yap.html index 8759fee..668ab39 100644 --- a/cmd/gopcomm/yap/article_yap.html +++ b/cmd/gopcomm/yap/article_yap.html @@ -200,7 +200,7 @@
123
+${ article.ViewCount }