@@ -14,6 +14,7 @@ import (
1414 "treehole_next/utils/sensitive"
1515
1616 "github.com/gofiber/fiber/v2"
17+ "github.com/google/uuid"
1718 "github.com/opentreehole/go-common"
1819 "github.com/rs/zerolog/log"
1920 "gorm.io/gorm"
@@ -951,7 +952,13 @@ func DeleteHole(c *fiber.Ctx) error {
951952 return c .Status (204 ).JSON (nil )
952953}
953954func GenerateSummary (c * fiber.Ctx ) error {
954-
955+ uid , _ := common .GetUserID (c )
956+ if config .Config .WhiteListUserIds != nil && ! slices .Contains (config .Config .WhiteListUserIds , uid ) {
957+ return c .Status (404 ).JSON (fiber.Map {
958+ "code" : 404 ,
959+ "message" : "Cannot GET " + c .Path (),
960+ })
961+ }
955962 id , _ := c .ParamsInt ("id" )
956963 forceRefresh := c .QueryBool ("force_refresh" )
957964 var cachedData Summary
@@ -1041,6 +1048,7 @@ func GenerateSummary(c *fiber.Ctx) error {
10411048 if cachedData .Data .HoleID != id && cachedData .Data .HoleID != 0 {
10421049 log .Error ().
10431050 Int ("hole_id" , id ).
1051+ Str ("trace_id" , cachedData .TraceID ).
10441052 Int ("ai_server_return_id" , cachedData .Data .HoleID ).
10451053 Msg ("AISummary: hole id error" )
10461054 cachedData .Data .HoleID = id
@@ -1099,9 +1107,10 @@ func GenerateSummary(c *fiber.Ctx) error {
10991107 }
11001108
11011109 requestBody := map [string ]any {
1102- "floors" : summaryFloors ,
1103- "content" : content ,
1104- "hole_id" : hole .ID ,
1110+ "floors" : summaryFloors ,
1111+ "content" : content ,
1112+ "hole_id" : hole .ID ,
1113+ "trace_id" : uuid .NewString (),
11051114 }
11061115
11071116 requestJSON , err := json .Marshal (requestBody )
@@ -1128,6 +1137,7 @@ func GenerateSummary(c *fiber.Ctx) error {
11281137 if resp .StatusCode != http .StatusOK {
11291138 log .Error ().
11301139 Str ("url" , config .Config .AISummaryURL + "/generate_summary" ).
1140+ Str ("trace_id" , requestBody ["trace_id" ].(string )).
11311141 Int ("status" , resp .StatusCode ).
11321142 Str ("req_body_base64" , func () string {
11331143 if len (requestJSON ) > config .Config .SummaryLogLimit {
@@ -1151,6 +1161,7 @@ func GenerateSummary(c *fiber.Ctx) error {
11511161 if err != nil {
11521162 log .Error ().
11531163 Str ("url" , config .Config .AISummaryURL + "/generate_summary" ).
1164+ Str ("trace_id" , requestBody ["trace_id" ].(string )).
11541165 Int ("status" , resp .StatusCode ).
11551166 Str ("req_body_base64" , func () string {
11561167 if len (requestJSON ) > config .Config .SummaryLogLimit {
@@ -1184,6 +1195,7 @@ func GenerateSummary(c *fiber.Ctx) error {
11841195 response .Message = errCode2Message [response .Code ]
11851196 default :
11861197 log .Error ().Str ("url" , config .Config .AISummaryURL + "/generate_summary" ).
1198+ Str ("trace_id" , requestBody ["trace_id" ].(string )).
11871199 Int ("status" , resp .StatusCode ).
11881200 Str ("req_body_base64" , func () string {
11891201 if len (requestJSON ) > config .Config .SummaryLogLimit {
0 commit comments