作者 yangfu

public resource

... ... @@ -31,6 +31,7 @@ ENV CONFIG_FILE=${CONFIG_FILE}
COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/
COPY --from=builder /build/cmd/chart-server/api/public ./public/
EXPOSE 8080
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ Name: chart
Host: 0.0.0.0
Port: 8080
Verbose: true
HostName: http://sumifcc-bchart-dev.sumifcc.com
Log:
Mode: file
... ...
... ... @@ -2,6 +2,7 @@ Name: chart
Host: 0.0.0.0
Port: 8081
Verbose: true
HostName: http://sumifcc-bchart-dev.sumifcc.com
Log:
Mode: file
... ...
... ... @@ -12,6 +12,7 @@ type Config struct {
config.Config
Redis redis.RedisConf `json:",optional"`
ByteMetadata ApiService
HostName string // 服务域名
}
type ApiService struct {
... ...
package public
import (
"net/http"
"path/filepath"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func GetFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PublicGetFileRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
handler := http.FileServer(http.Dir("public"))
r.URL.Path = filepath.Join(req.FileName)
handler.ServeHTTP(w, r)
}
}
... ...
... ... @@ -7,6 +7,7 @@ import (
chart "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/chart"
log "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/log"
page "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/page"
public "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/public"
table "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/table"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
... ... @@ -17,11 +18,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/chart/:id",
Handler: chart.GetChartHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chart",
Handler: chart.SaveChartHandler(serverCtx),
... ... @@ -73,6 +69,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/chart/load-data",
Handler: chart.LoadChartDataHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/chart/:id",
Handler: chart.GetChartHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
... ... @@ -113,11 +114,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/app-page/:id",
Handler: page.GetAppPageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/app-page",
Handler: page.SaveAppPageHandler(serverCtx),
... ... @@ -156,6 +152,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/app-page/:id",
Handler: page.GetAppPageHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/app-page/get-share-detail/:key",
Handler: page.GetAppPageShareDetailHandler(serverCtx),
},
... ... @@ -173,4 +174,14 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/public/:filename",
Handler: public.GetFileHandler(serverCtx),
},
},
)
}
... ...
... ... @@ -2,6 +2,7 @@ package chart
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"strings"
... ... @@ -26,26 +27,29 @@ func NewSearchChartComponentsLogic(ctx context.Context, svcCtx *svc.ServiceConte
}
func (l *SearchChartComponentsLogic) SearchChartComponents(req *types.ChartComponentSearchRequest) (resp *types.ChartComponentSearchResponse, err error) {
pathMaker := func(filename string) string {
return fmt.Sprintf("%s/%s/%s", l.svcCtx.Config.HostName, "public", filename)
}
var list = []types.ChartComponentItem{
{
Name: "记录型表格",
Code: domain.RecordTable1,
Cover: "",
Cover: pathMaker("RecordTable-1.png"),
},
{
Name: "总体指标",
Code: domain.MetricsCard1,
Cover: "",
Cover: pathMaker("MetricsCard-1.png"),
},
{
Name: "容器卡片",
Code: domain.ContainerCard1,
Cover: "",
Cover: pathMaker("ContainerCard-1.png"),
},
{
Name: "四分图",
Code: domain.QuarterChart1,
Cover: "",
Cover: pathMaker("QuarterChart-1.png"),
},
}
var result = make([]types.ChartComponentItem, 0)
... ...
package public
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetFileLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLogic {
return &GetFileLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetFileLogic) GetFile(req *types.PublicGetFileRequest) error {
// todo: add your logic here and delete this line
return nil
}
... ...
... ... @@ -143,6 +143,7 @@ type Title struct {
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,,file]"` // text file ,options=text||file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileName string `json:"fileName,optional"` // 文件名
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
}
... ... @@ -311,3 +312,7 @@ type LogGetRequest struct {
type LogGetResponse struct {
}
type PublicGetFileRequest struct {
FileName string `path:"filename"`
}
... ...
... ... @@ -53,6 +53,7 @@ type Title struct {
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileName string `json:"fileName,optional"` // 文件名
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
}
... ...
... ... @@ -2,4 +2,5 @@ import "core/chart.api"
import "core/table.api"
import "core/app_page.api"
import "core/log.api"
import "core/public.api"
// import "./core/chart_stting.api"
\ No newline at end of file
... ...
... ... @@ -15,9 +15,6 @@ info(
jwt: JwtAuth
)
service Core {
@doc "获取应用页详情"
@handler getAppPage
get /app-page/:id (AppPageGetRequest) returns (AppPageGetResponse)
@doc "保存应用页"
@handler saveAppPage
post /app-page (AppPageSaveRequest) returns (AppPageSaveResponse)
... ... @@ -112,6 +109,10 @@ type (
group: page
)
service Core {
@doc "获取应用页详情"
@handler getAppPage
get /app-page/:id (AppPageGetRequest) returns (AppPageGetResponse)
@doc "开放接口-获取应用页详情通过KEY"
@handler getAppPageShareDetail
get /api/app-page/get-share-detail/:key (GetAppPageShareDetailRequest) returns (GetAppPageShareDetailResponse)
... ...
... ... @@ -16,9 +16,6 @@ info(
//middleware: Authority
)
service Core {
@doc "获取图表详情"
@handler getChart
get /chart/:id (ChartGetRequest) returns (ChartGetResponse)
@doc "保存图表"
@handler saveChart
post /chart (ChartSaveRequest) returns (ChartSaveResponse)
... ... @@ -49,13 +46,14 @@ service Core {
@server(
prefix: v1
group: chart
//jwt: JwtAuth
//middleware: Authority
)
service Core {
@doc "加载图表数据"
@handler loadChartData
post /chart/load-data (LoadChartDataRequest) returns (LoadChartDataResponse)
@doc "获取图表详情"
@handler getChart
get /chart/:id (ChartGetRequest) returns (ChartGetResponse)
}
type (
... ... @@ -156,7 +154,6 @@ type(
Title Title `json:"title,optional"` // 标题
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
//Cover string `json:"cover,optional"` // 封面
Other Other `json:"other,optional"` // 其他额外配置
}
Other struct {
... ... @@ -184,6 +181,7 @@ type(
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,,file]"` // text file ,options=text||file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileName string `json:"fileName,optional"` // 文件名
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
}
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
group: public
)
service Core {
@doc "获取文件"
@handler getFile
get /public/:filename (PublicGetFileRequest)
}
type(
PublicGetFileRequest struct{
FileName string `path:"filename"`
}
)
\ No newline at end of file
... ...