-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathsiteinfo_controller.go
More file actions
721 lines (668 loc) · 23.5 KB
/
siteinfo_controller.go
File metadata and controls
721 lines (668 loc) · 23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package controller_admin
import (
"html"
"net/http"
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/base/middleware"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/siteinfo"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/log"
)
// SiteInfoController site info controller
type SiteInfoController struct {
siteInfoService *siteinfo.SiteInfoService
}
// NewSiteInfoController new site info controller
func NewSiteInfoController(siteInfoService *siteinfo.SiteInfoService) *SiteInfoController {
return &SiteInfoController{
siteInfoService: siteInfoService,
}
}
// GetGeneral get site general information
// @Summary get site general information
// @Description get site general information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteGeneralResp}
// @Router /answer/admin/api/siteinfo/general [get]
func (sc *SiteInfoController) GetGeneral(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteGeneral(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetInterface get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteInterfaceSettingsResp}
// @Router /answer/admin/api/siteinfo/interface [get]
func (sc *SiteInfoController) GetInterface(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteInterface(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetUsersSettings get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteUsersSettingsResp}
// @Router /answer/admin/api/siteinfo/users-settings [get]
func (sc *SiteInfoController) GetUsersSettings(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteUsersSettings(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteBranding get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteBrandingResp}
// @Router /answer/admin/api/siteinfo/branding [get]
func (sc *SiteInfoController) GetSiteBranding(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteBranding(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteTag get site tags setting
// @Summary get site tags setting
// @Description get site tags setting
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteTagsResp}
// @Router /answer/admin/api/siteinfo/tag [get]
func (sc *SiteInfoController) GetSiteTag(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteTag(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteQuestion get site questions setting
// @Summary get site questions setting
// @Description get site questions setting
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteQuestionsResp}
// @Router /answer/admin/api/siteinfo/question [get]
func (sc *SiteInfoController) GetSiteQuestion(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteQuestion(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteAdvanced get site advanced setting
// @Summary get site advanced setting
// @Description get site advanced setting
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteAdvancedResp}
// @Router /answer/admin/api/siteinfo/advanced [get]
func (sc *SiteInfoController) GetSiteAdvanced(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteAdvanced(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSitePolicies Get the policies information for the site
// @Summary Get the policies information for the site
// @Description Get the policies information for the site
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SitePoliciesResp}
// @Router /answer/admin/api/siteinfo/polices [get]
func (sc *SiteInfoController) GetSitePolicies(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSitePolicies(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteSecurity Get the security information for the site
// @Summary Get the security information for the site
// @Description Get the security information for the site
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteSecurityResp}
// @Router /answer/admin/api/siteinfo/security [get]
func (sc *SiteInfoController) GetSiteSecurity(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteSecurity(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSeo get site seo information
// @Summary get site seo information
// @Description get site seo information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteSeoResp}
// @Router /answer/admin/api/siteinfo/seo [get]
func (sc *SiteInfoController) GetSeo(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSeo(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteLogin get site info login config
// @Summary get site info login config
// @Description get site info login config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteLoginResp}
// @Router /answer/admin/api/siteinfo/login [get]
func (sc *SiteInfoController) GetSiteLogin(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteLogin(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteCustomCssHTML get site info custom html css config
// @Summary get site info custom html css config
// @Description get site info custom html css config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteCustomCssHTMLResp}
// @Router /answer/admin/api/siteinfo/custom-css-html [get]
func (sc *SiteInfoController) GetSiteCustomCssHTML(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteCustomCssHTML(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteTheme get site info theme config
// @Summary get site info theme config
// @Description get site info theme config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteThemeResp}
// @Router /answer/admin/api/siteinfo/theme [get]
func (sc *SiteInfoController) GetSiteTheme(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteTheme(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteUsers get site user config
// @Summary get site user config
// @Description get site user config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteUsersResp}
// @Router /answer/admin/api/siteinfo/users [get]
func (sc *SiteInfoController) GetSiteUsers(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteUsers(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetRobots get site robots information
// @Summary get site robots information
// @Description get site robots information
// @Tags site
// @Produce json
// @Success 200 {string} txt ""
// @Router /robots.txt [get]
func (sc *SiteInfoController) GetRobots(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSeo(ctx)
if err != nil {
ctx.String(http.StatusOK, "")
return
}
ctx.String(http.StatusOK, resp.Robots)
}
// GetCss get site custom CSS
// @Summary get site custom CSS
// @Description get site custom CSS
// @Tags site
// @Produce text/css
// @Success 200 {string} css ""
// @Router /custom.css [get]
func (sc *SiteInfoController) GetCss(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteCustomCssHTML(ctx)
if err != nil {
ctx.String(http.StatusOK, "")
return
}
ctx.Header("content-type", "text/css;charset=utf-8")
ctx.String(http.StatusOK, resp.CustomCss)
}
// UpdateSeo update site seo information
// @Summary update site seo information
// @Description update site seo information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteSeoReq true "seo"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/seo [put]
func (sc *SiteInfoController) UpdateSeo(ctx *gin.Context) {
req := schema.SiteSeoReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSeo(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateGeneral update site general information
// @Summary update site general information
// @Description update site general information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteGeneralReq true "general"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/general [put]
func (sc *SiteInfoController) UpdateGeneral(ctx *gin.Context) {
req := schema.SiteGeneralReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSiteGeneral(ctx, req)
req.Name = html.UnescapeString(req.Name)
handler.HandleResponse(ctx, err, req)
}
// UpdateInterface update site interface
// @Summary update site info interface
// @Description update site info interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteInterfaceReq true "general"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/interface [put]
func (sc *SiteInfoController) UpdateInterface(ctx *gin.Context) {
req := schema.SiteInterfaceReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSiteInterface(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateUsersSettings update users settings
// @Summary update site info users settings
// @Description update site info users settings
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteUsersSettingsReq true "general"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/users-settings [put]
func (sc *SiteInfoController) UpdateUsersSettings(ctx *gin.Context) {
req := schema.SiteUsersSettingsReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSiteUsersSettings(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateBranding update site branding
// @Summary update site info branding
// @Description update site info branding
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteBrandingReq true "branding info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/branding [put]
func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) {
req := &schema.SiteBrandingReq{}
if handler.BindAndCheck(ctx, req) {
return
}
currentBranding, getBrandingErr := sc.siteInfoService.GetSiteBranding(ctx)
if getBrandingErr == nil {
cleanUpErr := sc.siteInfoService.CleanUpRemovedBrandingFiles(ctx, req, currentBranding)
if cleanUpErr != nil {
log.Errorf("failed to clean up removed branding file(s): %v", cleanUpErr)
}
} else {
log.Errorf("failed to get current site branding: %v", getBrandingErr)
}
saveErr := sc.siteInfoService.SaveSiteBranding(ctx, req)
handler.HandleResponse(ctx, saveErr, nil)
}
// UpdateSiteQuestion update site question settings
// @Summary update site question settings
// @Description update site question settings
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteQuestionsReq true "questions settings"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/question [put]
func (sc *SiteInfoController) UpdateSiteQuestion(ctx *gin.Context) {
req := &schema.SiteQuestionsReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := sc.siteInfoService.SaveSiteQuestions(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSiteTag update site tag settings
// @Summary update site tag settings
// @Description update site tag settings
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteTagsReq true "tags settings"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/tag [put]
func (sc *SiteInfoController) UpdateSiteTag(ctx *gin.Context) {
req := &schema.SiteTagsReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := sc.siteInfoService.SaveSiteTags(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSiteAdvanced update site advanced info
// @Summary update site advanced info
// @Description update site advanced info
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteAdvancedReq true "advanced settings"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/advanced [put]
func (sc *SiteInfoController) UpdateSiteAdvanced(ctx *gin.Context) {
req := &schema.SiteAdvancedReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := sc.siteInfoService.SaveSiteAdvanced(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSitePolices update site policies configuration
// @Summary update site policies configuration
// @Description update site policies configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SitePoliciesReq true "write info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/polices [put]
func (sc *SiteInfoController) UpdateSitePolices(ctx *gin.Context) {
req := &schema.SitePoliciesReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSitePolicies(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteSecurity update site security configuration
// @Summary update site security configuration
// @Description update site security configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteSecurityReq true "write info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/security [put]
func (sc *SiteInfoController) UpdateSiteSecurity(ctx *gin.Context) {
req := &schema.SiteSecurityReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteSecurity(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteLogin update site login
// @Summary update site login
// @Description update site login
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteLoginReq true "login info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/login [put]
func (sc *SiteInfoController) UpdateSiteLogin(ctx *gin.Context) {
req := &schema.SiteLoginReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteLogin(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteCustomCssHTML update site custom css html config
// @Summary update site custom css html config
// @Description update site custom css html config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteCustomCssHTMLReq true "login info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/custom-css-html [put]
func (sc *SiteInfoController) UpdateSiteCustomCssHTML(ctx *gin.Context) {
req := &schema.SiteCustomCssHTMLReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteCustomCssHTML(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// SaveSiteTheme update site custom css html config
// @Summary update site custom css html config
// @Description update site custom css html config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteThemeReq true "login info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/theme [put]
func (sc *SiteInfoController) SaveSiteTheme(ctx *gin.Context) {
req := &schema.SiteThemeReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteTheme(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteUsers update site config about users
// @Summary update site info config about users
// @Description update site info config about users
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteUsersReq true "users info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/users [put]
func (sc *SiteInfoController) UpdateSiteUsers(ctx *gin.Context) {
req := &schema.SiteUsersReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteUsers(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetSMTPConfig get smtp config
// @Summary GetSMTPConfig get smtp config
// @Description GetSMTPConfig get smtp config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.GetSMTPConfigResp}
// @Router /answer/admin/api/setting/smtp [get]
func (sc *SiteInfoController) GetSMTPConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSMTPConfig(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSMTPConfig update smtp config
// @Summary update smtp config
// @Description update smtp config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.UpdateSMTPConfigReq true "smtp config"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/setting/smtp [put]
func (sc *SiteInfoController) UpdateSMTPConfig(ctx *gin.Context) {
req := &schema.UpdateSMTPConfigReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.UpdateSMTPConfig(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetPrivilegesConfig get privileges config
// @Summary GetPrivilegesConfig get privileges config
// @Description GetPrivilegesConfig get privileges config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.GetPrivilegesConfigResp}
// @Router /answer/admin/api/setting/privileges [get]
func (sc *SiteInfoController) GetPrivilegesConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetPrivilegesConfig(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdatePrivilegesConfig update privileges config
// @Summary update privileges config
// @Description update privileges config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.UpdatePrivilegesConfigReq true "config"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/setting/privileges [put]
func (sc *SiteInfoController) UpdatePrivilegesConfig(ctx *gin.Context) {
req := &schema.UpdatePrivilegesConfigReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.UpdatePrivilegesConfig(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetAIConfig get AI configuration
// @Summary get AI configuration
// @Description get AI configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteAIResp}
// @Router /answer/admin/api/ai-config [get]
func (sc *SiteInfoController) GetAIConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteAI(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateAIConfig update AI configuration
// @Summary update AI configuration
// @Description update AI configuration
// @Security ApiKeyAuth
// @Tags admin
// @Param data body schema.SiteAIReq true "AI config"
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/ai-config [put]
func (sc *SiteInfoController) UpdateAIConfig(ctx *gin.Context) {
req := &schema.SiteAIReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteAI(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetAIPromptConfig get AI prompt configuration
// @Summary get AI prompt configuration
// @Description get AI prompt configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.AIPromptConfig}
// @Router /answer/admin/api/ai-prompt-config [get]
func (sc *SiteInfoController) GetAIPromptConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetAIPromptConfig(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateAIPromptConfig update AI prompt configuration
// @Summary update AI prompt configuration
// @Description update AI prompt configuration
// @Security ApiKeyAuth
// @Tags admin
// @Param data body schema.AIPromptConfig true "AI prompt config"
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/ai-prompt-config [put]
func (sc *SiteInfoController) UpdateAIPromptConfig(ctx *gin.Context) {
req := &schema.AIPromptConfig{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveAIPromptConfig(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetAIProvider get AI provider configuration
// @Summary get AI provider configuration
// @Description get AI provider configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=[]schema.GetAIProviderResp}
// @Router /answer/admin/api/ai-provider [get]
func (sc *SiteInfoController) GetAIProvider(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetAIProvider(ctx)
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
handler.HandleResponse(ctx, nil, resp)
}
// RequestAIModels get AI models
// @Summary get AI models
// @Description get AI models
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=[]schema.GetAIModelResp}
// @Router /answer/admin/api/ai-models [post]
func (sc *SiteInfoController) RequestAIModels(ctx *gin.Context) {
req := &schema.GetAIModelsReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := sc.siteInfoService.GetAIModels(ctx, req)
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
handler.HandleResponse(ctx, nil, resp)
}
// GetMCPConfig get MCP configuration
// @Summary get MCP configuration
// @Description get MCP configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteMCPResp}
// @Router /answer/admin/api/mcp-config [get]
func (sc *SiteInfoController) GetMCPConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteMCP(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateMCPConfig update MCP configuration
// @Summary update MCP configuration
// @Description update MCP configuration
// @Security ApiKeyAuth
// @Tags admin
// @Param data body schema.SiteMCPReq true "MCP config"
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/mcp-config [put]
func (sc *SiteInfoController) UpdateMCPConfig(ctx *gin.Context) {
req := &schema.SiteMCPReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteMCP(ctx, req)
handler.HandleResponse(ctx, err, nil)
}