Skip to content

Commit 92f3ec5

Browse files
xbingWawesomeYGdhsifss
authored
Feat/v2.37.0 (#235)
* feat: Update post type icons to use `Icon` component, add `prefetch={false}` to related links, and refine UI spacing. * feat: Add Yuque document import functionality with new API endpoints and UI components. * feat: support yuque export * fix: set content-type --------- Co-authored-by: awesomeYG <gang.yang@chaitin.com> Co-authored-by: 姚凯 <kai.yao@chaitin.com>
1 parent 515786c commit 92f3ec5

File tree

29 files changed

+866
-453
lines changed

29 files changed

+866
-453
lines changed

.github/workflows/build-base-img.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: anydoc
2525
dockerfile: docker/anydoc/Dockerfile
2626
context: docker/anydoc
27-
tag: "v0.9.9"
27+
tag: "v0.9.10"
2828
- name: db
2929
dockerfile: docker/db/Dockerfile
3030
context: docker/db

backend/docs/docs.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,94 @@ const docTemplate = `{
11141114
}
11151115
}
11161116
},
1117+
"/admin/kb/document/yuque/export": {
1118+
"post": {
1119+
"consumes": [
1120+
"application/json"
1121+
],
1122+
"produces": [
1123+
"application/json"
1124+
],
1125+
"tags": [
1126+
"document"
1127+
],
1128+
"summary": "export yuque document",
1129+
"parameters": [
1130+
{
1131+
"description": "request params",
1132+
"name": "req",
1133+
"in": "body",
1134+
"required": true,
1135+
"schema": {
1136+
"$ref": "#/definitions/svc.FileExportReq"
1137+
}
1138+
}
1139+
],
1140+
"responses": {
1141+
"200": {
1142+
"description": "OK",
1143+
"schema": {
1144+
"allOf": [
1145+
{
1146+
"$ref": "#/definitions/context.Response"
1147+
},
1148+
{
1149+
"type": "object",
1150+
"properties": {
1151+
"data": {
1152+
"type": "string"
1153+
}
1154+
}
1155+
}
1156+
]
1157+
}
1158+
}
1159+
}
1160+
}
1161+
},
1162+
"/admin/kb/document/yuque/list": {
1163+
"post": {
1164+
"consumes": [
1165+
"multipart/form-data"
1166+
],
1167+
"produces": [
1168+
"application/json"
1169+
],
1170+
"tags": [
1171+
"document"
1172+
],
1173+
"summary": "list yuque documents",
1174+
"parameters": [
1175+
{
1176+
"type": "file",
1177+
"description": "upload file",
1178+
"name": "file",
1179+
"in": "formData",
1180+
"required": true
1181+
}
1182+
],
1183+
"responses": {
1184+
"200": {
1185+
"description": "OK",
1186+
"schema": {
1187+
"allOf": [
1188+
{
1189+
"$ref": "#/definitions/context.Response"
1190+
},
1191+
{
1192+
"type": "object",
1193+
"properties": {
1194+
"data": {
1195+
"$ref": "#/definitions/svc.AnydocListRes"
1196+
}
1197+
}
1198+
}
1199+
]
1200+
}
1201+
}
1202+
}
1203+
}
1204+
},
11171205
"/admin/kb/space/remote": {
11181206
"post": {
11191207
"produces": [

backend/docs/swagger.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,94 @@
11071107
}
11081108
}
11091109
},
1110+
"/admin/kb/document/yuque/export": {
1111+
"post": {
1112+
"consumes": [
1113+
"application/json"
1114+
],
1115+
"produces": [
1116+
"application/json"
1117+
],
1118+
"tags": [
1119+
"document"
1120+
],
1121+
"summary": "export yuque document",
1122+
"parameters": [
1123+
{
1124+
"description": "request params",
1125+
"name": "req",
1126+
"in": "body",
1127+
"required": true,
1128+
"schema": {
1129+
"$ref": "#/definitions/svc.FileExportReq"
1130+
}
1131+
}
1132+
],
1133+
"responses": {
1134+
"200": {
1135+
"description": "OK",
1136+
"schema": {
1137+
"allOf": [
1138+
{
1139+
"$ref": "#/definitions/context.Response"
1140+
},
1141+
{
1142+
"type": "object",
1143+
"properties": {
1144+
"data": {
1145+
"type": "string"
1146+
}
1147+
}
1148+
}
1149+
]
1150+
}
1151+
}
1152+
}
1153+
}
1154+
},
1155+
"/admin/kb/document/yuque/list": {
1156+
"post": {
1157+
"consumes": [
1158+
"multipart/form-data"
1159+
],
1160+
"produces": [
1161+
"application/json"
1162+
],
1163+
"tags": [
1164+
"document"
1165+
],
1166+
"summary": "list yuque documents",
1167+
"parameters": [
1168+
{
1169+
"type": "file",
1170+
"description": "upload file",
1171+
"name": "file",
1172+
"in": "formData",
1173+
"required": true
1174+
}
1175+
],
1176+
"responses": {
1177+
"200": {
1178+
"description": "OK",
1179+
"schema": {
1180+
"allOf": [
1181+
{
1182+
"$ref": "#/definitions/context.Response"
1183+
},
1184+
{
1185+
"type": "object",
1186+
"properties": {
1187+
"data": {
1188+
"$ref": "#/definitions/svc.AnydocListRes"
1189+
}
1190+
}
1191+
}
1192+
]
1193+
}
1194+
}
1195+
}
1196+
}
1197+
},
11101198
"/admin/kb/space/remote": {
11111199
"post": {
11121200
"produces": [

backend/docs/swagger.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4328,6 +4328,57 @@ paths:
43284328
summary: list url documents
43294329
tags:
43304330
- document
4331+
/admin/kb/document/yuque/export:
4332+
post:
4333+
consumes:
4334+
- application/json
4335+
parameters:
4336+
- description: request params
4337+
in: body
4338+
name: req
4339+
required: true
4340+
schema:
4341+
$ref: '#/definitions/svc.FileExportReq'
4342+
produces:
4343+
- application/json
4344+
responses:
4345+
"200":
4346+
description: OK
4347+
schema:
4348+
allOf:
4349+
- $ref: '#/definitions/context.Response'
4350+
- properties:
4351+
data:
4352+
type: string
4353+
type: object
4354+
summary: export yuque document
4355+
tags:
4356+
- document
4357+
/admin/kb/document/yuque/list:
4358+
post:
4359+
consumes:
4360+
- multipart/form-data
4361+
parameters:
4362+
- description: upload file
4363+
in: formData
4364+
name: file
4365+
required: true
4366+
type: file
4367+
produces:
4368+
- application/json
4369+
responses:
4370+
"200":
4371+
description: OK
4372+
schema:
4373+
allOf:
4374+
- $ref: '#/definitions/context.Response'
4375+
- properties:
4376+
data:
4377+
$ref: '#/definitions/svc.AnydocListRes'
4378+
type: object
4379+
summary: list yuque documents
4380+
tags:
4381+
- document
43314382
/admin/kb/space/remote:
43324383
post:
43334384
parameters:

backend/pkg/anydoc/anydoc.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ func (a *anydoc) List(ctx context.Context, plat platform.PlatformType, optFuncs
212212
if err != nil {
213213
return nil, err
214214
}
215-
u.Path = p.ListURL()
216-
var contentType string
215+
u.Path = p.PathPrefix() + "/list"
217216

218217
var body io.Reader
219218
switch p.ListMethod() {
@@ -286,19 +285,23 @@ func (a *anydoc) List(ctx context.Context, plat platform.PlatformType, optFuncs
286285
return nil, err
287286
}
288287

289-
req.Header["X-Trace-ID"] = trace.TraceID(ctx)
290-
291-
if contentType != "" {
292-
req.Header.Set("Content-Type", contentType)
288+
if req.Method == http.MethodPost {
289+
req.Header.Set("Content-Type", "application/json")
293290
}
294291

292+
req.Header["X-Trace-ID"] = trace.TraceID(ctx)
293+
295294
resp, err := util.HTTPClient.Do(req)
296295
if err != nil {
297296
return nil, err
298297
}
299298

300299
defer resp.Body.Close()
301300

301+
if resp.StatusCode != http.StatusOK {
302+
return nil, fmt.Errorf("anydoc list failed, status code: %d", resp.StatusCode)
303+
}
304+
302305
var (
303306
docRes anydocRes[struct {
304307
Docs *tree.Node[ListDoc] `json:"docs"`
@@ -317,9 +320,6 @@ func (a *anydoc) List(ctx context.Context, plat platform.PlatformType, optFuncs
317320
return nil, err
318321
}
319322

320-
if resp.StatusCode != http.StatusOK {
321-
return nil, fmt.Errorf("anydoc list status code: %d", resp.StatusCode)
322-
}
323323
res.Docs = docRes.Data.Docs
324324

325325
return &res, nil
@@ -353,7 +353,7 @@ func (a *anydoc) Export(ctx context.Context, platform platform.PlatformType, id
353353
return "", err
354354
}
355355

356-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s", a.address, p.ExportURL()), bytes.NewReader(reqBodyBytes))
356+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s", a.address, p.PathPrefix()+"/export"), bytes.NewReader(reqBodyBytes))
357357
if err != nil {
358358
return "", err
359359
}
@@ -367,6 +367,10 @@ func (a *anydoc) Export(ctx context.Context, platform platform.PlatformType, id
367367

368368
defer resp.Body.Close()
369369

370+
if resp.StatusCode != http.StatusOK {
371+
return "", fmt.Errorf("anydoc export status code: %d", resp.StatusCode)
372+
}
373+
370374
var res anydocRes[string]
371375
err = json.NewDecoder(resp.Body).Decode(&res)
372376
if err != nil {
@@ -378,10 +382,6 @@ func (a *anydoc) Export(ctx context.Context, platform platform.PlatformType, id
378382
return "", err
379383
}
380384

381-
if resp.StatusCode != http.StatusOK {
382-
return "", fmt.Errorf("anydoc export status code: %d", resp.StatusCode)
383-
}
384-
385385
return res.Data, nil
386386
}
387387

@@ -395,7 +395,7 @@ func (a *anydoc) AuthURL(ctx context.Context, plat platform.PlatformType, reqDat
395395
if err != nil {
396396
return "", err
397397
}
398-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s", a.address, p.AuthURL()), bytes.NewReader(reqBytes))
398+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s", a.address, p.PathPrefix()+"/auth_url"), bytes.NewReader(reqBytes))
399399
if err != nil {
400400
return "", err
401401
}
@@ -435,7 +435,7 @@ func (a *anydoc) UserInfo(ctx context.Context, plat platform.PlatformType, reqDa
435435
if err != nil {
436436
return nil, err
437437
}
438-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s", a.address, p.UserInfoURL()), bytes.NewReader(reqBytes))
438+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s%s", a.address, p.PathPrefix()+"/user"), bytes.NewReader(reqBytes))
439439
if err != nil {
440440
return nil, err
441441
}

backend/pkg/anydoc/platform/dingtalk.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,22 @@ package platform
22

33
import "net/http"
44

5-
type dingtalk struct {
6-
prefix string
7-
}
5+
type dingtalk struct{}
86

97
func (s *dingtalk) Platform() PlatformType {
108
return PlatformDingtalk
119
}
1210

13-
func (s *dingtalk) ListURL() string {
14-
return s.prefix + "/list"
15-
}
16-
1711
func (s *dingtalk) ListMethod() string {
1812
return http.MethodPost
1913
}
2014

21-
func (s *dingtalk) ExportURL() string {
22-
return s.prefix + "/export"
23-
}
24-
25-
func (s *dingtalk) AuthURL() string {
26-
return s.prefix + "/auth_url"
27-
}
28-
29-
func (s *dingtalk) UserInfoURL() string {
30-
return s.prefix + "/user"
15+
func (d *dingtalk) PathPrefix() string {
16+
return "/api/docs/dingtalk"
3117
}
3218

3319
func newDingtalk() Platform {
34-
return &dingtalk{prefix: "/api/docs/dingtalk"}
20+
return &dingtalk{}
3521
}
3622

3723
func init() {

0 commit comments

Comments
 (0)