Skip to content

Commit

Permalink
feat: PHP 运行环境增加日志 (#2764)
Browse files Browse the repository at this point in the history
Refs #2761
  • Loading branch information
zhengkunwang223 committed Nov 1, 2023
1 parent c47075b commit d15bd1d
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 2 deletions.
24 changes: 24 additions & 0 deletions backend/app/api/v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,27 @@ func (b *BaseApi) Keys(c *gin.Context) {
res.Keys = keys
helper.SuccessWithData(c, res)
}

// @Tags File
// @Summary Read file by Line
// @Description 按行读取文件
// @Param request body request.FileReadByLineReq true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /files/read [post]
func (b *BaseApi) ReadFileByLine(c *gin.Context) {
var req request.FileReadByLineReq
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
lines, end, err := files.ReadFileByLine(req.Path, req.Page, req.PageSize)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
}
res := response.FileLineContent{
End: end,
}
res.Path = req.Path
res.Content = strings.Join(lines, "\n")
helper.SuccessWithData(c, res)
}
6 changes: 6 additions & 0 deletions backend/app/dto/request/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ type FileRoleUpdate struct {
Sub bool `json:"sub" validate:"required"`
}

type FileReadByLineReq struct {
Path string `json:"path" validate:"required"`
Page int `json:"page" validate:"required"`
PageSize int `json:"pageSize" validate:"required"`
}

type FileExistReq struct {
Name string `json:"name" validate:"required"`
Dir string `json:"dir" validate:"required"`
Expand Down
6 changes: 6 additions & 0 deletions backend/app/dto/response/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ type FileWgetRes struct {
Key string `json:"key"`
}

type FileLineContent struct {
Content string `json:"content"`
End bool `json:"end"`
Path string `json:"path"`
}

type FileExist struct {
Exist bool `json:"exist"`
}
1 change: 1 addition & 0 deletions backend/router/ro_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) {
fileRouter.POST("/size", baseApi.Size)
fileRouter.GET("/ws", baseApi.Ws)
fileRouter.GET("/keys", baseApi.Keys)
fileRouter.POST("/read", baseApi.ReadFileByLine)

fileRouter.POST("/recycle/search", baseApi.SearchRecycleBinFile)
fileRouter.POST("/recycle/reduce", baseApi.ReduceRecycleBinFile)
Expand Down
53 changes: 51 additions & 2 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -5666,6 +5666,36 @@ const docTemplate = `{
}
}
},
"/files/read": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "按行读取文件",
"tags": [
"File"
],
"summary": "Read file by Line",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.FileReadByLineReq"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/files/recycle/clear": {
"post": {
"security": [
Expand Down Expand Up @@ -16955,6 +16985,25 @@ const docTemplate = `{
}
}
},
"request.FileReadByLineReq": {
"type": "object",
"required": [
"page",
"pageSize",
"path"
],
"properties": {
"page": {
"type": "integer"
},
"pageSize": {
"type": "integer"
},
"path": {
"type": "string"
}
}
},
"request.FileRename": {
"type": "object",
"required": [
Expand Down
49 changes: 49 additions & 0 deletions cmd/server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5659,6 +5659,36 @@
}
}
},
"/files/read": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "按行读取文件",
"tags": [
"File"
],
"summary": "Read file by Line",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.FileReadByLineReq"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/files/recycle/clear": {
"post": {
"security": [
Expand Down Expand Up @@ -16948,6 +16978,25 @@
}
}
},
"request.FileReadByLineReq": {
"type": "object",
"required": [
"page",
"pageSize",
"path"
],
"properties": {
"page": {
"type": "integer"
},
"pageSize": {
"type": "integer"
},
"path": {
"type": "string"
}
}
},
"request.FileRename": {
"type": "object",
"required": [
Expand Down
31 changes: 31 additions & 0 deletions cmd/server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,19 @@ definitions:
required:
- path
type: object
request.FileReadByLineReq:
properties:
page:
type: integer
pageSize:
type: integer
path:
type: string
required:
- page
- pageSize
- path
type: object
request.FileRename:
properties:
newName:
Expand Down Expand Up @@ -7955,6 +7968,24 @@ paths:
formatEN: Change owner [paths] => [user]/[group]
formatZH: 修改用户/组 [paths] => [user]/[group]
paramKeys: []
/files/read:
post:
description: 按行读取文件
parameters:
- description: request
in: body
name: request
required: true
schema:
$ref: '#/definitions/request.FileReadByLineReq'
responses:
"200":
description: OK
security:
- ApiKeyAuth: []
summary: Read file by Line
tags:
- File
/files/recycle/clear:
post:
consumes:
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/api/interface/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ export namespace File {
name: string;
}

export interface FileReadByLine {
path: string;
page: number;
pageSize: number;
}

export interface Favorite extends CommonModel {
path: string;
isDir: boolean;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/api/modules/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export const AddFavorite = (path: string) => {
return http.post<any>('files/favorite', { path: path });
};

export const ReadByLine = (req: File.FileReadByLine) => {
return http.post<any>('files/read', req);
};

export const RemoveFavorite = (id: number) => {
return http.post<any>('files/favorite/del', { id: id });
};
12 changes: 12 additions & 0 deletions frontend/src/views/website/runtime/php/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
</div>
</template>
</el-table-column>
<el-table-column :label="$t('website.log')" prop="">
<template #default="{ row }">
<el-button @click="openLog(row)" link type="primary">{{ $t('website.check') }}</el-button>
</template>
</el-table-column>
<el-table-column
prop="createdAt"
:label="$t('commons.table.date')"
Expand All @@ -61,6 +66,7 @@

<CreateRuntime ref="createRef" @close="search" />
<OpDialog ref="opRef" @search="search" />
<Log ref="logRef" @close="search" />
</div>
</template>

Expand All @@ -74,6 +80,7 @@ import CreateRuntime from '@/views/website/runtime/php/create/index.vue';
import Status from '@/components/status/index.vue';
import i18n from '@/lang';
import RouterMenu from '../index.vue';
import Log from '@/views/website/runtime/php/log/index.vue';
const paginationConfig = reactive({
cacheSizeKey: 'runtime-page-size',
Expand All @@ -89,6 +96,7 @@ let req = reactive<Runtime.RuntimeReq>({
});
let timer: NodeJS.Timer | null = null;
const opRef = ref();
const logRef = ref();
const buttons = [
{
Expand Down Expand Up @@ -133,6 +141,10 @@ const openDetail = (row: Runtime.Runtime) => {
createRef.value.acceptParams({ type: row.type, mode: 'edit', id: row.id, appID: row.appID });
};
const openLog = (row: Runtime.RuntimeDTO) => {
logRef.value.acceptParams({ path: row.path + '/' + 'build.log' });
};
const openDelete = async (row: Runtime.Runtime) => {
opRef.value.acceptParams({
title: i18n.global.t('commons.msg.deleteTitle'),
Expand Down
Loading

0 comments on commit d15bd1d

Please sign in to comment.