4chan-list-webm 中文文档教程
4chan-list-webm
生成在线程中发布的 webms 列表。
这是 演示 4chan-list-webm
的实际操作(请加星)。
Installation
$ yarn add 4chan-list-webm
# OR
$ npm install --save 4chan-list-webm
Usage
const listWebms = require('4chan-list-webm')
// promise
listWebms('wsg', 2045456)
.then(data => console.log(data.webms))
.catch(err => console.error('404!', err))
// async/await
async function run () {
try {
const data = await listWebms('http://boards.4chan.org/wsg/thread/2045456')
console.log(data)
} catch (err) {
console.error('Whoa! 404! :c', err)
}
}
run()
API
listWebm(url)
listWebm(board, threadNo, config)
返回一个承诺,该承诺解析为线程内有关 webms 的数据(请参阅有效负载)。
url
类型:String
线程的 URL。 如果发出 https
请求,缩略图和 webm 链接将使用 https
。
board
类型:String
开发板的简称,例如。 'wsg'
, 'b'
等
threadNo
类型:Number
目标线程的线程号。 例如,2312676
是http://boards.4chan.org/wsg/thread/2312676的线程号
config
类型:Object
一个配置对象,详见下文。
config.https
类型:Boolean
确定是否使用 https
的属性。 将密钥设置为 true
可启用 https
。
Payload
下面是一个示例有效载荷。 请注意,如果线程没有主题,主题键将被省略。
{
"subject": "Hawkeye being epic in other roles",
"webms": [
{
"filename": "1534288775634",
"url": "http://i.4cdn.org/wsg/1534332395477.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534332395477s.jpg"
},
{
"filename": "1534288802449",
"url": "http://i.4cdn.org/wsg/1534332452014.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534332452014s.jpg"
},
{
"filename": "1534288878879",
"url": "http://i.4cdn.org/wsg/1534332526405.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534332526405s.jpg"
},
{
"filename": "Dahmer (2002)",
"url": "http://i.4cdn.org/wsg/1534799616292.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534799616292s.jpg"
},
{
"filename": "Bourne_legacy",
"url": "http://i.4cdn.org/wsg/1535117894788.webm",
"thumbnail": "http://i.4cdn.org/wsg/1535117894788s.jpg"
}
]
}
Miscellaneous
CORS, and why this doesn't work in the browser
因为 CORS 仅支持 来源为 http(s)://boards.4chan .org
, 此模块在浏览器中不工作; 它仅适用于 Node.js。 唯一的例外情况是,如果您正在创建 Chrome 插件,并将 http(s)://boards.4chan.org
设置为来源。
Rate limits
如 4chan API 中所述,您必须确保每秒发出的请求不超过一个。 您有责任确保遵守请求限制。 我建议使用 limiter 或 bottleneck .
Thumbnails
如果您尝试通过内联链接加载缩略图(例如,更改 src
属性,您将收到 403 禁止错误
code> 通过 JavaScript,或对其进行硬编码)。 您仍然可以通过代理服务器下载这些图像并在那里提供它们。
Why?
¯\_(ツ)_/¯
Disclaimer
4chan-list-webm
的创建者与 4chan.org 没有任何关联。
4chan-list-webm
Generate a list of webms posted in a thread.
Here's a little demonstration of 4chan-list-webm
in action (plz star).
Installation
$ yarn add 4chan-list-webm
# OR
$ npm install --save 4chan-list-webm
Usage
const listWebms = require('4chan-list-webm')
// promise
listWebms('wsg', 2045456)
.then(data => console.log(data.webms))
.catch(err => console.error('404!', err))
// async/await
async function run () {
try {
const data = await listWebms('http://boards.4chan.org/wsg/thread/2045456')
console.log(data)
} catch (err) {
console.error('Whoa! 404! :c', err)
}
}
run()
API
listWebm(url)
listWebm(board, threadNo, config)
Returns a promise that resolves to data about webms within a thread (see payload).
url
Type: String
The URL of the thread. The thumbnail and webm links will use https
if an https
request is made.
board
Type: String
The short-name of the board, eg. 'wsg'
, 'b'
, etc.
threadNo
Type: Number
The thread number of the target thread. For example, 2312676
is the thread number of http://boards.4chan.org/wsg/thread/2312676
config
Type: Object
A configuration object, see details below.
config.https
Type: Boolean
Property that determines whether to use https
. Setting the key to true
enables https
.
Payload
Below an example payload. Note that the subject key will be omitted if the thread has no subject.
{
"subject": "Hawkeye being epic in other roles",
"webms": [
{
"filename": "1534288775634",
"url": "http://i.4cdn.org/wsg/1534332395477.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534332395477s.jpg"
},
{
"filename": "1534288802449",
"url": "http://i.4cdn.org/wsg/1534332452014.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534332452014s.jpg"
},
{
"filename": "1534288878879",
"url": "http://i.4cdn.org/wsg/1534332526405.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534332526405s.jpg"
},
{
"filename": "Dahmer (2002)",
"url": "http://i.4cdn.org/wsg/1534799616292.webm",
"thumbnail": "http://i.4cdn.org/wsg/1534799616292s.jpg"
},
{
"filename": "Bourne_legacy",
"url": "http://i.4cdn.org/wsg/1535117894788.webm",
"thumbnail": "http://i.4cdn.org/wsg/1535117894788s.jpg"
}
]
}
Miscellaneous
CORS, and why this doesn't work in the browser
Because CORS is only supported with an origin of http(s)://boards.4chan.org
, this module does not work in the browser; it only works with Node.js. The ONLY exception to this is if you're creating a Chrome plugin, with http(s)://boards.4chan.org
set as the origin.
Rate limits
As stated in the 4chan API, you must ensure that you do not make more than one request per second. It is your responsiblity to ensure that the request limit is respected. I recommend using limiter or bottleneck.
Thumbnails
You will get an 403 Forbidden error
if you try to load the thumbnails via inline linking (eg. changing the src
attribute of an <img>
via JavaScript, or hard-coding it). You can still download these images via a proxy server and serve them there.
Why?
¯\_(ツ)_/¯
Disclaimer
The creator of 4chan-list-webm
is not associated with 4chan.org in any way.