Skip to content

Commit d15bd1d

Browse files
feat: PHP 运行环境增加日志 (#2764)
Refs #2761
1 parent c47075b commit d15bd1d

File tree

11 files changed

+350
-2
lines changed

11 files changed

+350
-2
lines changed

backend/app/api/v1/file.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,27 @@ func (b *BaseApi) Keys(c *gin.Context) {
683683
res.Keys = keys
684684
helper.SuccessWithData(c, res)
685685
}
686+
687+
// @Tags File
688+
// @Summary Read file by Line
689+
// @Description 按行读取文件
690+
// @Param request body request.FileReadByLineReq true "request"
691+
// @Success 200
692+
// @Security ApiKeyAuth
693+
// @Router /files/read [post]
694+
func (b *BaseApi) ReadFileByLine(c *gin.Context) {
695+
var req request.FileReadByLineReq
696+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
697+
return
698+
}
699+
lines, end, err := files.ReadFileByLine(req.Path, req.Page, req.PageSize)
700+
if err != nil {
701+
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
702+
}
703+
res := response.FileLineContent{
704+
End: end,
705+
}
706+
res.Path = req.Path
707+
res.Content = strings.Join(lines, "\n")
708+
helper.SuccessWithData(c, res)
709+
}

backend/app/dto/request/file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ type FileRoleUpdate struct {
109109
Sub bool `json:"sub" validate:"required"`
110110
}
111111

112+
type FileReadByLineReq struct {
113+
Path string `json:"path" validate:"required"`
114+
Page int `json:"page" validate:"required"`
115+
PageSize int `json:"pageSize" validate:"required"`
116+
}
117+
112118
type FileExistReq struct {
113119
Name string `json:"name" validate:"required"`
114120
Dir string `json:"dir" validate:"required"`

backend/app/dto/response/file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ type FileWgetRes struct {
3333
Key string `json:"key"`
3434
}
3535

36+
type FileLineContent struct {
37+
Content string `json:"content"`
38+
End bool `json:"end"`
39+
Path string `json:"path"`
40+
}
41+
3642
type FileExist struct {
3743
Exist bool `json:"exist"`
3844
}

backend/router/ro_file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) {
3737
fileRouter.POST("/size", baseApi.Size)
3838
fileRouter.GET("/ws", baseApi.Ws)
3939
fileRouter.GET("/keys", baseApi.Keys)
40+
fileRouter.POST("/read", baseApi.ReadFileByLine)
4041

4142
fileRouter.POST("/recycle/search", baseApi.SearchRecycleBinFile)
4243
fileRouter.POST("/recycle/reduce", baseApi.ReduceRecycleBinFile)

cmd/server/docs/docs.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Code generated by swaggo/swag. DO NOT EDIT.
2-
1+
// Package docs GENERATED BY SWAG; DO NOT EDIT
2+
// This file was generated by swaggo/swag
33
package docs
44

55
import "github.com/swaggo/swag"
@@ -5666,6 +5666,36 @@ const docTemplate = `{
56665666
}
56675667
}
56685668
},
5669+
"/files/read": {
5670+
"post": {
5671+
"security": [
5672+
{
5673+
"ApiKeyAuth": []
5674+
}
5675+
],
5676+
"description": "按行读取文件",
5677+
"tags": [
5678+
"File"
5679+
],
5680+
"summary": "Read file by Line",
5681+
"parameters": [
5682+
{
5683+
"description": "request",
5684+
"name": "request",
5685+
"in": "body",
5686+
"required": true,
5687+
"schema": {
5688+
"$ref": "#/definitions/request.FileReadByLineReq"
5689+
}
5690+
}
5691+
],
5692+
"responses": {
5693+
"200": {
5694+
"description": "OK"
5695+
}
5696+
}
5697+
}
5698+
},
56695699
"/files/recycle/clear": {
56705700
"post": {
56715701
"security": [
@@ -16955,6 +16985,25 @@ const docTemplate = `{
1695516985
}
1695616986
}
1695716987
},
16988+
"request.FileReadByLineReq": {
16989+
"type": "object",
16990+
"required": [
16991+
"page",
16992+
"pageSize",
16993+
"path"
16994+
],
16995+
"properties": {
16996+
"page": {
16997+
"type": "integer"
16998+
},
16999+
"pageSize": {
17000+
"type": "integer"
17001+
},
17002+
"path": {
17003+
"type": "string"
17004+
}
17005+
}
17006+
},
1695817007
"request.FileRename": {
1695917008
"type": "object",
1696017009
"required": [

cmd/server/docs/swagger.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5659,6 +5659,36 @@
56595659
}
56605660
}
56615661
},
5662+
"/files/read": {
5663+
"post": {
5664+
"security": [
5665+
{
5666+
"ApiKeyAuth": []
5667+
}
5668+
],
5669+
"description": "按行读取文件",
5670+
"tags": [
5671+
"File"
5672+
],
5673+
"summary": "Read file by Line",
5674+
"parameters": [
5675+
{
5676+
"description": "request",
5677+
"name": "request",
5678+
"in": "body",
5679+
"required": true,
5680+
"schema": {
5681+
"$ref": "#/definitions/request.FileReadByLineReq"
5682+
}
5683+
}
5684+
],
5685+
"responses": {
5686+
"200": {
5687+
"description": "OK"
5688+
}
5689+
}
5690+
}
5691+
},
56625692
"/files/recycle/clear": {
56635693
"post": {
56645694
"security": [
@@ -16948,6 +16978,25 @@
1694816978
}
1694916979
}
1695016980
},
16981+
"request.FileReadByLineReq": {
16982+
"type": "object",
16983+
"required": [
16984+
"page",
16985+
"pageSize",
16986+
"path"
16987+
],
16988+
"properties": {
16989+
"page": {
16990+
"type": "integer"
16991+
},
16992+
"pageSize": {
16993+
"type": "integer"
16994+
},
16995+
"path": {
16996+
"type": "string"
16997+
}
16998+
}
16999+
},
1695117000
"request.FileRename": {
1695217001
"type": "object",
1695317002
"required": [

cmd/server/docs/swagger.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,19 @@ definitions:
29982998
required:
29992999
- path
30003000
type: object
3001+
request.FileReadByLineReq:
3002+
properties:
3003+
page:
3004+
type: integer
3005+
pageSize:
3006+
type: integer
3007+
path:
3008+
type: string
3009+
required:
3010+
- page
3011+
- pageSize
3012+
- path
3013+
type: object
30013014
request.FileRename:
30023015
properties:
30033016
newName:
@@ -7955,6 +7968,24 @@ paths:
79557968
formatEN: Change owner [paths] => [user]/[group]
79567969
formatZH: 修改用户/组 [paths] => [user]/[group]
79577970
paramKeys: []
7971+
/files/read:
7972+
post:
7973+
description: 按行读取文件
7974+
parameters:
7975+
- description: request
7976+
in: body
7977+
name: request
7978+
required: true
7979+
schema:
7980+
$ref: '#/definitions/request.FileReadByLineReq'
7981+
responses:
7982+
"200":
7983+
description: OK
7984+
security:
7985+
- ApiKeyAuth: []
7986+
summary: Read file by Line
7987+
tags:
7988+
- File
79587989
/files/recycle/clear:
79597990
post:
79607991
consumes:

frontend/src/api/interface/file.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ export namespace File {
164164
name: string;
165165
}
166166

167+
export interface FileReadByLine {
168+
path: string;
169+
page: number;
170+
pageSize: number;
171+
}
172+
167173
export interface Favorite extends CommonModel {
168174
path: string;
169175
isDir: boolean;

frontend/src/api/modules/files.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ export const AddFavorite = (path: string) => {
109109
return http.post<any>('files/favorite', { path: path });
110110
};
111111

112+
export const ReadByLine = (req: File.FileReadByLine) => {
113+
return http.post<any>('files/read', req);
114+
};
115+
112116
export const RemoveFavorite = (id: number) => {
113117
return http.post<any>('files/favorite/del', { id: id });
114118
};

frontend/src/views/website/runtime/php/index.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
</div>
4040
</template>
4141
</el-table-column>
42+
<el-table-column :label="$t('website.log')" prop="">
43+
<template #default="{ row }">
44+
<el-button @click="openLog(row)" link type="primary">{{ $t('website.check') }}</el-button>
45+
</template>
46+
</el-table-column>
4247
<el-table-column
4348
prop="createdAt"
4449
:label="$t('commons.table.date')"
@@ -61,6 +66,7 @@
6166

6267
<CreateRuntime ref="createRef" @close="search" />
6368
<OpDialog ref="opRef" @search="search" />
69+
<Log ref="logRef" @close="search" />
6470
</div>
6571
</template>
6672

@@ -74,6 +80,7 @@ import CreateRuntime from '@/views/website/runtime/php/create/index.vue';
7480
import Status from '@/components/status/index.vue';
7581
import i18n from '@/lang';
7682
import RouterMenu from '../index.vue';
83+
import Log from '@/views/website/runtime/php/log/index.vue';
7784
7885
const paginationConfig = reactive({
7986
cacheSizeKey: 'runtime-page-size',
@@ -89,6 +96,7 @@ let req = reactive<Runtime.RuntimeReq>({
8996
});
9097
let timer: NodeJS.Timer | null = null;
9198
const opRef = ref();
99+
const logRef = ref();
92100
93101
const buttons = [
94102
{
@@ -133,6 +141,10 @@ const openDetail = (row: Runtime.Runtime) => {
133141
createRef.value.acceptParams({ type: row.type, mode: 'edit', id: row.id, appID: row.appID });
134142
};
135143
144+
const openLog = (row: Runtime.RuntimeDTO) => {
145+
logRef.value.acceptParams({ path: row.path + '/' + 'build.log' });
146+
};
147+
136148
const openDelete = async (row: Runtime.Runtime) => {
137149
opRef.value.acceptParams({
138150
title: i18n.global.t('commons.msg.deleteTitle'),

0 commit comments

Comments
 (0)