Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Baihhh committed Jan 20, 2024
2 parents 59d15f7 + fffaf6f commit e92ed03
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 64 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: deploy

on:
push:
branches:
- 'feat/mvp-20240119'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/goplus-community:latest
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.21.6

RUN apt-get update

WORKDIR /community

# install goplus
RUN cd .. && git clone https://github.com/goplus/gop.git && cd gop && ./all.bash

# install npm
RUN apt-get install npm -y

# run goplus-community
COPY . .
CMD cd cmd/gopcomm && gop run .
10 changes: 10 additions & 0 deletions cmd/gopcomm/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Database DSN
GOP_COMMUNITY_DSN=

# Qiniu Storage
GOP_COMMUNITY_BLOBUS=
GOP_COMMUNITY_DOMAIN=

# Qiniu Dora Service
QINIU_ACCESS_KEY=
QINIU_SECRET_KEY=
19 changes: 14 additions & 5 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/goplus/community/markdown"
"github.com/goplus/community/translation"
language "golang.org/x/text/language"
_ "github.com/joho/godotenv/autoload"
)

var (
Expand Down Expand Up @@ -106,14 +107,13 @@ post "/translate", ctx => {
}
}

get "/getMedia", ctx => {
get "/getMedia/:id", ctx => {
mediaId := ctx.param("id")
// todo the err not empty return 404 for image
fileKey, _ := community.GetMediaUrl(todo, mediaId)
fileKey, _ := community.GetMediaUrl(context.Background(),mediaId)

http.Redirect(ctx.ResponseWriter, ctx.Request, "qiniu demain"+fileKey, http.StatusTemporaryRedirect)
}

post "/upload", ctx => {
file, header, err := ctx.FormFile("file")
filename := header.Filename
Expand Down Expand Up @@ -163,13 +163,22 @@ post "/upload", ctx => {
return
}

community.SaveMedia(context.Background(),cookie.Value,bytes)
id,err:=community.SaveMedia(context.Background(),cookie.Value,bytes)
if err!=nil {
log.Fatalln("save file",err.Error())
ctx.JSON(500, err.Error())
return
}
// todo append current project ip and getMedia
// sample: 127.0.0.1:8080/getMedia/ + id
ctx.JSON(200,id)
}


conf := &core.Config{}
community, _ = core.New(todo, conf)
trans = translation.New(os.Getenv("NIUTRANS_API_KEY"), "", "")

s3 := os.Getenv("S3_BUCKET")
println s3
println "start"
run ":8080"
128 changes: 72 additions & 56 deletions cmd/gopcomm/gop_autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,121 +11,122 @@ import (
"github.com/goplus/community/internal/core"
"github.com/goplus/community/translation"
"golang.org/x/text/language"
_ "github.com/joho/godotenv/autoload"
)

type community struct {
yap.App
community *core.Community
trans *translation.Engine
}
//line cmd/gopcomm/community_yap.gox:20
//line cmd/gopcomm/community_yap.gox:21
func (this *community) MainEntry() {
//line cmd/gopcomm/community_yap.gox:20:1
//line cmd/gopcomm/community_yap.gox:21:1
todo := context.TODO()
//line cmd/gopcomm/community_yap.gox:22:1
this.Get("/p/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:23:1
id := ctx.Param("id")
this.Get("/p/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:24:1
article, _ := this.community.Article(todo, id)
id := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:25:1
article, _ := this.community.Article(todo, id)
//line cmd/gopcomm/community_yap.gox:26:1
ctx.Yap__1("article", map[string]string{"ID": id, "Title": article.Title, "Content": article.Content})
})
//line cmd/gopcomm/community_yap.gox:31:1
this.Get("/add", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:32:1
this.Get("/add", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:33:1
ctx.Yap__1("add", map[string]interface {
}{})
})
//line cmd/gopcomm/community_yap.gox:35:1
this.Get("/", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:36:1
articles, _, _ := this.community.ListArticle(todo, core.MarkBegin, 20)
this.Get("/", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:37:1
articles, _, _ := this.community.ListArticle(todo, core.MarkBegin, 20)
//line cmd/gopcomm/community_yap.gox:38:1
ctx.Yap__1("home", map[string][]*core.ArticleEntry{"Items": articles})
})
//line cmd/gopcomm/community_yap.gox:41:1
this.Get("/edit", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:42:1
uid := "3"
this.Get("/edit", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:43:1
id := ctx.Param("id")
uid := "3"
//line cmd/gopcomm/community_yap.gox:44:1
id := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:45:1
doc := map[string]string{"ID": id}
//line cmd/gopcomm/community_yap.gox:47:1
if id != "" {
//line cmd/gopcomm/community_yap.gox:48:1
if id != "" {
//line cmd/gopcomm/community_yap.gox:49:1
if
//line cmd/gopcomm/community_yap.gox:48:1
//line cmd/gopcomm/community_yap.gox:49:1
editable, _ := this.community.CanEditable(todo, uid, id); !editable {
//line cmd/gopcomm/community_yap.gox:50:1
log.Println("no permissions")
//line cmd/gopcomm/community_yap.gox:51:1
log.Println("no permissions")
//line cmd/gopcomm/community_yap.gox:52:1
return
}
//line cmd/gopcomm/community_yap.gox:53:1
article, _ := this.community.Article(todo, id)
//line cmd/gopcomm/community_yap.gox:54:1
doc["Title"] = article.Title
article, _ := this.community.Article(todo, id)
//line cmd/gopcomm/community_yap.gox:55:1
doc["Title"] = article.Title
//line cmd/gopcomm/community_yap.gox:56:1
doc["Content"] = article.Content
}
//line cmd/gopcomm/community_yap.gox:57:1
//line cmd/gopcomm/community_yap.gox:58:1
ctx.Yap__1("edit", doc)
})
//line cmd/gopcomm/community_yap.gox:60:1
this.Get("/getTrans", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:61:1
id := ctx.Param("id")
this.Get("/getTrans", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:62:1
htmlUrl, _ := this.community.TransHtmlUrl(todo, id)
id := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:63:1
htmlUrl, _ := this.community.TransHtmlUrl(todo, id)
//line cmd/gopcomm/community_yap.gox:64:1
ctx.Json__1(map[string]string{"data": htmlUrl})
})
//line cmd/gopcomm/community_yap.gox:69:1
//line cmd/gopcomm/community_yap.gox:70:1
this.Post("/commit", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:71:1
trans := ctx.Param("trans")
//line cmd/gopcomm/community_yap.gox:72:1
id := ctx.Param("id")
trans := ctx.Param("trans")
//line cmd/gopcomm/community_yap.gox:73:1
mdData := ctx.Param("content")
id := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:74:1
mdData := ctx.Param("content")
//line cmd/gopcomm/community_yap.gox:75:1
htmlData := ctx.Param("html")
//line cmd/gopcomm/community_yap.gox:76:1
//line cmd/gopcomm/community_yap.gox:77:1
uid := "12"
//line cmd/gopcomm/community_yap.gox:78:1
//line cmd/gopcomm/community_yap.gox:79:1
article := &core.Article{ArticleEntry: core.ArticleEntry{ID: id, Title: ctx.Param("title"), UId: uid, Cover: ctx.Param("cover"), Tags: ctx.Param("tags")}, Content: mdData, HtmlData: htmlData}
//line cmd/gopcomm/community_yap.gox:89:1
id, _ = this.community.PutArticle(todo, uid, trans, article)
//line cmd/gopcomm/community_yap.gox:90:1
article.ID = id
id, _ = this.community.PutArticle(todo, uid, trans, article)
//line cmd/gopcomm/community_yap.gox:91:1
article.ID = id
//line cmd/gopcomm/community_yap.gox:92:1
ctx.Yap__1("edit", *article)
})
//line cmd/gopcomm/community_yap.gox:95:1
//line cmd/gopcomm/community_yap.gox:96:1
this.Post("/translate", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:97:1
uid := "1"
//line cmd/gopcomm/community_yap.gox:98:1
mdData := ctx.Param("content")
uid := "1"
//line cmd/gopcomm/community_yap.gox:99:1
htmlData := ctx.Param("html")
mdData := ctx.Param("content")
//line cmd/gopcomm/community_yap.gox:100:1
htmlData := ctx.Param("html")
//line cmd/gopcomm/community_yap.gox:101:1
id, _ := this.community.SaveHtml(todo, uid, htmlData, mdData)
//line cmd/gopcomm/community_yap.gox:102:1
transData, _ := this.trans.TranslateMarkdownText(mdData, language.Chinese, language.English)
//line cmd/gopcomm/community_yap.gox:103:1
transData, _ := this.trans.TranslateMarkdownText(mdData, language.Chinese, language.English)
//line cmd/gopcomm/community_yap.gox:104:1
ctx.Json__1(map[string]interface {
}{"id": id, "data": transData})
})
//line cmd/gopcomm/community_yap.gox:109:1
this.Get("/getMedia", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:110:1
this.Get("/getMedia/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:111:1
mediaId := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:112:1
fileKey, _ := this.community.GetMediaUrl(todo, mediaId)
//line cmd/gopcomm/community_yap.gox:114:1
//line cmd/gopcomm/community_yap.gox:113:1
fileKey, _ := this.community.GetMediaUrl(context.Background(), mediaId)
//line cmd/gopcomm/community_yap.gox:115:1
http.Redirect(ctx.ResponseWriter, ctx.Request, "qiniu demain"+fileKey, http.StatusTemporaryRedirect)
})
//line cmd/gopcomm/community_yap.gox:117:1
Expand Down Expand Up @@ -206,17 +207,32 @@ func (this *community) MainEntry() {
return
}
//line cmd/gopcomm/community_yap.gox:166:1
this.community.SaveMedia(context.Background(), cookie.Value, bytes)
})
id, err := this.community.SaveMedia(context.Background(), cookie.Value, bytes)
//line cmd/gopcomm/community_yap.gox:167:1
if err != nil {
//line cmd/gopcomm/community_yap.gox:168:1
log.Fatalln("save file", err.Error())
//line cmd/gopcomm/community_yap.gox:169:1
ctx.JSON(500, err.Error())
//line cmd/gopcomm/community_yap.gox:170:1
return
}
//line cmd/gopcomm/community_yap.gox:174:1
ctx.JSON(200, id)
})
//line cmd/gopcomm/community_yap.gox:177:1
conf := &core.Config{}
//line cmd/gopcomm/community_yap.gox:171:1
//line cmd/gopcomm/community_yap.gox:178:1
this.community, _ = core.New(todo, conf)
//line cmd/gopcomm/community_yap.gox:172:1
//line cmd/gopcomm/community_yap.gox:179:1
this.trans = translation.New(os.Getenv("NIUTRANS_API_KEY"), "", "")
//line cmd/gopcomm/community_yap.gox:174:1
//line cmd/gopcomm/community_yap.gox:181:1
s3 := os.Getenv("S3_BUCKET")
//line cmd/gopcomm/community_yap.gox:182:1
fmt.Println(s3)
//line cmd/gopcomm/community_yap.gox:183:1
fmt.Println("start")
//line cmd/gopcomm/community_yap.gox:175:1
//line cmd/gopcomm/community_yap.gox:184:1
this.Run__1(":8080")
}
func main() {
Expand Down
1 change: 1 addition & 0 deletions cmd/gopcomm/yap/static/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello!!!
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@ require (
golang.org/x/text v0.14.0
)

require github.com/qiniu/go-cdk-driver v0.1.0
require (
github.com/casdoor/casdoor-go-sdk v0.35.0
github.com/qiniu/go-cdk-driver v0.1.0
)

replace github.com/goplus/yap => github.com/IRONICBo/yap v0.6.0

require (
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.151.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
Loading

0 comments on commit e92ed03

Please sign in to comment.