Merge branch 'feat/0.7.0/user-manage' into test

# Conflicts:
#	internal/service/search_parser/search_parser.go
This commit is contained in:
LinkinStar 2022-12-16 16:48:47 +08:00
commit b8d2d6e279
33 changed files with 143 additions and 113 deletions

View File

@ -69,8 +69,5 @@ const (
func ExistInPathIgnore(name string) bool {
_, ok := PathIgnoreMap[name]
if ok {
return true
}
return false
return ok
}

View File

@ -7,6 +7,7 @@ import (
"github.com/answerdev/answer/internal/service"
"github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/robfig/cron/v3"
"github.com/segmentfault/pacman/log"
)
// ScheduledTaskManager scheduled task manager
@ -31,10 +32,13 @@ func (s *ScheduledTaskManager) Run() {
fmt.Println("start cron")
s.questionService.SitemapCron(context.Background())
c := cron.New()
c.AddFunc("0 */1 * * *", func() {
_, err := c.AddFunc("0 */1 * * *", func() {
ctx := context.Background()
fmt.Println("sitemap cron execution")
s.questionService.SitemapCron(ctx)
})
if err != nil {
log.Error(err)
}
c.Start()
}

View File

@ -2,8 +2,8 @@ package middleware
import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strings"
@ -11,6 +11,7 @@ import (
"github.com/answerdev/answer/internal/service/uploader"
"github.com/answerdev/answer/pkg/converter"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/log"
)
type AvatarMiddleware struct {
@ -44,7 +45,7 @@ func (am *AvatarMiddleware) AvatarThumb() gin.HandlerFunc {
filePath := fmt.Sprintf("%s/avatar/%s", uploadPath, urlfileName)
var avatarfile []byte
if size == 0 {
avatarfile, err = ioutil.ReadFile(filePath)
avatarfile, err = os.ReadFile(filePath)
} else {
avatarfile, err = am.uploaderService.AvatarThumbFile(ctx, uploadPath, urlfileName, size)
}
@ -52,7 +53,10 @@ func (am *AvatarMiddleware) AvatarThumb() gin.HandlerFunc {
ctx.Next()
return
}
ctx.Writer.WriteString(string(avatarfile))
_, err = ctx.Writer.WriteString(string(avatarfile))
if err != nil {
log.Error(err)
}
ctx.Abort()
return

View File

@ -281,9 +281,7 @@ func (qc *QuestionController) AddQuestion(ctx *gin.Context) {
if err != nil {
errlist, ok := resp.([]*validator.FormErrorField)
if ok {
for _, item := range errlist {
errFields = append(errFields, item)
}
errFields = append(errFields, errlist...)
}
}
if len(errFields) > 0 {
@ -335,9 +333,7 @@ func (qc *QuestionController) UpdateQuestion(ctx *gin.Context) {
errlist, err := qc.questionService.UpdateQuestionCheckTags(ctx, req)
if err != nil {
for _, item := range errlist {
errFields = append(errFields, item)
}
errFields = append(errFields, errlist...)
}
if len(errFields) > 0 {

View File

@ -108,7 +108,7 @@ func (tc *TemplateController) Index(ctx *gin.Context) {
}
siteInfo := tc.SiteInfo(ctx)
siteInfo.Canonical = fmt.Sprintf("%s", siteInfo.General.SiteUrl)
siteInfo.Canonical = siteInfo.General.SiteUrl
UrlUseTitle := false
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionIDAndTitle {

View File

@ -76,21 +76,21 @@ func Paginator(page, pageSize int, nums int64) *schema.Paginator {
prevpage = page - 1
nextpage = int(math.Min(float64(totalpages), float64(page+1)))
pages = make([]int, 5)
for i, _ := range pages {
for i := range pages {
pages[i] = start + i
}
case page >= 3 && totalpages > 5:
start := page - 3 + 1
pages = make([]int, 5)
prevpage = page - 3
for i, _ := range pages {
for i := range pages {
pages[i] = start + i
}
prevpage = page - 1
nextpage = page + 1
default:
pages = make([]int, int(math.Min(5, float64(totalpages))))
for i, _ := range pages {
for i := range pages {
pages[i] = i + 1
}
prevpage = int(math.Max(float64(1), float64(page-1)))

View File

@ -19,6 +19,9 @@ func (q *TemplateRenderController) TagInfo(ctx context.Context, req *schema.GetT
dto := &schema.GetTagInfoReq{}
_ = copier.Copy(dto, req)
resp, err = q.tagService.GetTagInfo(ctx, dto)
if err != nil {
return
}
searchQuestion := &schema.QuestionSearch{}
searchQuestion.Page = req.Page
searchQuestion.PageSize = req.PageSize

View File

@ -15,6 +15,7 @@ import (
"github.com/answerdev/answer/internal/service/uploader"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
// UserController user controller
@ -294,11 +295,13 @@ func (uc *UserController) UserVerifyEmailSend(ctx *gin.Context) {
ErrorMsg: translator.GlobalTrans.Tr(handler.GetLang(ctx), reason.CaptchaVerificationFailed),
})
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
return
}
uc.actionService.ActionRecordAdd(ctx, schema.ActionRecordTypeEmail, ctx.ClientIP())
err := uc.userService.UserVerifyEmailSend(ctx, userInfo.UserID)
_, err := uc.actionService.ActionRecordAdd(ctx, schema.ActionRecordTypeEmail, ctx.ClientIP())
if err != nil {
log.Error(err)
}
err = uc.userService.UserVerifyEmailSend(ctx, userInfo.UserID)
handler.HandleResponse(ctx, err, nil)
}

View File

@ -187,5 +187,4 @@ func InitBaseInfo(ctx *gin.Context) {
time.Sleep(1 * time.Second)
os.Exit(0)
}()
return
}

View File

@ -11,6 +11,23 @@ import (
"xorm.io/xorm"
)
const (
defaultSEORobotTxt = `User-agent: *
Disallow: /admin
Disallow: /search
Disallow: /install
Disallow: /review
Disallow: /users/login
Disallow: /users/register
Disallow: /users/account-recovery
Disallow: /users/oauth/*
Disallow: /users/*/*
Disallow: /answer/api
Disallow: /*?code*
Sitemap: `
)
var tables = []interface{}{
&entity.Activity{},
&entity.Answer{},
@ -116,6 +133,9 @@ func initSiteInfo(engine *xorm.Engine, language, siteName, siteURL, contactEmail
Content: string(generalDataBytes),
Status: 1,
})
if err != nil {
return err
}
loginConfig := map[string]bool{
"allow_new_registrations": true,
@ -127,6 +147,19 @@ func initSiteInfo(engine *xorm.Engine, language, siteName, siteURL, contactEmail
Content: string(loginConfigDataBytes),
Status: 1,
})
seoData := map[string]string{
"robots": defaultSEORobotTxt + siteURL + "/sitemap.xml",
}
seoDataBytes, _ := json.Marshal(seoData)
_, err = engine.InsertOne(&entity.SiteInfo{
Type: "seo",
Content: string(seoDataBytes),
Status: 1,
})
if err != nil {
return err
}
return err
}

View File

@ -29,13 +29,10 @@ type AnswerActivityRepo struct {
const (
acceptAction = "accept"
acceptedAction = "accepted"
acceptCancelAction = "accept_cancel"
acceptedCancelAction = "accepted_cancel"
)
var (
acceptActionList = []string{acceptAction, acceptedAction}
acceptCancelActionList = []string{acceptCancelAction, acceptedCancelAction}
)
// NewAnswerActivityRepo new repository

View File

@ -170,7 +170,6 @@ func (ar *authRepo) RemoveAllUserTokens(ctx context.Context, userID string) {
if err := ar.data.Cache.Del(ctx, key); err != nil {
log.Error(err)
}
return
}
// NewAuthRepo new repository

View File

@ -9,6 +9,7 @@ import (
"github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/service/action"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
// captchaRepo captcha repository
@ -65,7 +66,7 @@ func (cr *captchaRepo) SetCaptcha(ctx context.Context, key, captcha string) (err
func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha string, err error) {
captcha, err = cr.data.Cache.GetString(ctx, key)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
log.Debug(err)
}
// TODO: cache reflect should return empty when key not found
return captcha, nil

View File

@ -33,7 +33,6 @@ func Test_commentRepo_AddComment(t *testing.T) {
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
assert.NoError(t, err)
return
}
func Test_commentRepo_GetCommentPage(t *testing.T) {
@ -55,7 +54,6 @@ func Test_commentRepo_GetCommentPage(t *testing.T) {
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
assert.NoError(t, err)
return
}
func Test_commentRepo_UpdateComment(t *testing.T) {
@ -77,5 +75,4 @@ func Test_commentRepo_UpdateComment(t *testing.T) {
err = commentRepo.RemoveComment(context.TODO(), testCommentEntity.ID)
assert.NoError(t, err)
return
}

View File

@ -3,12 +3,13 @@ package repo_test
import (
"context"
"encoding/json"
"testing"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/repo/question"
"github.com/answerdev/answer/internal/repo/revision"
"github.com/answerdev/answer/internal/repo/unique"
"github.com/stretchr/testify/assert"
"testing"
)
var q = &entity.Question{
@ -53,6 +54,7 @@ func Test_revisionRepo_AddRevision(t *testing.T) {
assert.NotEqual(t, "", q.ID)
content, err := json.Marshal(q)
assert.NoError(t, err)
// auto update false
rev := getRev(q.ID, q.Title, string(content))
err = revisionRepo.AddRevision(context.TODO(), rev, false)

View File

@ -92,7 +92,7 @@ func Test_tagRepo_GetTagListByName(t *testing.T) {
tagOnce.Do(addTagList)
tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
gotTags, err := tagCommonRepo.GetTagListByName(context.TODO(), testTagList[0].SlugName, 1, false)
gotTags, err := tagCommonRepo.GetTagListByName(context.TODO(), testTagList[0].SlugName, false)
assert.NoError(t, err)
assert.Equal(t, testTagList[0].SlugName, gotTags[0].SlugName)
}

View File

@ -20,7 +20,7 @@ func Test_userBackyardRepo_GetUserInfo(t *testing.T) {
func Test_userBackyardRepo_GetUserPage(t *testing.T) {
userBackyardRepo := user.NewUserBackyardRepo(testDataSource, auth.NewAuthRepo(testDataSource))
got, total, err := userBackyardRepo.GetUserPage(context.TODO(), 1, 1, &entity.User{Username: "admin"}, "")
got, total, err := userBackyardRepo.GetUserPage(context.TODO(), 1, 1, &entity.User{Username: "admin"}, "", false)
assert.NoError(t, err)
assert.Equal(t, int64(1), total)
assert.Equal(t, "1", got[0].ID)

View File

@ -76,28 +76,27 @@ func (rr *reportRepo) GetReportListPage(ctx context.Context, dto schema.GetRepor
}
// GetByID get report by ID
func (ar *reportRepo) GetByID(ctx context.Context, id string) (report entity.Report, exist bool, err error) {
report = entity.Report{}
exist, err = ar.data.DB.ID(id).Get(&report)
return
}
// UpdateByID handle report by ID
func (ar *reportRepo) UpdateByID(
ctx context.Context,
id string,
handleData entity.Report,
) (err error) {
_, err = ar.data.DB.ID(id).Update(&handleData)
func (rr *reportRepo) GetByID(ctx context.Context, id string) (report *entity.Report, exist bool, err error) {
report = &entity.Report{}
exist, err = rr.data.DB.ID(id).Get(report)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return
}
func (vr *reportRepo) GetReportCount(ctx context.Context) (count int64, err error) {
// UpdateByID handle report by ID
func (rr *reportRepo) UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error) {
_, err = rr.data.DB.ID(id).Update(&handleData)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return
}
func (rr *reportRepo) GetReportCount(ctx context.Context) (count int64, err error) {
list := make([]*entity.Report, 0)
count, err = vr.data.DB.Where("status =?", entity.ReportStatusPending).FindAndCount(&list)
count, err = rr.data.DB.Where("status =?", entity.ReportStatusPending).FindAndCount(&list)
if err != nil {
return count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}

View File

@ -1,36 +0,0 @@
package router
import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)
func TestUIRouter_Register(t *testing.T) {
r := gin.Default()
NewUIRouter().Register(r)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
}
func TestUIRouter_Static(t *testing.T) {
r := gin.Default()
NewUIRouter().Register(r)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/static/version.txt", nil)
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "OK", w.Body.String())
}

View File

@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
@ -208,7 +208,7 @@ func (ds *DashboardService) RemoteVersion(ctx context.Context) string {
}
defer resp.Body.Close()
respByte, err := ioutil.ReadAll(resp.Body)
respByte, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("http.Client error", err)
return ""

View File

@ -277,6 +277,9 @@ func (es *EmailService) TestTemplate(ctx context.Context) (title, body string, e
return "", "", fmt.Errorf("email test body template parse error: %s", err)
}
tmpl, err = template.New("test_body").Parse(ec.TestBody)
if err != nil {
return "", "", fmt.Errorf("test_body template parse error: %s", err)
}
err = tmpl.Execute(bodyBuf, templateData)
if err != nil {
return "", "", err

View File

@ -40,8 +40,6 @@ func NewObjService(
}
}
func (os *ObjService) GetUnreviewedRevisionInfo(ctx context.Context, objectID string) (objInfo *schema.UnreviewedRevisionInfoInfo, err error) {
objInfo = &schema.UnreviewedRevisionInfoInfo{}
objectType, err := obj.GetObjectTypeStrByObjectID(objectID)
if err != nil {
return nil, err
@ -150,6 +148,9 @@ func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *sc
if err != nil {
return nil, err
}
if !exist {
break
}
objInfo = &schema.SimpleObjectInfo{
ObjectID: answerInfo.ID,
ObjectCreatorUserID: answerInfo.UserID,

View File

@ -1044,9 +1044,6 @@ func (qs *QuestionService) SitemapCron(ctx context.Context) {
if setCacheErr := qs.SetCache(ctx, schema.SitemapCachekey, data); setCacheErr != nil {
log.Errorf("set sitemap cron SetCache failed: %s", setCacheErr)
}
return
}
func (qs *QuestionService) SetCache(ctx context.Context, cachekey string, info interface{}) error {

View File

@ -2,8 +2,10 @@ package report_backyard
import (
"context"
"github.com/answerdev/answer/internal/service/config"
"github.com/answerdev/answer/pkg/htmltext"
"github.com/segmentfault/pacman/log"
"github.com/answerdev/answer/internal/base/pager"
"github.com/answerdev/answer/internal/base/reason"
@ -84,9 +86,15 @@ func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.
// flagged users
flaggedUsers, err = rs.commonUser.BatchUserBasicInfoByID(ctx, flaggedUserIds)
if err != nil {
return nil, err
}
// flag users
users, err = rs.commonUser.BatchUserBasicInfoByID(ctx, userIds)
if err != nil {
return nil, err
}
for _, r := range resp {
r.ReportedUser = flaggedUsers[r.ReportedUserID]
r.ReportUser = users[r.UserID]
@ -99,13 +107,13 @@ func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.
// HandleReported handle the reported object
func (rs *ReportBackyardService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
var (
reported = entity.Report{}
reported *entity.Report
handleData = entity.Report{
FlaggedContent: req.FlaggedContent,
FlaggedType: req.FlaggedType,
Status: entity.ReportStatusCompleted,
}
exist = false
exist bool
)
reported, exist, err = rs.reportRepo.GetByID(ctx, req.ID)
@ -152,6 +160,7 @@ func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schem
objIds, err = rs.commonRepo.GetObjectIDMap(r.ObjectID)
if err != nil {
log.Error(err)
continue
}
@ -168,11 +177,19 @@ func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schem
answerId, ok = objIds["answer"]
if ok {
answer, _, err = rs.answerRepo.GetAnswer(ctx, answerId)
if err != nil {
log.Error(err)
continue
}
}
commentId, ok = objIds["comment"]
if ok {
cmt, _, err = rs.commentCommonRepo.GetComment(ctx, commentId)
if err != nil {
log.Error(err)
continue
}
}
switch r.OType {
@ -201,15 +218,20 @@ func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schem
ReasonType: r.ReportType,
}
err = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.ReportType, r.Reason)
if err != nil {
log.Error(err)
}
}
if r.FlaggedType > 0 {
r.FlaggedReason = &schema.ReasonItem{
ReasonType: r.FlaggedType,
}
_ = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.FlaggedType, r.FlaggedReason)
err = rs.configRepo.GetJsonConfigByIDAndSetToObject(r.FlaggedType, r.FlaggedReason)
if err != nil {
log.Error(err)
}
}
res[i] = r
}
resp = &res
}

View File

@ -11,7 +11,7 @@ import (
type ReportRepo interface {
AddReport(ctx context.Context, report *entity.Report) (err error)
GetReportListPage(ctx context.Context, query schema.GetReportListPageDTO) (reports []entity.Report, total int64, err error)
GetByID(ctx context.Context, id string) (report entity.Report, exist bool, err error)
GetByID(ctx context.Context, id string) (report *entity.Report, exist bool, err error)
UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error)
GetReportCount(ctx context.Context) (count int64, err error)
}

View File

@ -32,7 +32,7 @@ func NewReportHandle(
}
// HandleObject this handle object status
func (rh *ReportHandle) HandleObject(ctx context.Context, reported entity.Report, req schema.ReportHandleReq) (err error) {
func (rh *ReportHandle) HandleObject(ctx context.Context, reported *entity.Report, req schema.ReportHandleReq) (err error) {
var (
objectID = reported.ObjectID
reportedUserID = reported.ReportedUserID

View File

@ -305,7 +305,7 @@ func (rs *RevisionService) GetUnreviewedRevisionPage(ctx context.Context, req *s
}
if exists {
var uinfo schema.UserBasicInfo
err = copier.Copy(&uinfo, userInfo)
_ = copier.Copy(&uinfo, userInfo)
item.UnreviewedInfo.UserInfo = uinfo
}
revisionResp = append(revisionResp, item)

View File

@ -81,5 +81,4 @@ func (rs *RoleService) translateRole(ctx context.Context, role *entity.Role) {
role.Name = translator.GlobalTrans.Tr(handler.GetLangByCtx(ctx), trRoleNameModerator)
role.Description = translator.GlobalTrans.Tr(handler.GetLangByCtx(ctx), trRoleDescriptionModerator)
}
return
}

View File

@ -49,7 +49,7 @@ func (sp *SearchParser) ParseStructure(dto *schema.SearchDTO) (
all = 0
q = 0
a = 0
withWords = []string{}
withWords []string
limitWords = 5
)
@ -194,7 +194,7 @@ func (sp *SearchParser) parseUserID(query *string, currentUserID string) (userID
q = strings.ReplaceAll(q, exprMe, "")
} else if len(res) == 2 {
name := res[1]
user, has, err := sp.userCommon.GetUserBasicInfoByUserName(nil, name)
user, has, err := sp.userCommon.GetUserBasicInfoByUserName(context.TODO(), name)
if err == nil && has {
userID = user.ID
q = re.ReplaceAllString(q, "")
@ -247,7 +247,7 @@ func (sp *SearchParser) parseNotAccepted(query *string) (notAccepted bool) {
expr = `hasaccepted:no`
)
if strings.Index(q, expr) != -1 {
if strings.Contains(q, expr) {
q = strings.ReplaceAll(q, expr, "")
notAccepted = true
}
@ -263,7 +263,7 @@ func (sp *SearchParser) parseIsQuestion(query *string) (isQuestion bool) {
expr = `is:question`
)
if strings.Index(q, expr) == 0 {
if strings.Contains(q, expr) {
q = strings.ReplaceAll(q, expr, "")
isQuestion = true
}
@ -316,9 +316,9 @@ func (sp *SearchParser) parseAccepted(query *string) (accepted bool) {
expr = `isaccepted:yes`
)
if strings.Index(q, expr) != -1 {
if strings.Contains(q, expr) {
accepted = true
strings.ReplaceAll(q, expr, "")
q = strings.ReplaceAll(q, expr, "")
}
*query = strings.TrimSpace(q)
@ -350,7 +350,7 @@ func (sp *SearchParser) parseIsAnswer(query *string) (isAnswer bool) {
expr = `is:answer`
)
if strings.Index(q, expr) != -1 {
if strings.Contains(q, expr) {
isAnswer = true
q = strings.ReplaceAll(q, expr, "")
}

View File

@ -1,6 +1,7 @@
package siteinfo_common
import (
"context"
"testing"
"github.com/answerdev/answer/internal/base/constant"
@ -25,7 +26,7 @@ func TestSiteInfoCommonService_GetSiteGeneral(t *testing.T) {
defer ctl.Finish()
mockInit(ctl)
siteInfoCommonService := NewSiteInfoCommonService(mockSiteInfoRepo)
resp, err := siteInfoCommonService.GetSiteGeneral(nil)
resp, err := siteInfoCommonService.GetSiteGeneral(context.TODO())
assert.NoError(t, err)
assert.Equal(t, resp.Name, "name")
}

View File

@ -162,6 +162,9 @@ func (ts *TagCommonService) SetTagsAttribute(ctx context.Context, tags []string,
default:
return
}
if err != nil {
return err
}
err = ts.tagCommonRepo.UpdateTagsAttribute(ctx, tagslist, attribute, false)
if err != nil {
return err
@ -212,6 +215,9 @@ func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.T
// GetObjectTag get object tag
func (ts *TagCommonService) GetObjectTag(ctx context.Context, objectId string) (objTags []*schema.TagResp, err error) {
tagsInfoList, err := ts.GetObjectEntityTag(ctx, objectId)
if err != nil {
return nil, err
}
return ts.TagFormat(ctx, tagsInfoList)
}
@ -436,7 +442,7 @@ func (ts *TagCommonService) CheckTagsIsChange(ctx context.Context, tagNameList,
check[item] = true
}
for _, value := range check {
if value == false {
if !value {
return true
}
}

View File

@ -119,12 +119,14 @@ func (us *UploaderService) AvatarThumbFile(ctx *gin.Context, uploadPath, fileNam
return avatarfile, fmt.Errorf("img extension not exist")
}
err = imaging.Encode(&buf, new_image, FormatExts[fileSuffix])
if err != nil {
return avatarfile, errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
}
thumbReader := bytes.NewReader(buf.Bytes())
dir.CreateDirIfNotExist(path.Join(us.serviceConfig.UploadPath, avatarThumbSubPath))
err = dir.CreateDirIfNotExist(path.Join(us.serviceConfig.UploadPath, avatarThumbSubPath))
if err != nil {
return nil, errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
}
avatarFilePath := path.Join(avatarThumbSubPath, thumbFileName)
savefilePath := path.Join(us.serviceConfig.UploadPath, avatarFilePath)
out, err := os.Create(savefilePath)

View File

@ -180,6 +180,7 @@ func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWith
objInfo, err = vs.objectService.GetInfo(ctx, voteInfo.ObjectID)
if err != nil {
log.Error(err)
continue
}
item := schema.GetVoteWithPageResp{