fix: lesson plan permission.
This commit is contained in:
+7
-2
@@ -256,7 +256,7 @@ func callAIForAnalysis(prompt string) (*aiAnalysisResult, error) {
|
|||||||
},
|
},
|
||||||
Temperature: 0.6,
|
Temperature: 0.6,
|
||||||
TopP: 0.6,
|
TopP: 0.6,
|
||||||
MaxTokens: 4000,
|
MaxCompletionTokens: 4000,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -419,6 +419,11 @@ func (tc *TrainingController) streamAIAnalysis(c *gin.Context, prompt string,
|
|||||||
regionID *uint32, trainID, sourceType, analysisType string,
|
regionID *uint32, trainID, sourceType, analysisType string,
|
||||||
originalFileSize, compressedContentSize int64, uploadTime int64) {
|
originalFileSize, compressedContentSize int64, uploadTime int64) {
|
||||||
|
|
||||||
|
sizeInBytes := len(prompt)
|
||||||
|
sizeInKB := float64(sizeInBytes) / 1024.0
|
||||||
|
|
||||||
|
log.Printf("=== 发送给流式 AI 的内容大小: %.2f KB (%d 字节) ===", sizeInKB, sizeInBytes)
|
||||||
|
|
||||||
c.Writer.Header().Set("Content-Type", "text/event-stream")
|
c.Writer.Header().Set("Content-Type", "text/event-stream")
|
||||||
c.Writer.Header().Set("Cache-Control", "no-cache")
|
c.Writer.Header().Set("Cache-Control", "no-cache")
|
||||||
c.Writer.Header().Set("Connection", "keep-alive")
|
c.Writer.Header().Set("Connection", "keep-alive")
|
||||||
@@ -450,7 +455,7 @@ func (tc *TrainingController) streamAIAnalysis(c *gin.Context, prompt string,
|
|||||||
},
|
},
|
||||||
Temperature: 0.6,
|
Temperature: 0.6,
|
||||||
TopP: 0.6,
|
TopP: 0.6,
|
||||||
MaxTokens: 4000,
|
MaxCompletionTokens: 4000,
|
||||||
Stream: true,
|
Stream: true,
|
||||||
StreamOptions: &openai.StreamOptions{
|
StreamOptions: &openai.StreamOptions{
|
||||||
IncludeUsage: true,
|
IncludeUsage: true,
|
||||||
|
|||||||
@@ -148,8 +148,20 @@ func (lc *LessonPlanController) Upload(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lc *LessonPlanController) List(c *gin.Context) {
|
func (lc *LessonPlanController) List(c *gin.Context) {
|
||||||
|
userID, _, ok := currentUser(c)
|
||||||
|
if !ok {
|
||||||
|
writeError(c, http.StatusUnauthorized, "invalid user context")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
role := currentUserRole(c)
|
||||||
|
|
||||||
|
query := lc.DB.Where("file_type = ?", models.AppFileTypeLessonPlan)
|
||||||
|
if role != models.UserRoleSuperAdmin && role != models.UserRoleRegionAdmin {
|
||||||
|
query = query.Where("uploader_id = ?", userID)
|
||||||
|
}
|
||||||
|
|
||||||
var records []models.AppFile
|
var records []models.AppFile
|
||||||
if err := lc.DB.Where("file_type = ?", models.AppFileTypeLessonPlan).Order("created_at DESC").Find(&records).Error; err != nil {
|
if err := query.Order("created_at DESC").Find(&records).Error; err != nil {
|
||||||
writeError(c, http.StatusInternalServerError, "failed to list lesson plans")
|
writeError(c, http.StatusInternalServerError, "failed to list lesson plans")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -157,6 +169,13 @@ func (lc *LessonPlanController) List(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lc *LessonPlanController) Page(c *gin.Context) {
|
func (lc *LessonPlanController) Page(c *gin.Context) {
|
||||||
|
userID, _, ok := currentUser(c)
|
||||||
|
if !ok {
|
||||||
|
writeError(c, http.StatusUnauthorized, "invalid user context")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
role := currentUserRole(c)
|
||||||
|
|
||||||
var params lessonPlanPaginationParams
|
var params lessonPlanPaginationParams
|
||||||
if err := c.ShouldBindQuery(¶ms); err != nil {
|
if err := c.ShouldBindQuery(¶ms); err != nil {
|
||||||
writeError(c, http.StatusBadRequest, err.Error())
|
writeError(c, http.StatusBadRequest, err.Error())
|
||||||
@@ -173,6 +192,9 @@ func (lc *LessonPlanController) Page(c *gin.Context) {
|
|||||||
var total int64
|
var total int64
|
||||||
var records []models.AppFile
|
var records []models.AppFile
|
||||||
query := lc.DB.Model(&models.AppFile{}).Where("file_type = ?", models.AppFileTypeLessonPlan)
|
query := lc.DB.Model(&models.AppFile{}).Where("file_type = ?", models.AppFileTypeLessonPlan)
|
||||||
|
if role != models.UserRoleSuperAdmin && role != models.UserRoleRegionAdmin {
|
||||||
|
query = query.Where("uploader_id = ?", userID)
|
||||||
|
}
|
||||||
if err := query.Count(&total).Error; err != nil {
|
if err := query.Count(&total).Error; err != nil {
|
||||||
writeError(c, http.StatusInternalServerError, "failed to count lesson plans")
|
writeError(c, http.StatusInternalServerError, "failed to count lesson plans")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user