MCPcopy Create free account
hub / github.com/53AI/53AIHub / getWPSFileUploadAddress

Function getWPSFileUploadAddress

api/controller/wps.go:512–646  ·  view source on GitHub ↗

getWPSFileUploadAddress 获取WPS文件上传地址

(c *gin.Context)

Source from the content-addressed store, hash-verified

510
511// getWPSFileUploadAddress 获取WPS文件上传地址
512func getWPSFileUploadAddress(c *gin.Context) (any, error) {
513 // 记录请求开始
514 logger.Infof(c, "开始处理WPS文件上传地址请求,文件ID: %s", c.Param("file_id"))
515
516 // 获取文件信息
517 file, wpsErr := getWPSFileCommon(c, true)
518 if wpsErr != nil {
519 logger.Errorf(c, "获取文件信息失败: %v", wpsErr)
520 return nil, wpsErr
521 }
522
523 // 验证文件是否存在
524 if file == nil {
525 logger.Error(c, "文件不存在")
526 return nil, weboffice.ErrFileNotExists
527 }
528
529 logger.Infof(c, "成功获取文件信息,文件ID: %d, 文件路径: %s", file.ID, file.Path)
530
531 // 解析请求体
532 var req UploadAddressRequest
533 if err := c.ShouldBindJSON(&req); err != nil {
534 logger.Errorf(c, "解析请求体失败: %v", err)
535 return nil, weboffice.ErrInvalidArguments.WithMessage("请求参数错误")
536 }
537
538 // 记录请求参数
539 logger.Infof(c, "请求参数 - 文件名: %s, 文件大小: %d, 摘要: %v, 是否手动: %v, 内容类型: %s",
540 req.Name, req.Size, req.Digest, req.IsManual, req.ContentType)
541
542 // 验证文件大小
543 if req.Size <= 0 {
544 logger.Errorf(c, "文件大小无效: %d", req.Size)
545 return nil, weboffice.ErrInvalidArguments.WithMessage("文件大小必须大于0")
546 }
547
548 // 验证摘要算法是否支持
549 if len(req.Digest) == 0 {
550 logger.Error(c, "摘要为空")
551 return nil, weboffice.ErrInvalidArguments.WithMessage("摘要不能为空")
552 }
553
554 supportedDigests := map[string]bool{"sha1": true, "md5": true, "sha256": true}
555 for digestType := range req.Digest {
556 if !supportedDigests[digestType] {
557 logger.Errorf(c, "不支持的摘要算法: %s", digestType)
558 return nil, weboffice.ErrInvalidArguments.WithMessage("不支持的摘要算法: " + digestType)
559 }
560 }
561
562 // 检查用户权限
563 ctx, err := weboffice.ParseContext(c.Request, true)
564 if err != nil {
565 logger.Errorf(c, "解析WPS上下文失败: %v", err)
566 return nil, weboffice.ErrInvalidArguments.WithMessage(err.Error())
567 }
568 if ctx.UserModel() == nil {
569 logger.Error(c, "用户不存在")

Callers

nothing calls this directly

Calls 9

getWPSFileCommonFunction · 0.85
InfofMethod · 0.80
ErrorfMethod · 0.80
WithMessageMethod · 0.80
EncodeMethod · 0.80
UserModelMethod · 0.65
ErrorMethod · 0.45
NewMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected