getWPSFileCommon 公共方法:根据文件ID获取文件信息
(c *gin.Context, checkUser bool)
| 98 | |
| 99 | // getWPSFileCommon 公共方法:根据文件ID获取文件信息 |
| 100 | func getWPSFileCommon(c *gin.Context, checkUser bool) (*model.File, *weboffice.Error) { |
| 101 | // 获取文件ID参数 |
| 102 | fileIDStr := c.Param("file_id") |
| 103 | // 转换成 int64 |
| 104 | fileID, err := strconv.ParseInt(fileIDStr, 10, 64) |
| 105 | if err != nil { |
| 106 | return nil, weboffice.ErrInvalidArguments.WithMessage("无效的文件ID") |
| 107 | } |
| 108 | |
| 109 | ctx, err := weboffice.ParseContext(c.Request, checkUser) |
| 110 | if err != nil { |
| 111 | return nil, weboffice.ErrInvalidArguments.WithMessage(err.Error()) |
| 112 | } |
| 113 | |
| 114 | // 判断是否用户存在 |
| 115 | if checkUser && ctx.UserModel() == nil { |
| 116 | return nil, weboffice.ErrPermissionDenied.WithMessage("用户不存在") |
| 117 | } |
| 118 | |
| 119 | config, err := model.GetPlatformSettingByExternalID(ctx.Eid(), ctx.AppID(), model.PLATFORM_KEY_WPS) |
| 120 | if err != nil { |
| 121 | return nil, weboffice.ErrInternalError.WithMessage("获取平台配置失败") |
| 122 | } |
| 123 | if config == nil { |
| 124 | return nil, weboffice.ErrPermissionDenied.WithMessage("平台配置不存在") |
| 125 | } |
| 126 | |
| 127 | // 查询文件 |
| 128 | file, err := model.GetFileByID(config.Eid, fileID) |
| 129 | if err != nil { |
| 130 | return nil, weboffice.ErrFileNotExists |
| 131 | } |
| 132 | |
| 133 | file.LoadUploadFile() |
| 134 | |
| 135 | return file, nil |
| 136 | } |
| 137 | |
| 138 | // calculateFileHash 计算文件内容的SHA256哈希 |
| 139 | func calculateFileHash(fileContent []byte) string { |
no test coverage detected