merge: Merge branch 'master' of github.com:textworld/sonic

pull/344/head
textworld 1 year ago
commit 106e6ffa5f

@ -90,6 +90,8 @@ See: https://hub.docker.com/r/gosonic/sonic
| [Journal](https://github.com/hooxuu/sonic-theme-Journal) |
| [Clark](https://github.com/ClarkQAQ/sonic_theme_clark) |
| [Earth](https://github.com/Meepoljdx/sonic-theme-earth) |
| [PaperMod](https://github.com/jakezhu9/sonic-theme-papermod) |
| [Tink](https://github.com/raisons/sonic-theme-tink) |
## TODO
- [ ] i18n

@ -16,7 +16,7 @@ logging:
### The Database configuration,You should choose one between MySQL and SQLite3,if both MySQL and SQLite3 are configured ,use Sqlite3 first
sqlite3:
enable: false
enable: true
### mysql数据库配置,请将用户名、密码、ip地址、端口、数据库名称替换为你自己的配置
### mysql database configuration, please replace the user name, password, ip address, port, database name to your own configuration.

@ -76,10 +76,14 @@ See: https://hub.docker.com/r/gosonic/sonic
## 主题生态
| Theme | URL |
|---------|---------------------------------------------------|
| Anatole | https://github.com/go-sonic/default-theme-anatole |
| Journal | https://github.com/hooxuu/sonic-theme-Journal |
| Theme |
|---------|
| [Anatole](https://github.com/go-sonic/default-theme-anatole) |
| [Journal](https://github.com/hooxuu/sonic-theme-Journal) |
| [Clark](https://github.com/ClarkQAQ/sonic_theme_clark) |
| [Earth](https://github.com/Meepoljdx/sonic-theme-earth) |
| [PaperMod](https://github.com/jakezhu9/sonic-theme-papermod) |
| [Tink](https://github.com/raisons/sonic-theme-tink) |
## TODO
- [ ] i18n

@ -89,6 +89,23 @@ func (p *PhotoHandler) CreatePhoto(ctx *gin.Context) (interface{}, error) {
return p.PhotoService.ConvertToDTO(ctx, photo), nil
}
func (p *PhotoHandler) CreatePhotoBatch(ctx *gin.Context) (interface{}, error) {
photosParam := make([]*param.Photo, 0)
err := ctx.ShouldBindJSON(&photosParam)
if err != nil {
e := validator.ValidationErrors{}
if errors.As(err, &e) {
return nil, xerr.WithStatus(e, xerr.StatusBadRequest).WithMsg(trans.Translate(e))
}
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("parameter error")
}
photos, err := p.PhotoService.CreateBatch(ctx, photosParam)
if err != nil {
return nil, err
}
return p.PhotoService.ConvertToDTOs(ctx, photos), nil
}
func (p *PhotoHandler) UpdatePhoto(ctx *gin.Context) (interface{}, error) {
id, err := util.ParamInt32(ctx, "id")
if err != nil {

@ -228,6 +228,7 @@ func (s *Server) RegisterRouters() {
photoRouter.GET("/:id", s.wrapHandler(s.PhotoHandler.GetPhotoByID))
photoRouter.DELETE("/:id", s.wrapHandler(s.PhotoHandler.DeletePhoto))
photoRouter.POST("", s.wrapHandler(s.PhotoHandler.CreatePhoto))
photoRouter.POST("/batch", s.wrapHandler(s.PhotoHandler.CreatePhotoBatch))
photoRouter.PUT("/:id", s.wrapHandler(s.PhotoHandler.UpdatePhoto))
photoRouter.GET("/teams", s.wrapHandler(s.PhotoHandler.ListPhotoTeams))
}

@ -53,6 +53,7 @@ var AllProperty = []Property{
EmailPassword,
EmailFromName,
EmailIsEnabled,
EmailStarttls,
CustomHead,
CustomContentHead,
StatisticsCode,

@ -38,4 +38,9 @@ var (
DefaultValue: false,
Kind: reflect.Bool,
}
EmailStarttls = Property{
KeyValue: "email_starttls",
DefaultValue: false,
Kind: reflect.Bool,
}
)

@ -1 +1 @@
Subproject commit 2155ccec5c4517531904119a8a69e17aff41abb3
Subproject commit 3c05fe576ebf67a4ca4623ac09305962d6bf6a10

@ -78,6 +78,27 @@ func (p *photoServiceImpl) Create(ctx context.Context, photoParam *param.Photo)
return photo, nil
}
func (*photoServiceImpl) CreateBatch(ctx context.Context, photosParam []*param.Photo) ([]*entity.Photo, error) {
photos := make([]*entity.Photo, len(photosParam))
for i, photoParam := range photosParam {
photo := &entity.Photo{
Name: photoParam.Name,
Description: photoParam.Description,
URL: photoParam.URL,
Thumbnail: photoParam.Thumbnail,
Location: photoParam.Location,
Team: photoParam.Team,
}
photos[i] = photo
}
photoDAL := dal.GetQueryByCtx(ctx).Photo
err := photoDAL.WithContext(ctx).CreateInBatches(photos, 100)
if err != nil {
return nil, WrapDBErr(err)
}
return photos, err
}
func (p *photoServiceImpl) Update(ctx context.Context, id int32, photoParam *param.Photo) (*entity.Photo, error) {
photoDAL := dal.GetQueryByCtx(ctx).Photo
var takeTime *time.Time

@ -13,6 +13,7 @@ type PhotoService interface {
Page(ctx context.Context, page param.Page, sort *param.Sort) ([]*entity.Photo, int64, error)
GetByID(ctx context.Context, id int32) (*entity.Photo, error)
Create(ctx context.Context, photoParam *param.Photo) (*entity.Photo, error)
CreateBatch(ctx context.Context, photosParam []*param.Photo) ([]*entity.Photo, error)
Update(ctx context.Context, id int32, photoParam *param.Photo) (*entity.Photo, error)
Delete(ctx context.Context, id int32) error
ConvertToDTO(ctx context.Context, photo *entity.Photo) *dto.Photo

@ -10,6 +10,7 @@ import (
"go.uber.org/fx"
"github.com/go-sonic/sonic/model/dto"
"github.com/go-sonic/sonic/util"
"github.com/go-sonic/sonic/util/xerr"
)
@ -25,6 +26,13 @@ func (g gitThemeFetcherImpl) FetchTheme(ctx context.Context, file interface{}) (
tempDir := os.TempDir()
themeDirName := lastSplit
tmpThemeDir := filepath.Join(tempDir, themeDirName)
if util.FileIsExisted(tmpThemeDir) {
err := os.RemoveAll(tmpThemeDir)
if err != nil {
return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("delete tmp theme directory err")
}
}
_, err := git.PlainClone(filepath.Join(tempDir, themeDirName), false, &git.CloneOptions{
URL: gitURL,
})

Loading…
Cancel
Save