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

Function getWPSFileCommon

api/controller/wps.go:100–136  ·  view source on GitHub ↗

getWPSFileCommon 公共方法:根据文件ID获取文件信息

(c *gin.Context, checkUser bool)

Source from the content-addressed store, hash-verified

98
99// getWPSFileCommon 公共方法:根据文件ID获取文件信息
100func 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哈希
139func calculateFileHash(fileContent []byte) string {

Callers 7

getWPSFileFunction · 0.85
getWPSFileDownloadFunction · 0.85
getWPSFilePermissionFunction · 0.85
renameWPSFileFunction · 0.85
prepareWPSFileUploadFunction · 0.85
getWPSFileUploadAddressFunction · 0.85
completeWPSFileUploadFunction · 0.85

Calls 6

WithMessageMethod · 0.80
LoadUploadFileMethod · 0.80
UserModelMethod · 0.65
EidMethod · 0.65
AppIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected