public Task <GetFileByVersionResult> Version(int version) { return(Task.Run(() => { var request = FilterRequestForWPS(Request); if (!request.Status) { return new GetFileByVersionResult { code = request.code, msg = request.msg }; } // 从数据库查询文件信息...... // 创建时间和修改时间默认全是现在 var now = TimestampHelper.GetCurrentTimestamp(); var result = new GetFileByVersionResult { id = request.FileId, name = "文件名", version = 1, size = 1024, create_time = now, creator = "创建者用户名", modify_time = now, modifier = "修改者用户名", download_url = "文件下载url" }; return result; })); }
public Task <FileInfoResult> FileInfo() { return(Task.Run(() => { // 简单的过滤下不合理的请求,可注释,以下接口基本上都有此过滤 var request = FilterRequestForWPS(Request); if (!request.Status) { return new FileInfoResult { code = request.code, msg = request.msg }; } // 获取自定义参数 var userId = request.Params["_w_userId"].ToString(); // 从数据库查询用户名、文件 等信息...... // 创建时间和修改时间默认全是现在,可更改,但是注意时间戳是11位的(秒) var now = TimestampHelper.GetCurrentTimestamp(); var result = new FileInfoResult { file = new Model.WPSFile { id = request.FileId, name = "文件名", version = 1, size = 1024, // WPS单位是B create_time = now, creator = "创建者用户名", modify_time = now, modifier = "修改者用户名", download_url = "文件下载链接", user_acl = new User_acl { history = 1, // 允许查看历史版本 rename = 1, // 允许重命名 copy = 1 // 允许复制 }, watermark = new Watermark { type = 0, // 1为有水印 value = "水印文字" } }, user = new UserForFile() { id = userId, name = "用户名", //permission = "read", permission = "write", // write为允许编辑,read为只能查看 avatar_url = "用户头像url", } }; return result; })); }
public JsonResult Version(int version) { _log.WriteInfo("开始请求接口【file/version】"); GetFileByVersionResult result = new GetFileByVersionResult(); try { var request = GetFilterRequest.GetParams(HttpContext.ApplicationInstance.Request); if (!request.Status) { result.code = request.code; result.message = request.message; result.details = request.details; result.hint = request.hint; } else { // 从数据库查询文件信息...... // 创建时间和修改时间默认全是现在 var now = TimestampHelper.GetCurrentTimestamp(); var fileName = version == 1 ? "TestFile_v1.docx" : (version == 2 ? "TestFile_v2.docx" : "TestFile.docx"); string filePath = Server.MapPath($"/Files/{fileName}"); result.file = new GetFileResult { id = request.FileId, name = fileName, version = version, size = FileHelper.FileSize(filePath), // WPS单位是B, create_time = now, creator = "天玺", modify_time = now, modifier = "天玺", download_url = $"{ConfigurationManager.AppSettings["WPSTokenUrl"]}/Files/{fileName}" }; } } catch (Exception ex) { _log.WriteError("【系统异常】-【" + ex.Message + "】", ex); result.code = (int)Enumerator.ErrorCode.ServerError; result.message = Enumerator.ErrorCode.ServerError.ToString(); result.details = result.hint = EnumExtension.GetDescription(Enumerator.ErrorCode.ServerError); } _log.WriteInfo("请求接口【file/version】完成,返回数据:" + JsonConvert.SerializeObject(result)); return(Json(result, JsonRequestBehavior.AllowGet)); }
public Task <GetHistoryResult> GetHistory(GetHistoryRequest body) { return(Task.Run(() => { var request = FilterRequestForWPS(Request); if (!request.Status) { return new GetHistoryResult { code = request.code, msg = request.msg }; } // 从数据库查询用户、文件信息等...... // 创建时间和修改时间默认全是现在 var now = TimestampHelper.GetCurrentTimestamp(); // 不需要使用历史版本功能的此处也请返回,如果此接口不通时,文档加载会报错:“GetFileInfoFailed” var result = new GetHistoryResult { histories = new List <HistroyModel> { new HistroyModel { id = request.FileId, name = "文件名", size = 1024, // 单位B version = 1, download_url = "文件下载链接", create_time = now, modify_time = now, creator = new UserModel { id = "创建者ID", name = "创建者名", avatar_url = "创建者头像url" }, modifier = new UserModel { id = "修改者ID", name = "修改者名", avatar_url = "修改者头像url" } } } }; return result; })); }
public JsonResult FileInfo() { _log.WriteInfo("开始请求接口【file/info】"); FileInfoResult result = new FileInfoResult(); try { var request = GetFilterRequest.GetParams(HttpContext.ApplicationInstance.Request); if (!request.Status) { result.code = request.code; result.message = request.message; result.details = request.details; result.hint = request.hint; } else { // 获取自定义参数 var userId = request.Params["_w_userId"].ToString(); //用户ID var fileId = request.FileId; //文件ID #region >>>从数据库查询用户名、文件 等信息......<<< #endregion #region >>>示例<<< // 创建时间和修改时间默认全是现在,可更改,但是注意时间戳是11位的(秒) var now = TimestampHelper.GetCurrentTimestamp(); var fileName = request.FileId == "1000" ? "TestFile.docx" : (request.FileId == "1001" ? "TestFile_v1.docx" : "TestFile_v2.docx"); int version = request.FileId == "1000" ? 5 : (request.FileId == "1001" ? 1 : 2); string filePath = Server.MapPath($"/Files/{fileName}"); result.file = new WPSFile { id = "1000", name = "TestFile.docx", // 如果线下修改后将修改此版本重新上传 version = 5, size = FileHelper.FileSize(filePath), // WPS单位是B create_time = now, creator = "天玺", modify_time = now, modifier = "天玺", download_url = $"{ConfigurationManager.AppSettings["WPSTokenUrl"]}/Files/{fileName}", user_acl = new User_acl { history = 1, // 允许查看历史版本 rename = 1, // 允许重命名 copy = 1, // 允许复制 export = 1, }, watermark = new Watermark { type = 1, // 1为有水印 value = "水印文字" } }; result.user = new UserForFile() { id = "1000", name = "天玺", //permission = "read", permission = "write", // write为允许编辑,read为只能查看 avatar_url = $"{ConfigurationManager.AppSettings["WPSTokenUrl"]}/Images/photo1.jpg", }; #endregion } } catch (Exception ex) { _log.WriteError("【系统异常】-【" + ex.Message + "】", ex); result.code = (int)Enumerator.ErrorCode.ServerError; result.message = Enumerator.ErrorCode.ServerError.ToString(); result.details = result.hint = EnumExtension.GetDescription(Enumerator.ErrorCode.ServerError); } _log.WriteInfo("请求接口【file/info】完成,返回数据:" + JsonConvert.SerializeObject(result)); return(Json(result, JsonRequestBehavior.AllowGet)); }