本文由AI翻译

为 ONLYOFFICE Workspace 自定义模块创建 API

简介

如果您为 ONLYOFFICE 创建了自己的模块,并根据这些说明将其添加到ONLYOFFICE Workspace,您还可以为此模块创建 API。

如何为自己的模块创建 API

  1. 创建一个类库项目(ASC.Api.Sample),并将其放置在 ...module\ASC.Api\ASC.Api.Sample 文件夹中。
    重要!!! 输出的 dll 文件名必须为 "ASC.Api.*.dll";
  2. ...\web\studio\ASC.Web.Studio\bin\ 连接所需的引用:
    ASC.Api.dll
    ASC.Web.Sample.dll
  3. 创建 SampleApi 类并实现 IApiEntryPoint 接口:
    public class SampleApi : IApiEntryPoint{public string Name{get { return "sample"; }}}
  4. 创建具有特定属性的公共方法:
    [Attributes.Create("create", false)]public SampleClass Create(string value){return SampleDao.Create(value);}

    属性指定方法的类型、调用此方法的路径、授权和资费计划的验证。可能的选项如下所示:

    CreateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //对应 "POST" 请求UpdateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //对应 "PUT" 请求DeleteAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //对应 "DELETE" 请求ReadAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //对应 "GET" 请求

    requiresAuthorizationcheckPayment 参数是可选的,默认值为 true

  5. 在项目属性中设置输出路径为:
    <OutputPath>..\..\..\web\studio\ASC.Web.Studio\bin\</OutputPath><DocumentationFile>..\..\..\web\studio\ASC.Web.Studio\bin\ASC.Api.Sample.XML</DocumentationFile>

    这样构建的文件将创建在 web\studio\ASC.Web.Studio\bin 文件夹中。

  6. 项目可以手动构建或使用构建器构建。对于后者,请在 build\msbuild\build.proj 文件中添加以下行:
    <ProjectToBuild Include="$(ASCDir)module\ASC.Api\ASC.Api.Sample\ASC.Api.Sample.csproj"/>

    然后运行 build\Build.bat 文件。

  7. 重要!!!ASC.Api.Sample.SampleApi 添加到 web\studio\ASC.Web.Studio\web.autofac.config 文件中:
    <componenttype="ASC.Api.Sample.SampleApi, ASC.Api.Sample"service="ASC.Api.Interfaces.IApiEntryPoint, ASC.Api"name="sample"/>
  8. 构建项目,运行网站,并通过 jQuery 发起请求测试方法:
    $.ajax({
        type: "POST",
        url: "http://localhost:port/api/2.0/sample/create.json",
        data: {value: "create"}});

在您自己的服务器上托管 ONLYOFFICE 工作区

文章: 标签:
浏览所有标签