4chan-list-webm
Advanced tools
Comparing version 4.1.1 to 4.1.2
'use strict' | ||
const axios = require('axios') | ||
const parseUrl = require('./parse-url') | ||
const transform = require('./transform') | ||
function listWebm (...args) { | ||
let board | ||
let threadNo | ||
let protocol | ||
if (args[1] === undefined) { | ||
;({ board, threadNo, protocol } = parseUrl(args[0])) | ||
} else { | ||
[ board, threadNo ] = args | ||
args[2] = args[2] || {} | ||
protocol = args[2].https ? 'https' : 'http' | ||
} | ||
const apiUrl = `${protocol}://a.4cdn.org/${board}/thread/${threadNo}.json` | ||
return axios.get(apiUrl).then(res => transform(res.data, protocol, board)) | ||
} | ||
module.exports = listWebm | ||
module.exports = require('./list-webm') |
'use strict' | ||
/** | ||
* Extracts the protocol, board and thread number from a 4chan URL | ||
* @func parseUrl | ||
* @param {String} url A 4chan url | ||
* @returns {Object} Object containing the protocol, board and thread number | ||
*/ | ||
function parseUrl (url) { | ||
@@ -4,0 +10,0 @@ const regex = /(https?).*\/(.+)\/thread\/(\d+)/g |
'use strict' | ||
/** | ||
* Returns a webm url | ||
* @func webmUrl | ||
* @param {String} protocol The protocol used for the URL | ||
* @param {String} board Board shortname, eg. 'b' | ||
* @param {Number} timestamp Unix timestamp of the webm | ||
*/ | ||
function webmUrl (protocol, board, timestamp) { | ||
@@ -7,2 +14,9 @@ return `${protocol}://i.4cdn.org/${board}/${timestamp}.webm` | ||
/** | ||
* Returns a thumbnail url | ||
* @func thumbUrl | ||
* @param {String} protocol The protocol used for the URL | ||
* @param {String} board Board shortname, eg. 'b' | ||
* @param {Number} timestamp Unix timestamp of the thumbnail | ||
*/ | ||
function thumbUrl (protocol, board, timestamp) { | ||
@@ -12,2 +26,8 @@ return `${protocol}://i.4cdn.org/${board}/${timestamp}s.jpg` | ||
/** | ||
* Returns whether the file is a webm | ||
* @func isWebm | ||
* @param {String} file The filename of the file | ||
* @returns {Boolean} True if *.webm | ||
*/ | ||
function isWebm (file) { | ||
@@ -17,2 +37,10 @@ return file.ext === '.webm' | ||
/** | ||
* Transforms a 4chan thread payload into a JSON with webm data | ||
* @func transform | ||
* @param {Object} raw Raw thread JSON payload | ||
* @param {String} protocol Protocol to use for generating links | ||
* @param {String} board Board shortname, eg. 'b' | ||
* @returns {Object} JSON containing thread subject and webm data | ||
*/ | ||
function transform (raw, protocol, board) { | ||
@@ -19,0 +47,0 @@ const reducer = (acc, file) => acc.concat([{ |
{ | ||
"name": "4chan-list-webm", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"description": "Generate a list of webms posted in a 4chan thread", | ||
"main": "./index.js", | ||
"author": "Philip Scott <pscott@zeptohost.com>", | ||
"author": "scootykins <scootykins@yahoo.com>", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"type": "git", | ||
"url": "https://github.com/ScottyFillups/4chan-list-webm.git" | ||
"url": "https://github.com/scootykins/4chan-list-webm.git" | ||
}, | ||
@@ -31,0 +31,0 @@ "dependencies": { |
# 4chan-list-webm | ||
[![npm version](https://badge.fury.io/js/4chan-list-webm.svg)](https://badge.fury.io/js/4chan-list-webm) | ||
[![Build Status](https://travis-ci.org/ScottyFillups/4chan-list-webm.svg?branch=master)](https://travis-ci.org/ScottyFillups/4chan-list-webm) | ||
[![Coverage Status](https://coveralls.io/repos/github/ScottyFillups/4chan-list-webm/badge.svg?branch=master)](https://coveralls.io/github/ScottyFillups/4chan-list-webm?branch=master) | ||
[![Build Status](https://travis-ci.org/scootykins/4webm.svg?branch=master)](https://travis-ci.org/scootykins/4webm) | ||
[![Coverage Status](https://coveralls.io/repos/github/scootykins/4chan-list-webm/badge.svg?branch=master)](https://coveralls.io/github/scootykins/4chan-list-webm?branch=master) | ||
[![install size](https://packagephobia.now.sh/badge?p=4chan-list-webm)](https://packagephobia.now.sh/result?p=4chan-list-webm) | ||
@@ -7,0 +7,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
190549
27
607
1