Skip to content

Commit

Permalink
fix image url
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanh Nguyen committed Mar 31, 2023
1 parent 7582018 commit 3e37a01
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 520 deletions.
32 changes: 0 additions & 32 deletions be-api/config/conf.d/i18n/all_in_one.lang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,12 @@
# !!!multi-documents in one file is not supported yet!!!
en:
_display: "English"
error_exter_not_enabled: "Exter login is not enabled."
error_exter_login_failed:
zero: "Exter login failed, please retry."
other: "Exter login failed (code {{.code}}): {{.message}}."
error_exter_token_validation_failed: "Exter token validation failed with error: {{.error}}."
error_user_creation_failed:
zero: "User account initialization failed, please retry."
other: "User account initialization failed: {{.error}}."
error_jwt_generation_failed: "Error generating JWT: {{.error}}."
error_login_failed:
zero: "Authentication failed."
other: "Authentication failed: {{.error}}."
error_server:
zero: "General server error occurred."
other: "General server error: {{.error}}."
error_no_permission: "You are not authorized to perform this action."
error_empty_blog_title: "Blog title is empty, please provide one."
error_empty_blog_content: "Blog content is empty, please provide one."
error_blog_not_exist: "Blog post {{.id}} does not exist."

vi:
_display: "Tiếng Việt"
error_exter_not_enabled: "Chức năng đăng nhập qua Exter chưa được bật."
error_exter_login_failed:
zero: "Đăng nhập qua Exter không thành công, vui lòng thử lại."
other: "Đăng nhập qua Exter không thành công (max {{.code}}): {{.message}}."
error_exter_token_validation_failed: "Xác thực mã Exter thất bại, lỗi: {{.error}}."
error_user_creation_failed:
zero: "Khởi tạo tài khoản người dùng không thành công, vui lòng thử lại."
other: "Khởi tạo tài khoản người dùng không thành công: {{.error}}."
error_jwt_generation_failed: "Có lỗi khi tạo JWT: {{.error}}."
error_login_failed:
zero: "Đăng nhập không thành công."
other: "Đăng nhập không thành công: {{.error}}."
error_server:
zero: "Có lỗi xảy ra từ đầu máy chủ."
other: "Có lỗi xảy ra từ đầu máy chủ: {{.error}}."
error_no_permission: "Bạn chưa được cấp quyền thực thi tác vụ này."
error_empty_blog_title: "Vui lòng nhập tựa đề bài viết."
error_empty_blog_content: "Vui lòng nhập nội dung bài viết."
error_blog_not_exist: "Bài viết {{.id}} không tồn tại."
1 change: 0 additions & 1 deletion be-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func main() {
// - Application configurations via global variable goapi.AppConfig
// - itineris.ApiRouter instance via global variable goapi.ApiRouter
var bootstrappers = []goapi.IBootstrapper{
// gvabe.Bootstrapper,
docms.Bootstrapper,
}
goapi.Start(bootstrappers...)
Expand Down
38 changes: 20 additions & 18 deletions be-api/src/docms/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/labstack/echo/v4"
)

var Bootstrapper = &MyBootstrapper{name: "gvabe"}
var Bootstrapper = &MyBootstrapper{name: "docms"}

// MyBootstrapper implements goapi.IBootstrapper
type MyBootstrapper struct {
Expand All @@ -41,7 +41,6 @@ func postInitEchoSetup(e *echo.Echo) error {
const confKeyFeTemplate = "docms.frontend.template"
feTemplate := goapi.AppConfig.GetString(confKeyFeTemplate)

// register handler for frontend's assets
if fePath == "" || feDir == "" || feTemplate == "" {
return fmt.Errorf("frontend path/directory/template is not defined at key [%s/%s/%s]", confKeyFePath, confKeyFeDir, confKeyFeTemplate)
}
Expand All @@ -51,37 +50,40 @@ func postInitEchoSetup(e *echo.Echo) error {
e.GET(fePath+"/:tid/:did/:img", serveImage)

feTemplateDir := feDir + "/" + feTemplate
e.Static(fePath, feTemplateDir)
e.GET("/", func(c echo.Context) error {
return c.Redirect(http.StatusFound, fePath+"/")
})
e.GET(fePath+"/", func(c echo.Context) error {
if fcontent, err := os.ReadFile(feTemplateDir + "/index.html"); err != nil {
if os.IsNotExist(err) {
return c.HTML(http.StatusNotFound, "Not found: "+fePath+"/index.html")
} else {
return err
}

// map frontend's static assets
dirContent, err := GetDirContent(feTemplateDir, nil)
if err != nil {
return err
}
for _, entry := range dirContent {
if entry.IsDir() {
e.Static(fePath+"/"+entry.Name()+"/*", feTemplateDir+"/"+entry.Name())
} else {
return c.HTMLBlob(http.StatusOK, fcontent)
e.File(fePath+"/"+entry.Name(), feTemplateDir+"/"+entry.Name())
}
})
e.GET("/manifest.json", func(c echo.Context) error {
if fcontent, err := os.ReadFile(feTemplateDir + "/manifest.json"); err != nil {
}

// finally route everything else to "index.html:
e.GET(fePath+"/*", func(c echo.Context) error {
if fcontent, err := os.ReadFile(feTemplateDir + "/index.html"); err != nil {
if os.IsNotExist(err) {
return c.HTML(http.StatusNotFound, "Not found: manifest.json")
return c.HTML(http.StatusNotFound, "Not found: "+c.Request().RequestURI)
} else {
return err
}
} else {
return c.JSONBlob(http.StatusOK, fcontent)
return c.HTMLBlob(http.StatusOK, fcontent)
}
})

return nil
}

var staticFileMime = map[string]string{
var imgFileMime = map[string]string{
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
Expand All @@ -102,7 +104,7 @@ func serveImage(c echo.Context) error {
}

ext := filepath.Ext(imgName)
mimeType, ok := staticFileMime[ext]
mimeType, ok := imgFileMime[ext]
if !ok {
return c.HTML(http.StatusNotFound, fmt.Sprintf("Not found: %s/%s/%s", topicId, docId, imgName))
}
Expand Down
153 changes: 0 additions & 153 deletions be-api/src/gvabe/bootstrap.go

This file was deleted.

79 changes: 0 additions & 79 deletions be-api/src/gvabe/bootstrap_api.go

This file was deleted.

Loading

0 comments on commit 3e37a01

Please sign in to comment.