Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/1.4.0/badge' into feat/1.4.…
Browse files Browse the repository at this point in the history
…0/badge
  • Loading branch information
kumfo committed Aug 8, 2024
2 parents 49ba98c + 9b0de85 commit 8a40e95
Show file tree
Hide file tree
Showing 27 changed files with 807 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DOCKER_CMD=docker
GO_ENV=CGO_ENABLED=0 GO111MODULE=on
Revision=$(shell git rev-parse --short HEAD 2>/dev/null || echo "")
GO_FLAGS=-ldflags="-X github.com/apache/incubator-answer/cmd.Version=$(VERSION) -X 'github.com/apache/incubator-answer/cmd.Revision=$(Revision)' -X 'github.com/apache/incubator-answer/cmd.Time=`date +%s`' -extldflags -static"
GO=$(GO_ENV) $(shell which go)
GO=$(GO_ENV) "$(shell which go)"

build: generate
@$(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC)
Expand Down
22 changes: 13 additions & 9 deletions cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions internal/base/constant/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package constant

// EventType event type. It is used to define the type of event. Such as object.action
type EventType string

// event object
const (
eventQuestion = "question"
eventAnswer = "answer"
eventComment = "comment"
eventUser = "user"
)

// event action
const (
eventCreate = "create"
eventUpdate = "update"
eventDelete = "delete"
eventVote = "vote"
eventAccept = "accept" // only question have the accept event
eventShare = "share" // the object share link has been clicked
eventFlag = "flag"
eventReact = "react"
)

const (
EventUserUpdate EventType = eventUser + "." + eventUpdate
EventUserShare EventType = eventUser + "." + eventShare
)

const (
EventQuestionCreate EventType = eventQuestion + "." + eventCreate
EventQuestionUpdate EventType = eventQuestion + "." + eventUpdate
EventQuestionDelete EventType = eventQuestion + "." + eventDelete
EventQuestionVote EventType = eventQuestion + "." + eventVote
EventQuestionAccept EventType = eventQuestion + "." + eventAccept
EventQuestionFlag EventType = eventQuestion + "." + eventFlag
EventQuestionReact EventType = eventQuestion + "." + eventReact
)

const (
EventAnswerCreate EventType = eventAnswer + "." + eventCreate
EventAnswerUpdate EventType = eventAnswer + "." + eventUpdate
EventAnswerDelete EventType = eventAnswer + "." + eventDelete
EventAnswerVote EventType = eventAnswer + "." + eventVote
EventAnswerFlag EventType = eventAnswer + "." + eventFlag
EventAnswerReact EventType = eventAnswer + "." + eventReact
)

const (
EventCommentCreate EventType = eventComment + "." + eventCreate
EventCommentUpdate EventType = eventComment + "." + eventUpdate
EventCommentDelete EventType = eventComment + "." + eventDelete
EventCommentVote EventType = eventComment + "." + eventVote
EventCommentFlag EventType = eventComment + "." + eventFlag
)
24 changes: 24 additions & 0 deletions internal/controller/template_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package controller
import (
"encoding/json"
"fmt"
"github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/event_queue"
"github.com/apache/incubator-answer/plugin"
"html/template"
"net/http"
Expand Down Expand Up @@ -54,19 +56,25 @@ type TemplateController struct {
cssPath string
templateRenderController *templaterender.TemplateRenderController
siteInfoService siteinfo_common.SiteInfoCommonService
eventQueueService event_queue.EventQueueService
userService *content.UserService
}

// NewTemplateController new controller
func NewTemplateController(
templateRenderController *templaterender.TemplateRenderController,
siteInfoService siteinfo_common.SiteInfoCommonService,
eventQueueService event_queue.EventQueueService,
userService *content.UserService,
) *TemplateController {
script, css := GetStyle()
return &TemplateController{
scriptPath: script,
cssPath: css,
templateRenderController: templateRenderController,
siteInfoService: siteInfoService,
eventQueueService: eventQueueService,
userService: userService,
}
}
func GetStyle() (script []string, css string) {
Expand Down Expand Up @@ -271,6 +279,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
id := ctx.Param("id")
title := ctx.Param("title")
answerid := ctx.Param("answerid")
shareUsername := ctx.Query("share")
if checker.IsQuestionsIgnorePath(id) {
// if id == "ask" {
file, err := ui.Build.ReadFile("build/index.html")
Expand All @@ -291,6 +300,13 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
tc.Page404(ctx)
return
}
if len(shareUsername) > 0 {
userInfo, err := tc.userService.GetOtherUserInfoByUsername(
ctx, &schema.GetOtherUserInfoByUsernameReq{Username: shareUsername})
if err == nil {
tc.eventQueueService.Send(ctx, schema.NewEvent(constant.EventUserShare, userInfo.ID))
}
}
encodeTitle := htmltext.UrlTitle(detail.Title)
if encodeTitle == title {
correctTitle = true
Expand Down Expand Up @@ -562,6 +578,14 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteI
ctx.HTML(code, tpl, data)
}

func (tc *TemplateController) OpenSearch(ctx *gin.Context) {
if tc.checkPrivateMode(ctx) {
tc.Page404(ctx)
return
}
tc.templateRenderController.OpenSearch(ctx)
}

func (tc *TemplateController) Sitemap(ctx *gin.Context) {
if tc.checkPrivateMode(ctx) {
tc.Page404(ctx)
Expand Down
22 changes: 22 additions & 0 deletions internal/controller/template_render/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ func (t *TemplateRenderController) Sitemap(ctx *gin.Context) {
)
}

func (t *TemplateRenderController) OpenSearch(ctx *gin.Context) {
general, err := t.siteInfoService.GetSiteGeneral(ctx)
if err != nil {
log.Error("get site general failed:", err)
return
}

favicon := general.SiteUrl + "/favicon.ico"
branding, err := t.siteInfoService.GetSiteBranding(ctx)
if err == nil && len(branding.Favicon) > 0 {
favicon = branding.Favicon
}

ctx.Header("Content-Type", "application/xml")
ctx.HTML(
http.StatusOK, "opensearch.xml", gin.H{
"general": general,
"favicon": favicon,
},
)
}

func (t *TemplateRenderController) SitemapPage(ctx *gin.Context, page int) error {
general, err := t.siteInfoService.GetSiteGeneral(ctx)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/controller_admin/siteinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func (sc *SiteInfoController) GetRobots(ctx *gin.Context) {
ctx.String(http.StatusOK, resp.Robots)
}

// GetRobots get site robots information
// @Summary get site robots information
// @Description get site robots information
// GetCss get site custom CSS
// @Summary get site custom CSS
// @Description get site custom CSS
// @Tags site
// @Produce json
// @Success 200 {string} txt ""
// @Produce text/css
// @Success 200 {string} css ""
// @Router /custom.css [get]
func (sc *SiteInfoController) GetCss(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteCustomCssHTML(ctx)
Expand Down
Loading

0 comments on commit 8a40e95

Please sign in to comment.