feat: 增加修改 PHP 文件的接口 (#593)

pull/595/head
zhengkunwang223 2023-04-12 14:48:30 +08:00 committed by GitHub
parent 1bbf501783
commit bd1ced0af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 834 additions and 510 deletions

View File

@ -524,7 +524,7 @@ func (b *BaseApi) GetWebsitePHPConfig(c *gin.Context) {
// @Param request body request.WebsitePHPConfigUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/php/update [post]
// @Router /websites/php/config [post]
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"id","isList":false,"db":"websites","output_colume":"primary_domain","output_value":"domain"}],"formatZH":"[domain] PHP 配置修改","formatEN":"[domain] PHP conf update"}
func (b *BaseApi) UpdateWebsitePHPConfig(c *gin.Context) {
var req request.WebsitePHPConfigUpdate
@ -538,3 +538,25 @@ func (b *BaseApi) UpdateWebsitePHPConfig(c *gin.Context) {
}
helper.SuccessWithData(c, nil)
}
// @Tags Website PHP
// @Summary Update php conf
// @Description 更新 php 配置
// @Accept json
// @Param request body request.WebsitePHPFileUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/php/update [post]
// @x-panel-log {"bodyKeys":["websiteId"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"websiteId","isList":false,"db":"websites","output_colume":"primary_domain","output_value":"domain"}],"formatZH":"php 配置修改 [domain]","formatEN":"Nginx conf update [domain]"}
func (b *BaseApi) UpdatePHPFile(c *gin.Context) {
var req request.WebsitePHPFileUpdate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteService.UpdatePHPConfigFile(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}

View File

@ -139,3 +139,9 @@ type WebsitePHPConfigUpdate struct {
ID uint `json:"id" validate:"required"`
Params map[string]string `json:"params" validate:"required"`
}
type WebsitePHPFileUpdate struct {
ID uint `json:"id" validate:"required"`
Type string `json:"type" validate:"required"`
Content string `json:"content" validate:"required"`
}

View File

@ -56,6 +56,7 @@ type IWebsiteService interface {
ChangeDefaultServer(id uint) error
GetPHPConfig(id uint) (*response.PHPConfig, error)
UpdatePHPConfig(req request.WebsitePHPConfigUpdate) error
UpdatePHPConfigFile(req request.WebsitePHPFileUpdate) error
}
func NewIWebsiteService() IWebsiteService {
@ -499,14 +500,12 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint, configType string)
if err != nil {
return response.FileInfo{}, err
}
runtimeInstall.GetPath()
configPath = path.Join(runtimeInstall.GetPath(), "conf", "php-fpm.conf")
case constant.ConfigPHP:
runtimeInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
if err != nil {
return response.FileInfo{}, err
}
runtimeInstall.GetPath()
configPath = path.Join(runtimeInstall.GetPath(), "conf", "php.ini")
}
info, err := files.NewFileInfo(files.FileOption{
@ -938,3 +937,34 @@ func (w WebsiteService) UpdatePHPConfig(req request.WebsitePHPConfigUpdate) (err
}
return nil
}
func (w WebsiteService) UpdatePHPConfigFile(req request.WebsitePHPFileUpdate) error {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))
if err != nil {
return err
}
if website.Type != constant.Runtime {
return nil
}
runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID))
if err != nil {
return err
}
if runtime.Resource != constant.ResourceAppstore {
return nil
}
runtimeInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID))
if err != nil {
return err
}
configPath := ""
if req.Type == constant.ConfigFPM {
configPath = path.Join(runtimeInstall.GetPath(), "conf", "php-fpm.conf")
} else {
configPath = path.Join(runtimeInstall.GetPath(), "conf", "php.ini")
}
if err := files.NewFileOp().WriteFile(configPath, strings.NewReader(req.Content), 0755); err != nil {
return err
}
return nil
}

View File

@ -44,5 +44,6 @@ func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) {
groupRouter.GET("/php/config/:id", baseApi.GetWebsitePHPConfig)
groupRouter.POST("/php/config", baseApi.UpdateWebsitePHPConfig)
groupRouter.POST("/php/update", baseApi.UpdatePHPFile)
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -271,4 +271,10 @@ export namespace Website {
id: number;
params: any;
}
export interface PHPUpdate {
id: number;
content: string;
type: string;
}
}

View File

@ -166,3 +166,7 @@ export const GetPHPConfig = (id: number) => {
export const UpdatePHPConfig = (req: Website.PHPConfigUpdate) => {
return http.post<any>(`/websites/php/config/`, req);
};
export const UpdatePHPFile = (req: Website.PHPUpdate) => {
return http.post<any>(`/websites/php/update`, req);
};

View File

@ -23,8 +23,7 @@
<script lang="ts" setup>
import { Codemirror } from 'vue-codemirror';
import { oneDark } from '@codemirror/theme-one-dark';
import { GetWebsiteConfig } from '@/api/modules/website';
import { InstalledOp } from '@/api/modules/app';
import { GetWebsiteConfig, UpdatePHPFile } from '@/api/modules/website';
import { computed, onMounted, ref } from 'vue';
import { File } from '@/api/interface/file';
import i18n from '@/lang';
@ -71,15 +70,14 @@ const get = () => {
const submit = async () => {
loading.value = true;
let operateReq = {
installId: props.installId,
operate: 'restart',
};
await InstalledOp(operateReq)
UpdatePHPFile({
id: id.value,
content: content.value,
type: props.type,
})
.then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
})
.catch(() => {})
.finally(() => {
loading.value = false;
});