数据导出

1.  接口描述

电子实验记录本的数据导出API接口,使用JSON格式进行数据交换。用于导出按存储的原始格式导出数据。

在调用API时,在Header里要加入如下的信息

Authorization: Bearer {AccessToken}

AccessToken 的获取方式,见“认证接口”

2.  接口调用

请求URL: https://eln.iphy.ac.cn:61262/eln_api/export
https://eln.iphy.ac.cn:61263/matelab/index.php?do=eln_api&action=export(已废弃)
https://eln.iphy.ac.cn:61263/open_eln/eln_api_export.php(已废弃)

参数

eln 选填,数组。要查询的记录本名称合集。所有指定的记录本必须是存放在同一服务器上的;如果此参数为空,则搜索范围为自己的所有记录本。记录本名称有两种表示方法,1. 字符串,自己的记录本名称。2. {“title": "记录本名称“, "user": "xxx@abc.com"},指定他人的记录本;
user 选填。字符串。如果是自己的记录本,可不填写;他人的合作编辑记录本,需要填写记录本所有者的Email
date_start 选填,日期格式字符串。搜索晚于此记录创建的日期的记录(包含当天);
date_end 选填,日期格式字符串。搜索早于此记录创建的日期的记录(包含当天);
keywords 选填,数组。在包含关键词中的记录中查找;
uids 选填,数组。要查找的记录的UID;

示例

{
    "eln": [
              "记录本名称1",
              "记录本名称2",
              {"title":"记录本名称2", "user":"xxx@abc.com"},
              {"title":"记录本名称3", "user":"xxxx@abc.com"}
    ],
    "date_start": "2000-1-1",
    "date_end": "2000-12-31",
    "keywords":  ["关键词1", "关键词2"],
    "uids":  ["uid1", "uid2"]
}

3.  返回数据

返回数据会包含所有符合条件的条目的原始存储数据。

code 错误代码;
  • 0: 成功;
  • 1: 认证 Token 信息无效;
  • 2: 输入数据格式错误;
  • 3: 服务器原因错误;
  • 'refresh': 认证 Token 过期,需使用刷新Token重新获取。
msg 错误描述;
dataset 数据集;
  • eln_name: 记录本名称
  • id: 数据项目ID
  • comm: 数据名称
  • data: 数据

示例

{
    "code": 0,
    "dataset": [{
        "eln_name": "记录本名称",
        "id": 1024,
        "comm": "数据名称",
        "data": [
            {
                "type": "richtext",
                "name": "富文本",
                "uid": "1234",
                "width": false,
                "data": "<p>Text</p>"
            },
            {
                "type": "form",
                "name": "表单1",
                "uid": "2s023322",
                "width": false,
                "data": [
                    {
                        "type": "date",
                        "uid": "sdfdfdf",
                        "required": false,
                        "name": "日期",
                        "date": "2000-1-1"
                    },
                    {
                        "type": "time",
                        "uid": "sdfdfdf",
                        "required": false,
                        "name": "时间",
                        "date": "23:59"
                    },
                    {
                        "type": "text",
                        "uid": "edf3",
                        "required": false,
                        "name": "文本",
                        "date": "text"
                    },
                    {
                        "type": "number",
                        "uid": "dddd",
                        "required": false,
                        "name": "数字",
                        "date": 1024
                    },
                    {
                        "type": "bool",
                        "uid": "dddd",
                        "name": "布尔值",
                        "date": true
                    },
                    {
                        "type": "file",
                        "uid": "dddd",
                        "name": "文件上传",
                        "date": {
                            "hash": "1234567890abcdef",
                            "filename": "a.zip",
                            "size": 1024
                        }
                    },
                    {
                        "type": "select",
                        "uid": "dddd",
                        "name": "选择",
                        "options": [
                            {"key": "a", "value": "1"},
                            {"key": "b", "value": "2"}
                        ]
                        "date": "2"
                    }
                ]
            },
            {
                "type": "table",
                "name": "表格1",
                "uid": "2s023322",
                "width": false,
                "data": [
                    {
                        "type": "date",
                        "name": "日期",
                        "data": ["2000-1-1","2000-1-1"]
                    },
                    {
                        "type": "time",
                        "name": "时间",
                        "date": ["23:59","23:59"]
                    },
                    {
                        "type": "text",
                        "name": "文本",
                        "date": ["text","text"]
                    },
                    {
                        "type": "number",
                        "name": "数字",
                       "date": [1024,1024]
                    },
                    {
                        "type": "bool",
                        "name": "布尔值",
                        "date": [true,true]
                    },
                    {
                        "type": "file",
                        "name": "文件上传",
                        "date": [
                            {
                                 "hash": "1234567890abcdef",
                                "filename": "a.zip",
                                "size": 1024
                            },
                            {
                                 "hash": "1234567890abcdef",
                                "filename": "a.zip",
                                "size": 1024
                            }
                        ]
                    },
                    {
                        "type": "select",
                        "name": "选择",
                        "options": [
                            {
                                "key": "a",
                                "value": "1"
                            },
                            {
                                "key": "b",
                                "value": "2"
                            }
                        ]
                        "date": ["2","2"]
                    }
                ]
            },
            {
                "type": "images",
                "name": "图片1",
                "uid": "2s023322",
                "width": false,
                "data": [
                    {
                        "hash": "1234567890abcdef",
                        "filename": "a.zip",
                        "size": 1024
                    },
                    {
                         "hash": "1234567890abcdef",
                        "filename": "a.zip",
                        "size": 1024
                    }
                ]
            }
        ]
    }
}

富文本中的超连接和图片如何变为可访问连接?

使用正则表达式,查找 符合 /="elnurl:\/\/([^>"]*)"/i 的字符串,替换为
="http://记录本服务器/eln_url/eln?token={用户token}&eln={记录本id}&i={记录id}&{正则匹配部分}"

上传的文件如何获得下载链接?

上传的文件在JSON中存储的格式为:
{"hash":"1234567890ABCDEFG", "size":12345, "filename":"filename.ext"}
使用这些信息,生成url
https://记录本服务器/eln_url/eln?token={用户token}&eln={记录本id}&i={记录id}&h={hash}&s={size}&f={filename}