From d57dfae556ed5e0922a7125612f7f6fcfafe51ae Mon Sep 17 00:00:00 2001 From: Baihhh <2542274498@qq.com> Date: Mon, 19 Feb 2024 18:39:03 +0800 Subject: [PATCH] fix: add article --- cmd/gopcomm/gop_autogen.go | 186 +++++++++++++++++----------------- cmd/gopcomm/yap/edit_yap.html | 29 ++---- internal/core/community.go | 9 +- 3 files changed, 103 insertions(+), 121 deletions(-) diff --git a/cmd/gopcomm/gop_autogen.go b/cmd/gopcomm/gop_autogen.go index 4b4c7689..a2674b00 100644 --- a/cmd/gopcomm/gop_autogen.go +++ b/cmd/gopcomm/gop_autogen.go @@ -204,237 +204,237 @@ func (this *community) MainEntry() { //line cmd/gopcomm/community_yap.gox:167:1 err = this.community.DeleteArticle(todo, uid, id) //line cmd/gopcomm/community_yap.gox:168:1 - xLog.Info("err", err) -//line cmd/gopcomm/community_yap.gox:169:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:170:1 +//line cmd/gopcomm/community_yap.gox:169:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "delete failed"}) } else { -//line cmd/gopcomm/community_yap.gox:175:1 +//line cmd/gopcomm/community_yap.gox:174:1 ctx.Json__1(map[string]interface { }{"code": 200, "msg": "delete success"}) } }) -//line cmd/gopcomm/community_yap.gox:182:1 +//line cmd/gopcomm/community_yap.gox:181:1 this.Get("/medias", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:183:1 +//line cmd/gopcomm/community_yap.gox:182:1 format := ctx.Param("format") -//line cmd/gopcomm/community_yap.gox:184:1 +//line cmd/gopcomm/community_yap.gox:183:1 uid := ctx.Param("uid") -//line cmd/gopcomm/community_yap.gox:185:1 +//line cmd/gopcomm/community_yap.gox:184:1 files, err := this.community.ListMediaByUserId(todo, uid, format) -//line cmd/gopcomm/community_yap.gox:186:1 +//line cmd/gopcomm/community_yap.gox:185:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:187:1 +//line cmd/gopcomm/community_yap.gox:186:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "get media failed"}) } else { -//line cmd/gopcomm/community_yap.gox:192:1 +//line cmd/gopcomm/community_yap.gox:191:1 ctx.Json__1(map[string]interface { }{"code": 200, "items": files}) } }) -//line cmd/gopcomm/community_yap.gox:199:1 +//line cmd/gopcomm/community_yap.gox:198:1 this.Get("/delMedia", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:200:1 +//line cmd/gopcomm/community_yap.gox:199:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:201:1 +//line cmd/gopcomm/community_yap.gox:200:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:202:1 +//line cmd/gopcomm/community_yap.gox:201:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:203:1 +//line cmd/gopcomm/community_yap.gox:202:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:204:1 +//line cmd/gopcomm/community_yap.gox:203:1 xLog.Error("token parse error") -//line cmd/gopcomm/community_yap.gox:205:1 +//line cmd/gopcomm/community_yap.gox:204:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:210:1 +//line cmd/gopcomm/community_yap.gox:209:1 err = this.community.DelMedia(todo, uid, id) -//line cmd/gopcomm/community_yap.gox:211:1 +//line cmd/gopcomm/community_yap.gox:210:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:212:1 +//line cmd/gopcomm/community_yap.gox:211:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "delete failed"}) } else { -//line cmd/gopcomm/community_yap.gox:217:1 +//line cmd/gopcomm/community_yap.gox:216:1 ctx.Json__1(map[string]interface { }{"code": 200, "msg": "delete success"}) } }) -//line cmd/gopcomm/community_yap.gox:224:1 +//line cmd/gopcomm/community_yap.gox:223:1 this.Get("/", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:226:1 +//line cmd/gopcomm/community_yap.gox:225:1 // Get User Info var user *core.User -//line cmd/gopcomm/community_yap.gox:227:1 +//line cmd/gopcomm/community_yap.gox:226:1 userId := "" -//line cmd/gopcomm/community_yap.gox:228:1 +//line cmd/gopcomm/community_yap.gox:227:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:229:1 +//line cmd/gopcomm/community_yap.gox:228:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:230:1 +//line cmd/gopcomm/community_yap.gox:229:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:231:1 +//line cmd/gopcomm/community_yap.gox:230:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:232:1 +//line cmd/gopcomm/community_yap.gox:231:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:234:1 +//line cmd/gopcomm/community_yap.gox:233:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:238:1 +//line cmd/gopcomm/community_yap.gox:237:1 articles, next, _ := this.community.ListArticle(todo, core.MarkBegin, limitConst, "") -//line cmd/gopcomm/community_yap.gox:239:1 +//line cmd/gopcomm/community_yap.gox:238:1 articlesJson, _ := json.Marshal(&articles) -//line cmd/gopcomm/community_yap.gox:240:1 +//line cmd/gopcomm/community_yap.gox:239:1 ctx.Yap__1("home", map[string]interface { }{"UserId": userId, "User": user, "Items": strings.Replace(string(articlesJson), `\"`, `"`, -1), "Next": next}) }) -//line cmd/gopcomm/community_yap.gox:248:1 +//line cmd/gopcomm/community_yap.gox:247:1 this.Get("/get", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:249:1 +//line cmd/gopcomm/community_yap.gox:248:1 from := ctx.Param("from") -//line cmd/gopcomm/community_yap.gox:250:1 +//line cmd/gopcomm/community_yap.gox:249:1 limit := ctx.Param("limit") -//line cmd/gopcomm/community_yap.gox:251:1 +//line cmd/gopcomm/community_yap.gox:250:1 searchValue := ctx.Param("value") -//line cmd/gopcomm/community_yap.gox:253:1 +//line cmd/gopcomm/community_yap.gox:252:1 limitInt, err := strconv.Atoi(limit) -//line cmd/gopcomm/community_yap.gox:254:1 +//line cmd/gopcomm/community_yap.gox:253:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:255:1 +//line cmd/gopcomm/community_yap.gox:254:1 limitInt = limitConst } -//line cmd/gopcomm/community_yap.gox:258:1 +//line cmd/gopcomm/community_yap.gox:257:1 articles, next, _ := this.community.ListArticle(todo, from, limitInt, searchValue) -//line cmd/gopcomm/community_yap.gox:259:1 +//line cmd/gopcomm/community_yap.gox:258:1 ctx.Json__1(map[string]interface { }{"code": 200, "items": articles, "next": next, "value": searchValue}) }) -//line cmd/gopcomm/community_yap.gox:267:1 +//line cmd/gopcomm/community_yap.gox:266:1 this.Get("/search", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:268:1 +//line cmd/gopcomm/community_yap.gox:267:1 searchValue := ctx.Param("value") -//line cmd/gopcomm/community_yap.gox:277:1 +//line cmd/gopcomm/community_yap.gox:276:1 // todo middleware var user *core.User -//line cmd/gopcomm/community_yap.gox:278:1 +//line cmd/gopcomm/community_yap.gox:277:1 userId := "" -//line cmd/gopcomm/community_yap.gox:279:1 +//line cmd/gopcomm/community_yap.gox:278:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:280:1 +//line cmd/gopcomm/community_yap.gox:279:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:281:1 +//line cmd/gopcomm/community_yap.gox:280:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:282:1 +//line cmd/gopcomm/community_yap.gox:281:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:283:1 +//line cmd/gopcomm/community_yap.gox:282:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:285:1 +//line cmd/gopcomm/community_yap.gox:284:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:289:1 +//line cmd/gopcomm/community_yap.gox:288:1 articles, next, _ := this.community.ListArticle(todo, core.MarkBegin, limitConst, searchValue) -//line cmd/gopcomm/community_yap.gox:290:1 +//line cmd/gopcomm/community_yap.gox:289:1 articlesJson, _ := json.Marshal(&articles) -//line cmd/gopcomm/community_yap.gox:291:1 +//line cmd/gopcomm/community_yap.gox:290:1 ctx.Yap__1("home", map[string]interface { }{"UserId": userId, "User": user, "Items": strings.Replace(string(articlesJson), `\"`, `"`, -1), "Value": searchValue, "Next": next}) }) -//line cmd/gopcomm/community_yap.gox:300:1 +//line cmd/gopcomm/community_yap.gox:299:1 this.Get("/edit/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:301:1 +//line cmd/gopcomm/community_yap.gox:300:1 var user *core.User -//line cmd/gopcomm/community_yap.gox:302:1 +//line cmd/gopcomm/community_yap.gox:301:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:303:1 +//line cmd/gopcomm/community_yap.gox:302:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:304:1 +//line cmd/gopcomm/community_yap.gox:303:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:305:1 +//line cmd/gopcomm/community_yap.gox:304:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:306:1 +//line cmd/gopcomm/community_yap.gox:305:1 xLog.Error("get user error:", err) } } -//line cmd/gopcomm/community_yap.gox:310:1 +//line cmd/gopcomm/community_yap.gox:309:1 uid := user.Id -//line cmd/gopcomm/community_yap.gox:311:1 +//line cmd/gopcomm/community_yap.gox:310:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:312:1 +//line cmd/gopcomm/community_yap.gox:311:1 if id != "" { -//line cmd/gopcomm/community_yap.gox:313:1 +//line cmd/gopcomm/community_yap.gox:312:1 if -//line cmd/gopcomm/community_yap.gox:313:1 +//line cmd/gopcomm/community_yap.gox:312:1 editable, _ := this.community.CanEditable(todo, uid, id); !editable { -//line cmd/gopcomm/community_yap.gox:314:1 +//line cmd/gopcomm/community_yap.gox:313:1 xLog.Error("no permissions") -//line cmd/gopcomm/community_yap.gox:315:1 +//line cmd/gopcomm/community_yap.gox:314:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:317:1 +//line cmd/gopcomm/community_yap.gox:316:1 article, _ := this.community.Article(todo, id) -//line cmd/gopcomm/community_yap.gox:318:1 +//line cmd/gopcomm/community_yap.gox:317:1 articleJson, _ := json.Marshal(&article) -//line cmd/gopcomm/community_yap.gox:319:1 +//line cmd/gopcomm/community_yap.gox:318:1 ctx.Yap__1("edit", map[string]interface { }{"User": user, "Article": strings.Replace(string(articleJson), `\"`, `"`, -1)}) } }) -//line cmd/gopcomm/community_yap.gox:326:1 +//line cmd/gopcomm/community_yap.gox:325:1 this.Get("/getTrans", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:327:1 +//line cmd/gopcomm/community_yap.gox:326:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:328:1 +//line cmd/gopcomm/community_yap.gox:327:1 htmlUrl, err := this.community.TransHtmlUrl(todo, id) -//line cmd/gopcomm/community_yap.gox:329:1 +//line cmd/gopcomm/community_yap.gox:328:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:330:1 +//line cmd/gopcomm/community_yap.gox:329:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:335:1 +//line cmd/gopcomm/community_yap.gox:334:1 ctx.Json__1(map[string]interface { }{"code": 200, "data": htmlUrl}) }) -//line cmd/gopcomm/community_yap.gox:342:1 +//line cmd/gopcomm/community_yap.gox:341:1 this.Post("/commit", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:345:1 +//line cmd/gopcomm/community_yap.gox:344:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:346:1 +//line cmd/gopcomm/community_yap.gox:345:1 mdData := ctx.Param("content") -//line cmd/gopcomm/community_yap.gox:347:1 +//line cmd/gopcomm/community_yap.gox:346:1 transData := ctx.Param("trans_data") -//line cmd/gopcomm/community_yap.gox:349:1 +//line cmd/gopcomm/community_yap.gox:348:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:350:1 +//line cmd/gopcomm/community_yap.gox:349:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:351:1 +//line cmd/gopcomm/community_yap.gox:350:1 xLog.Info("token", err) -//line cmd/gopcomm/community_yap.gox:352:1 +//line cmd/gopcomm/community_yap.gox:351:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "no token"}) } -//line cmd/gopcomm/community_yap.gox:357:1 +//line cmd/gopcomm/community_yap.gox:356:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:358:1 +//line cmd/gopcomm/community_yap.gox:357:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:359:1 +//line cmd/gopcomm/community_yap.gox:358:1 xLog.Info("uid", err) -//line cmd/gopcomm/community_yap.gox:360:1 +//line cmd/gopcomm/community_yap.gox:359:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:366:1 +//line cmd/gopcomm/community_yap.gox:365:1 article := &core.Article{ArticleEntry: core.ArticleEntry{ID: id, Title: ctx.Param("title"), UId: uid, Cover: ctx.Param("cover"), Tags: ctx.Param("tags"), Abstract: ctx.Param("abstract")}, Content: mdData, TransContent: transData} +//line cmd/gopcomm/community_yap.gox:377:1 + id, err = this.community.PutArticle(todo, uid, article) //line cmd/gopcomm/community_yap.gox:378:1 - id, _ = this.community.PutArticle(todo, uid, article) + xLog.Info("err", err) //line cmd/gopcomm/community_yap.gox:379:1 ctx.Json__1(map[string]interface { }{"code": 200, "data": id}) diff --git a/cmd/gopcomm/yap/edit_yap.html b/cmd/gopcomm/yap/edit_yap.html index 4ee1d5f6..3d87f945 100644 --- a/cmd/gopcomm/yap/edit_yap.html +++ b/cmd/gopcomm/yap/edit_yap.html @@ -142,12 +142,11 @@ - @@ -155,9 +154,6 @@ - - click or drag a file here to upload - @@ -200,16 +196,17 @@ tags: [], abstract: '' }); - const cover = ref(); let coverUrl = ""; let content = "" // edit - const editId = ref(0) const isAdd = window.location.href.indexOf("edit") !== -1 ? ref(false) : ref(true) const article = isAdd.value ? {} : JSON.parse("{{.Article}}") - const fileList = ref([]) - + const fileList = isAdd.value ? ref([]) : ref([{ + id: "cover", + status: "finished", + url: article.Cover, + }]) // a form to be submitted to backend const formData = new FormData(); @@ -236,8 +233,8 @@ } console.log('tags:', tags.value); - if(isAdd){ - formData.append("id",editId.value) + if(!isAdd.value){ + formData.append("id",article.ID) } // organize the formData @@ -317,7 +314,6 @@ return resUrl.json(); }) .then(todosUrl => { - console.log("url",todosUrl) if(todosUrl.code === 200){ coverUrl = todosUrl.url } @@ -343,7 +339,6 @@ return { showModal, articleForm, - cover, isAdd, fileList, } @@ -364,13 +359,7 @@ articleForm.value.title = article.Title articleForm.value.tags = article.Tags.split(";") articleForm.value.abstract = article.Abstract - editId.value = article.ID coverUrl = article.Cover - fileList.value.push({ - id: "c", - status: "finished", - url: article.Cover - }) window.GoplusMarkdown.MarkdownEditor.methods.setMarkdown(article.Content) } }, diff --git a/internal/core/community.go b/internal/core/community.go index 1e97cc92..56f1bc7d 100644 --- a/internal/core/community.go +++ b/internal/core/community.go @@ -264,15 +264,8 @@ func (p *Community) PutArticle(ctx context.Context, uid string, article *Article } return strconv.FormatInt(idInt, 10), nil } - // if trans != "" { - // // add article except html_id, content (trans) - // sqlStr := "update article set title=?, mtime=?, ctime=?, tags=?, abstract=?, cover=?, trans_content=?, trans_html_id=? where id=?" - // _, err = p.db.Exec(sqlStr, &article.Title, time.Now(), time.Now(), &article.Tags, &article.Abstract, &article.Cover, &article.Content, htmlId, &article.ID) - // return article.ID, err - // } - // edit article - sqlStr := "update article set title=?, mtime=?, tags=?, abstract=?, cover=?, content=?, trans_content where id=?" + sqlStr := "update article set title=?, mtime=?, tags=?, abstract=?, cover=?, content=?, trans_content=? where id=?" _, err = p.db.Exec(sqlStr, &article.Title, time.Now(), &article.Tags, &article.Abstract, &article.Cover, &article.Content, &article.TransContent, &article.ID) return article.ID, err }