|
1 | | -# HoYoRandom |
| 1 | +# RandomAPI |
2 | 2 |
|
3 | | -   |
| 3 | +   |
4 | 4 |
|
5 | 5 | 一个使用 node.js 编写的随机 API: |
6 | 6 |
|
7 | | -- 丰富的选项 |
8 | | -- API 和资源文件分离,自动更新 |
9 | | -- 支持自部署,可以使用你自己的资源(图片、视频、一言) |
| 7 | +- 开箱即用,同时拥有丰富的选项 |
| 8 | +- 独立资源存储库,从 Github 自动拉取更新 |
| 9 | +- 支持自部署,轻松自定义你自己的资源(图片、视频、一言) |
10 | 10 | - 模块化架构,易于扩展 |
11 | 11 |
|
12 | | -包括原神&崩坏 3 精选图片、音乐、视频以及一言. |
| 12 | +默认的资源(`HoYoRandom`)包括原神&崩坏 3 精选图片、音乐、视频以及一言. |
13 | 13 | 喜欢的话麻烦点个`Star`吧ヾ(≧▽≦\\\*)o |
14 | 14 | 欢迎贡献! |
15 | 15 |
|
16 | | -## 链接 |
| 16 | +## Links |
17 | 17 |
|
18 | | -> 默认的资源存储在[DreamOfIce/HoYoRandomResources](https://github.com/DreamOfIce/HoYoRandomResources) |
19 | | -> 详细文档位于[DreamOfIce/HoYoRandom-docs](https://github.com/DreamOfIce/HoYoRandom-docs) |
20 | | -> 使用 PHP 编写的旧版本:[HoYoRandom-php](https://github.com/DreamOfIce/HoYoRandom-php)(不再更新) |
| 18 | +> DEMO: [点击进入](https://api.dreamofice.cn/hoyorandom) |
| 19 | +> 默认资源`HoYoRandom` [DreamOfIce/HoYoRandomResources](https://github.com/DreamOfIce/HoYoRandomResources) |
| 20 | +> 详细文档位于 [DreamOfIce/randomAPI-docs](https://github.com/DreamOfIce/randomAPI-docs) |
| 21 | +> 使用 PHP 编写的旧版本 [HoYoRandom-php](https://github.com/DreamOfIce/HoYoRandom-php)(_不再更新_) |
21 | 22 |
|
22 | 23 | ## TODO |
23 | 24 |
|
24 | 25 | - [x] 一言接口 |
25 | 26 | - [x] 媒体文件接口 |
26 | | -- [ ] 自部署文档 |
| 27 | +- [x] 自部署文档 |
27 | 28 | - [ ] 开发文档 |
28 | 29 | - [ ] 标签(tag)支持 |
29 | 30 | - [ ] 统计系统 |
30 | | -- [ ] `TypeScript`重写 |
| 31 | +- [ ] `TypeScript`重写(v2.x) |
31 | 32 |
|
32 | | -## API 端点 |
| 33 | +## 资源存储库 |
33 | 34 |
|
34 | | -我提供的公共 API,服务器位于美国,目前没有速率限制: |
| 35 | +- 默认的配置使用[HoYoRandomResources](https://github.com/DreamOfIce/HoYoRandomResources), 包含了原神&崩坏 3 的图片、音乐、视频和一言 |
| 36 | +- 通过修改`config.json`,可以使用自己的资源存储库,详见[文档-部署](https://docs.dreamofice.cn/hoyorandom/deploy/config) |
| 37 | +- 关于资源存储库的格式,请参考[文档-自定义资源](https://docs.dreamofice.cn/hoyorandom/resource) |
35 | 38 |
|
36 | | -> 本站已启用`HSTS`,并加入`Preload List`,故仅支持 https 调用 |
37 | | -> https://api.dreamofice.cn/hoyorandom/ |
38 | | -
|
39 | | ---- |
40 | | - |
41 | | -## 接口 |
42 | | - |
43 | | -支持的参数列表请见[参数](#参数)一节 |
44 | | - |
45 | | -> 以下为默认的 API 接口,你可以自行部署不同的接口 |
| 39 | +## 参数 |
46 | 40 |
|
47 | | -### 图片 |
| 41 | +目前支持三种方式传入参数: |
48 | 42 |
|
49 | | -- 路径: `/img` |
50 | | -- 类型: `media` |
51 | | -- 资源: [HoYoRandomResources/img](https://github.com/DreamOfIce/HoYoRandomResources/tree/master/img) |
| 43 | +> 优先级为从上到下递减 |
52 | 44 |
|
53 | | -返回示例: |
| 45 | +- `URL`参数,如: |
| 46 | + `https://api.dreamofice.cn/hoyorandom/img?c=ys&f=json` |
| 47 | +- `URL`路径: |
| 48 | + > 路径与参数的对应关系依次为:`/endpoint/${category}/${tag}/${format}/${encoding}/${seletor}` |
| 49 | + > 如: `https://api.dreamofice.cn/hoyorandom/img/ys/all/json` |
| 50 | +- `POST`负载(支持`application/json`和`application/x-www-form-urlencoded`): |
54 | 51 |
|
55 | | -- Raw |
56 | | -  |
57 | | -- JSON |
58 | 52 | ```json |
59 | | - { |
60 | | - "category": "ys", |
61 | | - "name": "韶光抚月,天下人间", |
62 | | - "url": "https://cf.dreamofice.cn/p/HoYoRandom/img/ys/%E9%9F%B6%E5%85%89%E6%8A%9A%E6%9C%88%EF%BC%8C%E5%A4%A9%E4%B8%8B%E4%BA%BA%E9%97%B4.webp" |
63 | | - } |
| 53 | + { "category": "ys", "format": "json" } |
64 | 54 | ``` |
65 | 55 |
|
66 | | -### 音乐 |
| 56 | +### Media 类型 |
67 | 57 |
|
68 | | -- 路径: `/music` |
69 | | -- 类型: `media` |
70 | | -- 资源: [HoYoRandomResources/music](https://github.com/DreamOfIce/HoYoRandomResources/tree/master/music) |
| 58 | +| 参数名 | 简写 | 默认值 | 合法值 | 描述 | 备注 | |
| 59 | +| :------: | :--: | :-----: | :--------------------------------------------------------------------------------: | :----------------------------: | :----------------------------------------------: | |
| 60 | +| category | c | `all` | `all`或有效的类型或其组成的数组 | 资源类型,`all`代指所有 | | |
| 61 | +| tag | t | `all` | `all`或有效的标签或其组成的数组 | 资源的标签(tag)(**开发中**) | 输入多个值时随机返回符合任意一个条件的资源 | |
| 62 | +| format | f | `raw` | `raw`,`json` | 返回的格式 | 具体示例参见[返回格式-Media](#Media) | |
| 63 | +| encoding | e | `utf-8` | 任意[支持的字符编码](https://github.com/ashtuchkin/iconv-lite#supported-encodings) | `format=json`时,返回文本的编码 | | |
71 | 64 |
|
72 | | -返回示例: |
| 65 | +### Hitokoto 类型 |
73 | 66 |
|
74 | | -- Raw |
75 | | - <audio controls src='https://api.dreamofice.cn/hoyorandom/music' >当前环境似乎不支持播放呢(っ °Д °;)っ</audio> |
76 | | -- JSON |
77 | | - ```json |
78 | | - { |
79 | | - "category": "ys", |
80 | | - "name": "HOYO-MiX - Ruu's Melody 阿瑠的歌", |
81 | | - "url": "https://cf.dreamofice.cn/p/hoyorandom/music/ys/HOYO-MiX%20-%20Ruu's%20Melody%20%E9%98%BF%E7%91%A0%E7%9A%84%E6%AD%8C.mp3" |
82 | | - } |
83 | | - ``` |
| 67 | +| 参数名 | 简写 | 默认值 | 合法值 | 描述 | 备注 | |
| 68 | +| :------: | :--: | :---------: | :----------------------------------------------------------------------------------------------------: | :--------------------: | :----------------------------------------------: | |
| 69 | +| category | c | `all` | `all`或有效的类型或其组成的数组 | 资源类型,`all`代指所有 | | |
| 70 | +| tag | t | `all` | `all`或有效的标签或其组成的数组 (**开发中**) | 一言的标签(tag) | 输入多个值时随机返回符合任意一个条件的资源 | |
| 71 | +| format | f | `json` | `js`,`json`,`text` | 返回的格式 | 具体示例参见[返回格式-Hitokoto](#Hitokoto) | |
| 72 | +| encoding | e | `utf-8` | 任意[支持的字符编码](https://github.com/ashtuchkin/iconv-lite#supported-encodings) | 返回文本的编码 | | |
| 73 | +| seletor | s | `#hitokoto` | `format=js`时,要插入一言的元素的[CSS 选择器](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) | | |
84 | 74 |
|
85 | | -### 视频 |
| 75 | +--- |
86 | 76 |
|
87 | | -- 路径: `/video` |
88 | | -- 类型: `media` |
89 | | -- 资源: [HoYoRandomResources/video](https://github.com/DreamOfIce/HoYoRandomResources/tree/master/video) |
| 77 | +## 返回格式 |
90 | 78 |
|
91 | | -返回示例: |
| 79 | +# Media |
92 | 80 |
|
93 | | -- Raw |
94 | | - <video controls src="https://api.dreamofice.cn/hoyorandom/video"></video> |
95 | | -- JSON |
| 81 | +- `raw` 直接 302 重定向到对应的资源: |
| 82 | +  |
| 83 | +- `json`返回一个 JSON: |
96 | 84 | ```json |
97 | 85 | { |
98 | 86 | "category": "ys", |
99 | | - "name": "295850674-1-208", |
100 | | - "url": "https://cf.dreamofice.cn/p/hoyorandom/video/ys/295850674-1-208.mp4" |
| 87 | + "name": "韶光抚月,天下人间", |
| 88 | + "url": "https://cf.dreamofice.cn/p/HoYoRandom/img/ys/%E9%9F%B6%E5%85%89%E6%8A%9A%E6%9C%88%EF%BC%8C%E5%A4%A9%E4%B8%8B%E4%BA%BA%E9%97%B4.webp" |
101 | 89 | } |
102 | 90 | ``` |
103 | 91 |
|
104 | | -### 一言 |
105 | | - |
106 | | -- 路径: `/hitokoto` |
107 | | -- 类型: `hitokoto` |
108 | | -- 资源: [HoYoRandomResources/hitokoto](https://github.com/DreamOfIce/HoYoRandomResources/tree/master/hitokoto) |
109 | | - |
110 | | -返回示例: |
| 92 | +# Hitokoto |
111 | 93 |
|
112 | | -- text |
| 94 | +- `text`直接返回文本 |
113 | 95 | ```text |
114 | 96 | 烟花易逝,人情长存 |
115 | 97 | ``` |
116 | | -- JSON |
| 98 | +- `json` 返回一个 JSON: |
117 | 99 | ```json |
118 | 100 | { |
119 | 101 | "hitokoto": "愿风神忽悠你", |
|
123 | 105 | - js |
124 | 106 |
|
125 | 107 | ```javascript |
126 | | -document |
127 | | - .querySeletor('#hitokoto') |
128 | | - .innerText( |
129 | | - '你不明白「牺牲是无法避免的」意味着什么,真正可怕的,并不是这个世界夺走了多少人的性命,而是它让多少人对失去生命这件事,习以为常', |
130 | | - ); |
| 108 | +document.querySeletor('#hitokoto').innerText('你不明白「牺牲是无法避免的」意味着什么,真正可怕的,并不是这个世界夺走了多少人的性命,而是它让多少人对失去生命这件事,习以为常'); |
131 | 109 | ``` |
132 | 110 |
|
133 | | -## 参数 |
134 | | - |
135 | | -目前支持三种方式传入参数: |
136 | | - |
137 | | -> 优先级为从上到下递减 |
138 | | -
|
139 | | -- `URL`参数: |
140 | | - `https://api.dreamofice.cn/hoyorandom/img?c=ys&f=json` |
141 | | -- `URL`路径: |
142 | | - > 路径与参数的对应关系依次为:`/endpoint/${category}/${tag}/${format}/${encoding}/${seletor}` > `https://api.dreamofice.cn/hoyorandom/img/ys/all/json` |
143 | | -- `POST`负载(支持`application/json`和`application/x-www-form-urlencoded`): |
144 | | - ```json |
145 | | - { "category": "ys", "format": "json" } |
146 | | - ``` |
| 111 | +## HoYoRandom |
147 | 112 |
|
148 | | -### Media |
| 113 | +### API 端点 |
149 | 114 |
|
150 | | -| 参数名 | 简写 | 默认值 | 合法值 | 描述 | 备注 | |
151 | | -| :------: | :--: | :-----: | :--------------------------------------------------------------------------------: | :----------------------------: | :----------------------------------------------: | |
152 | | -| category | c | `all` | `all` & 有效的类型值(`ys`,`bh3`)或其组成的数组 | 资源类型,`all`代指所有 | | |
153 | | -| tag | t | `all` | `all` & 有效的标签或其组成的数组 | 资源的标签(tag)(**开发中**) | 输入多个值时随机返回符合任意一个条件的资源 | |
154 | | -| format | f | `raw` | `raw`,`json` | 返回的格式 | 具体示例参见[接口-图片](#图片)一节的返回示例部分 | |
155 | | -| encoding | e | `utf-8` | 任意[支持的字符编码](https://github.com/ashtuchkin/iconv-lite#supported-encodings) | `format=json`时,返回文本的编码 | | |
| 115 | +我提供的公共 `HoYoRandom` API,目前没有速率限制: |
156 | 116 |
|
157 | | -### Hitokoto |
| 117 | +> 此域名已启用`HSTS`,并加入`HSTS Preload List`,故仅支持 https 调用 |
| 118 | +> https://api.dreamofice.cn/hoyorandom/ |
158 | 119 |
|
159 | | -| 参数名 | 简写 | 默认值 | 合法值 | 描述 | 备注 | |
160 | | -| :------: | :--: | :---------: | :----------------------------------------------------------------------------------------------------: | :--------------------: | :----------------------------------------------: | |
161 | | -| category | c | `all` | `all`或有效的类型字符串(`ys`,`bh3`)或其组成的数组 | 资源类型,`all`代指所有 | | |
162 | | -| tag | t | `all` | `all`或有效的标签或其组成的数组 (**开发中**) | 一言的标签(tag) | 输入多个值时随机返回符合任意一个条件的资源 | |
163 | | -| format | f | `json` | `js`,`json`,`text` | 返回的格式 | 具体示例参见[接口-一言](#一言)的返回示例部分部分 | |
164 | | -| encoding | e | `utf-8` | 任意[支持的字符编码](https://github.com/ashtuchkin/iconv-lite#supported-encodings) | 返回文本的编码 | | |
165 | | -| seletor | s | `#hitokoto` | `format=js`时,要插入一言的元素的[CSS 选择器](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) | | |
| 120 | +### 文档 |
| 121 | +> 敬请期待 |
166 | 122 |
|
167 | 123 | ## 常见问题(FAQ) |
168 | 124 |
|
|
0 commit comments