See https://github.com/EhTagTranslation/Editor
连接到 EhTagTranslation 数据库的 RESTful API。
https://ehtagconnector.azurewebsites.net/api/
使用 ETag 进行版本控制,其值为最新一次 Git commit 的 sha1 值。可以使用查询数据库数据版本 API 进行查询。
ETag将随HTTP 2XX及HTTP 404响应返回。对于
HEAD,GET请求,可以使用If-None-Match控制缓存。对于
POST,PUT,DELETE请求,必须使用If-Match头以防止编辑冲突。当未包含
If-Match头时,将返回HTTP 428 Precondition Required;当If-Match头的版本与最新版本不匹配时,将返回HTTP 412 Precondition Failed,此时需要使用对应的GET/HEAD请求更新ETag及相应的资源。
参考:HTTP 条件请求
进行数据库修改(POST, PUT, DELETE 请求)时需要进行用户认证,需要的信息为用户的 GitHub token,可通过 OAuth 或 PAT 获取。该 token 只用于确认用户信息,不需要除 public access 外的特殊 scope。
认证信息通过 X-Token HTTP 头输入(如 X-Token: e9b35fc3cd731c11d4e535724b1e376bfc2b3104)。当缺少此头部或 token 无效时返回 HTTP 401 Unauthorized,具体错误原因可查询响应内容。
使用 Accept 头或 format URI 查询参数控制 API 返回 JSON 的格式,可选的值有:
Accept: application/json/?format=json默认设置,返回所有信息。
{"name": {"raw": "轻音少女","text": "轻音少女","html": "<p>轻音少女</p>","ast": [{"type": "paragraph","content": [{"type": "text","text": "轻音少女"}]}]},"intro": {"raw": "","text": "","html": "<p><img src=\"https://ul.ehgt.org/ee/4f/ee4f3da314a2748030b53b9e495c8d20fd0d6fd5-1465878-5000-3501-jpg_l.jpg\" alt=\"图\" /></p>","ast": [{"type": "paragraph","content": [{"type": "image","title": "","url": "https://ul.ehgt.org/ee/4f/ee4f3da314a2748030b53b9e495c8d20fd0d6fd5-1465878-5000-3501-jpg_l.jpg","nsfw": false,"content": [{"type": "text","text": "图"}]}]}]},"links": {"raw": "","text": "","html": "","ast": []}}
Accept: application/raw+json/?format=raw.json仅返回
raw字段内容。{"name": "轻音少女","intro": "","links": ""}
Accept: application/html+json/?format=html.json仅返回
html字段内容。{"name": "<p>轻音少女</p>","intro": "<p><img src=\"https://ul.ehgt.org/ee/4f/ee4f3da314a2748030b53b9e495c8d20fd0d6fd5-1465878-5000-3501-jpg_l.jpg\" alt=\"图\" /></p>","links": ""}
Accept: application/text+json/?format=text.json仅返回
text字段内容。{"name": "轻音少女","intro": "","links": ""}
Accept: application/ast+json/?format=ast.json仅返回
ast字段内容。{"name": [{"type": "paragraph","content": [{"type": "text","text": "轻音少女"}]}],"intro": [{"type": "paragraph","content": [{"type": "image","title": "","url": "https://ul.ehgt.org/ee/4f/ee4f3da314a2748030b53b9e495c8d20fd0d6fd5-1465878-5000-3501-jpg_l.jpg","nsfw": false,"content": [{"type": "text","text": "图"}]}]}],"links": []}
所有示例可参见 examples.http,返回 JSON 对象的定义可参见 interface.d.ts。
路径: GET /database
示例请求:
GET /api/databaseAccept: application/jsonIf-None-Match: "5bd33aed633b18d5bca6b2d8c66dcf6b56bd75b1"示例响应:
HTTP/2.0 200 OKContent-Type: application/json; charset=utf-8ETag: "10ee33e7a348bf5842433944baa196da53eaa0df"{# Git 地址"repo": "https://github.com/EhTagTranslation/Database.git",# 最新一次提交信息"head": {"author": {"name": "OpportunityLiu","email": "Opportunity@live.in","when": "2019-02-06T14:06:00+00:00"},"committer": {"name": "EhTagApi-Bot","email": "47353891+EhTagApi-Bot@users.noreply.github.com","when": "2019-02-06T14:06:00+00:00"},"sha": "10ee33e7a348bf5842433944baa196da53eaa0df","message": "In parody: Added 'gotoubun no hanayome'.\n\nPrevious value: (non-existence)\nCurrent value: | gotoubun no hanayome | 五等分的新娘 | 《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。 | [维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (\\*) |\n"},# 数据库结构版本"version": 5,# 数据库内容摘要"data": [{"namespace": "rows","count": 9,"frontMatters": {"key": "rows","name": "内容索引","description": "标签列表的行名。"}}# ...]}如需获取数据库全部内容请参考获取数据库内容。
如只需获取 ETag 信息(即最新一次提交的 sha1),可以使用 HEAD 请求。
路径: HEAD /database
示例请求:
HEAD /api/databaseIf-None-Match: "5bd33aed633b18d5bca6b2d8c66dcf6b56bd75b1"示例响应:
HTTP/2.0 204 No ContentETag: "10ee33e7a348bf5842433944baa196da53eaa0df"路径: GET /database/:namespace
示例请求:
GET /api/database/reclassAccept: application/json示例响应:
HTTP/2.0 200 OKContent-Type: application/json; charset=utf-8ETag: "d4553b638098466ef013567b319c034f8ee34950"{"namespace": "reclass","count": 11,"frontMatters": {"key": "reclass","name": "重新分类","description": "标签列表的重新分类(reclass)翻译。","copyright": "除有特殊说明外,本文的简介文本翻译自 EHWiki,遵循原始许可协议(即 GNU 自由文档许可证)进行二次分发。\n\nCopyright (c) 2017 EhTagTranslator-Wiki. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled \"GNU Free Documentation License\".\n\n本文的其他内容,遵循知识共享(Creative Commons) 署名-非商业性使用-相同方式共享 3.0 协议提供。\n"}}路径: HEAD /database/:namespace/:raw
示例请求:
HEAD /api/database/reclass/private示例响应:
HTTP/2.0 204 No ContentETag: "d4553b638098466ef013567b319c034f8ee34950"条目不存在则返回
HTTP 404 Not Found。
路径: GET /database/:namespace/:raw
示例请求:
GET /api/database/male/shotacon?format=raw.jsonAccept: application/json示例响应:
HTTP/2.0 200 OKContent-Type: application/raw+json; charset=utf-8ETag: "d4553b638098466ef013567b319c034f8ee34950"{"name": "正太","intro": "小男孩。\n","links": ""}条目不存在则返回
HTTP 404 Not Found。
路径: POST /database/:namespace/:raw
示例请求:
POST /api/database/parody/gotoubun%20no%20hanayomeX-Token: e9b35fc3cd731c11d4e535724b1e376bfc2b3104If-Match: "5bd33aed633b18d5bca6b2d8c66dcf6b56bd75b1"Content-Type: application/jsonAccept: application/html+json
{
"name": "五等分的新娘",
"intro": "《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。 ",
"links": "[维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (*)"
}示例响应:
HTTP/2.0 201 CreatedContent-Type: application/html+json; charset=utf-8Location: /api/database/parody/gotoubun no hanayomeETag: "d4553b638098466ef013567b319c034f8ee34950"{"name": "<p>五等分的新娘</p>","intro": "<p>《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。</p>","links": "<p><a href=\"https://zh.wikipedia.org/zh-cn/五等分的新娘\" rel=\"nofollow\">维基百科</a> (*)</p>"}已有同名条目时将返回
HTTP 409 Conflict,需改用PUT请求。
路径: PUT /database/:namespace/:raw
示例请求:
PUT /api/database/reclass/privateX-Token: e9b35fc3cd731c11d4e535724b1e376bfc2b3104Content-Type: application/jsonIf-Match: "d4553b638098466ef013567b319c034f8ee34950"
{
"name": "私人的",
"intro": "私人画廊是一个非正式的类别,允许用户不与 E-Hentai 社区其他成员分享他们的内容。他们往往是想要成为自己的个人用户画廊,他们只是希望自己的朋友前来参观。",
"links": ""
}示例响应:
HTTP/2.0 200 OKContent-Type: application/ast+json; charset=utf-8ETag: "5bd33aed633b18d5bca6b2d8c66dcf6b56bd75b1"{"name": {"raw": "私人的","text": "私人的","html": "<p>私人的</p>","ast": [{"type": "paragraph","content": [{"type": "text","text": "私人的"}]}]},"intro": {"raw": "私人画廊是一个非正式的类别,允许用户不与 E-Hentai 社区其他成员分享他们的内容。他们往往是想要将其作为自己的个人用户画廊,或只是希望自己的朋友前来参观。从私人画廊获得的GP数量减少到上传者通常会收到的金额的10%。要创建私人图库,用户必须拥有铜星或更高星级。","text": "私人画廊是一个非正式的类别,允许用户不与 E-Hentai 社区其他成员分享他们的内容。他们往往是想要将其作为自己的个人用户画廊,或只是希望自己的朋友前来参观。从私人画廊获得的GP数量减少到上传者通常会收到的金额的10%。要创建私人图库,用户必须拥有铜星或更高星级。","html": "<p>私人画廊是一个非正式的类别,允许用户不与 E-Hentai 社区其他成员分享他们的内容。他们往往是想要将其作为自己的个人用户画廊,或只是希望自己的朋友前来参观。从私人画廊获得的GP数量减少到上传者通常会收到的金额的10%。要创建私人图库,用户必须拥有铜星或更高星级。</p>","ast": [{"type": "paragraph","content": [{"type": "text","text": "私人画廊是一个非正式的类别,允许用户不与 E-Hentai 社区其他成员分享他们的内容。他们往往是想要将其作为自己的个人用户画廊,或只是希望自己的朋友前来参观。从私人画廊获得的GP数量减少到上传者通常会收到的金额的10%。要创建私人图库,用户必须拥有铜星或更高星级。"}]}]},"links": {"raw": "","text": "","html": "","ast": []}}当请求内容与数据库内容一致时(未进行修改),将返回
HTTP 204 No Content。
条目不存在则返回
HTTP 404 Not Found,需改用POST请求。
路径: DELETE /database/:namespace/:raw
示例请求:
DELETE /api/database/reclass/privateX-Token: e9b35fc3cd731c11d4e535724b1e376bfc2b3104If-Match: "3b24693f057ccb422ce76a3334be549c66139309"示例响应:
HTTP/2.0 204 No ContentETag: "5bd33aed633b18d5bca6b2d8c66dcf6b56bd75b1"条目不存在则返回
HTTP 404 Not Found。
使用此 API 在不修改数据库的情况下格式化条目。
路径: POST /tools/normalize
示例请求:
POST /api/tools/normalize?format=ast.jsonContent-Type: application/json
{
"name": "五等分的新娘",
"intro": "《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。 ",
"links": "[维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (*)"
}示例响应:
HTTP/2.0 200 OKContent-Type: application/ast+json; charset=utf-8{"name": [{"type": "paragraph","content": [{"type": "text","text": "五等分的新娘"}]}],"intro": [{"type": "paragraph","content": [{"type": "text","text": "《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。"}]}],"links": [{"type": "paragraph","content": [{"type": "link","title": "","url": "https://zh.wikipedia.org/zh-cn/五等分的新娘","content": [{"type": "text","text": "维基百科"}]},{"type": "text","text": " (*)"}]}]}使用此 API 在不修改数据库的情况下将条目序列化为 MarkDown 表格行。
路径: POST /tools/serialize/:raw
示例请求:
POST /api/tools/serialize/gotoubun%20no%20hanayomeContent-Type: application/json
{
"name": "五等分的新娘",
"intro": "《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。 ",
"links": "[维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (*)"
}示例响应:
HTTP/2.0 200 OKContent-Type: text/plain; charset=utf-8| gotoubun no hanayome | 五等分的新娘 | 《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。 | [维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (*) |使用此 API 解析数据库中的 MarkDown 表格行。
路径: POST /tools/parse
示例请求:
POST /api/tools/parseAccept: application/raw+jsonContent-Type: text/plain| gotoubun no hanayome | 五等分的新娘 | 《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。 | [维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (*) |示例响应:
HTTP/2.0 200 OKContent-Type: application/raw+json; charset=utf-8{"key": "gotoubun no hanayome","value": {"name": "五等分的新娘","intro": "《五等分的新娘》(日语:五等分の花嫁)是由日本漫画家春场葱所创作的少年漫画作品。于《周刊少年Magazine》2017年第36・37合并号开始正式连载中。","links": "[维基百科](https://zh.wikipedia.org/zh-cn/五等分的新娘) (*)"}}