-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: MVP1 development tasks. #54
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
20abcca
use gop to build file and Distinguish between the deployment of diffe…
linjie7674 1c5dc21
Merge pull request #26 from linjie7674/bugfix/deploy
IRONICBo 1d47835
feat: Add logout api.
IRONICBo a63c48e
update
linjie7674 cfc86ef
Get the content of the branch name with a slash at the end as the bra…
linjie7674 8d8ec8b
add share protocol
LiusCraft e81b98d
Merge pull request #28 from linjie7674/bugfix/push_docker
IRONICBo 29b5300
Merge pull request #29 from LiusCraft/docs/share
IRONICBo 567b344
Merge branch 'dev' into docs/function-modules
IRONICBo 633a4f1
docs: Update arch and translation.
IRONICBo 86569f1
docs: update web module
Kasey0727 c528c9c
Merge pull request #9 from Kasey0727/main
Baihhh 259c6bc
Merge pull request #8 from IRONICBo/docs/function-modules
Baihhh dbef2ba
fix: Update to xlog.
IRONICBo 2d5a618
fix: Refresh static path.
IRONICBo 6a2829d
chore: Update vue demo.
IRONICBo 19bb76f
Merge branch 'merge' into feat/mvp-20240119
IRONICBo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ import ( | |
"github.com/goplus/community/markdown" | ||
"github.com/goplus/community/translation" | ||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" | ||
"go.uber.org/zap" | ||
language "golang.org/x/text/language" | ||
_ "github.com/joho/godotenv/autoload" | ||
"github.com/qiniu/x/xlog" | ||
) | ||
|
||
var ( | ||
|
@@ -28,11 +28,11 @@ const ( | |
todo := context.TODO() | ||
endpoint := os.Getenv("GOP_COMMUNITY_ENDPOINT") | ||
domain := os.Getenv("GOP_COMMUNITY_DOMAIN") | ||
logger, _ := zap.NewProduction() | ||
defer logger.Sync() | ||
zlog := logger.Sugar() | ||
xLog := xlog.New("") | ||
|
||
static "/" | ||
// Modify / to /static | ||
// Support 404 handle | ||
static "/static" | ||
|
||
get "/success", ctx => { | ||
ctx.yap "2xx", {} | ||
|
@@ -46,6 +46,10 @@ get "/failed", ctx => { | |
ctx.yap "5xx", {} | ||
} | ||
|
||
get "/demo", ctx => { | ||
ctx.yap "demo", {} | ||
} | ||
|
||
get "/p/:id", ctx => { | ||
// todo middleware | ||
// Get User Info | ||
|
@@ -54,7 +58,7 @@ get "/p/:id", ctx => { | |
if err == nil { | ||
user, err = community.getUser(token.Value) | ||
if err != nil { | ||
zlog.Error("get user error:", err) | ||
xLog.Error("get user error:", err) | ||
} | ||
} | ||
|
||
|
@@ -87,7 +91,7 @@ get "/user/:id", ctx => { | |
// Get current User Info by id | ||
userClaim, err := community.getUserClaim(id) | ||
if err != nil { | ||
zlog.Error("get current user error:", err) | ||
xLog.Error("get current user error:", err) | ||
} | ||
// todo middleware | ||
// get user by token | ||
|
@@ -96,7 +100,7 @@ get "/user/:id", ctx => { | |
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handle |
||
user, err = community.getUser(token.Value) | ||
if err != nil { | ||
zlog.Error("get user error:", err) | ||
xLog.Error("get user error:", err) | ||
} | ||
} | ||
// get article list published by uid | ||
|
@@ -124,7 +128,7 @@ get "/", ctx => { | |
if err == nil { | ||
user, err = community.getUser(token.Value) | ||
if err != nil { | ||
zlog.Error("get user error:", err) | ||
xLog.Error("get user error:", err) | ||
} | ||
} | ||
|
||
|
@@ -172,7 +176,7 @@ get "/search", ctx => { | |
if err == nil { | ||
user, err = community.getUser(token.Value) | ||
if err != nil { | ||
zlog.Error("get user error:", err) | ||
xLog.Error("get user error:", err) | ||
} | ||
} | ||
|
||
|
@@ -206,7 +210,7 @@ get "/edit/:id", ctx => { | |
id := ctx.param("id") | ||
if id != "" { | ||
if editable, _ := community.canEditable(todo, uid, id); !editable { | ||
zlog.Error("no permissions") | ||
xLog.Error("no permissions") | ||
http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) | ||
} | ||
article, _ := community.article(todo, id) | ||
|
@@ -340,15 +344,15 @@ post "/upload", ctx => { | |
ctx.ParseMultipartForm(10 << 20) | ||
|
||
if err != nil { | ||
zlog.Error("upload file error:", filename) | ||
xLog.Error("upload file error:", filename) | ||
ctx.JSON(500, err.Error()) | ||
return | ||
} | ||
|
||
|
||
dst, err := os.Create(filename) | ||
if err != nil { | ||
zlog.Error("create file error:", file) | ||
xLog.Error("create file error:", file) | ||
ctx.JSON(500, err.Error()) | ||
return | ||
} | ||
|
@@ -357,21 +361,21 @@ post "/upload", ctx => { | |
dst.Close() | ||
err = os.Remove(filename) | ||
if err != nil { | ||
zlog.Error("delete file error:", filename) | ||
xLog.Error("delete file error:", filename) | ||
return | ||
} | ||
}() | ||
|
||
|
||
_, err = io.Copy(dst, file) | ||
if err != nil { | ||
zlog.Error("copy file errer:", filename) | ||
xLog.Error("copy file errer:", filename) | ||
ctx.JSON(500, err.Error()) | ||
return | ||
} | ||
bytes, err := os.ReadFile(filename) | ||
if err != nil { | ||
zlog.Error("read file errer:", filename) | ||
xLog.Error("read file errer:", filename) | ||
ctx.JSON(500, err.Error()) | ||
return | ||
} | ||
|
@@ -391,7 +395,7 @@ post "/upload", ctx => { | |
} | ||
id,err:=community.SaveMedia(context.Background(), uid, bytes) | ||
if err!=nil { | ||
zlog.Error("save file",err.Error()) | ||
xLog.Error("save file",err.Error()) | ||
ctx.JSON(500, err.Error()) | ||
return | ||
} | ||
|
@@ -402,19 +406,36 @@ post "/upload", ctx => { | |
|
||
get "/login", ctx => { | ||
// Get URL from query string | ||
redirectURL := ctx.URL.Query().Get("redirect_url") | ||
// redirectURL := ctx.URL.Query().Get("redirect_url") | ||
// Get current request page URL from | ||
// Concatenate the current request page URL from refer | ||
redirectURL := fmt.Sprintf("%s/%s", ctx.Request.Referer() + "callback") | ||
|
||
loginURL := community.RedirectToCasdoor(redirectURL) | ||
ctx.Redirect loginURL, http.StatusFound | ||
} | ||
|
||
get "/logout", ctx => { | ||
tokenCookie, err := ctx.Request.Cookie("token") | ||
if err != nil { | ||
xLog.Error("get token error:", err) | ||
} | ||
|
||
// Delete token | ||
tokenCookie.MaxAge = -1 | ||
http.SetCookie(ctx.ResponseWriter, tokenCookie) | ||
|
||
// Redirect to home page | ||
http.Redirect(ctx.ResponseWriter, ctx.Request, fmt.Sprintf("http://localhost:8080"), http.StatusFound) | ||
} | ||
|
||
get "/callback", ctx => { | ||
code :=ctx.URL.Query().Get("code") | ||
state :=ctx.URL.Query().Get("state") | ||
|
||
token, error := community.GetAccessToken(code, state) | ||
if error != nil { | ||
zlog.Error("err",error) // Redirect to login | ||
xLog.Error("err",error) // Redirect to login | ||
} | ||
|
||
cookie := http.Cookie{ | ||
|
@@ -427,7 +448,7 @@ get "/callback", ctx => { | |
|
||
// Redirect to home page | ||
// TODO: Get redirect URL from state | ||
http.Redirect(ctx.ResponseWriter, ctx.Request, fmt.Sprintf("http://localhost:8080?token=%s", token.AccessToken), http.StatusFound) | ||
http.Redirect(ctx.ResponseWriter, ctx.Request, fmt.Sprintf("http://localhost:8080"), http.StatusFound) | ||
} | ||
|
||
conf := &core.Config{} | ||
|
@@ -436,11 +457,11 @@ trans = translation.New(os.Getenv("NIUTRANS_API_KEY"), "", "") | |
core.CasdoorConfigInit() | ||
|
||
// 404 | ||
// handle "/",ctx => { | ||
// ctx.yap "4xx", {} | ||
// } | ||
handle "/",ctx => { | ||
ctx.yap "4xx", {} | ||
} | ||
|
||
zlog.Info "Started in endpoint: ", endpoint | ||
xLog.Info "Started in endpoint: ", endpoint | ||
|
||
// 500 | ||
run(endpoint, func(h http.Handler) http.Handler { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there no reverse judgment? like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will update it.