commit
This commit is contained in:
parent
70e2f7a8aa
commit
008d2f30d7
675 changed files with 189892 additions and 0 deletions
137
node_modules/r34api.js/README.md
generated
vendored
Normal file
137
node_modules/r34api.js/README.md
generated
vendored
Normal file
|
@ -0,0 +1,137 @@
|
|||
# R34Api.js
|
||||
- By [BulzyKrown](https://bulzyland.xyz)
|
||||
- With the help of [Esponjosin](https://esponjosin.xyz) and Rickz
|
||||
|
||||
## Instalation
|
||||
```js
|
||||
// With NPM
|
||||
$ npm install r34api.js --save
|
||||
|
||||
// With Yarn
|
||||
$ yarn add r34api.js
|
||||
```
|
||||
|
||||
### Using in your project:
|
||||
```js
|
||||
const r34api = new (require('r34api.js'));
|
||||
|
||||
console.log(r34api.methods);
|
||||
|
||||
// Output:
|
||||
[ 'random', 'search', 'tags', 'help' ]
|
||||
```
|
||||
|
||||
### Methods:
|
||||
|
||||
#### help:
|
||||
- Show information about an method.
|
||||
```js
|
||||
|
||||
/**
|
||||
* @param {String} [method] Name of the method you want to obtain information
|
||||
*/
|
||||
|
||||
const data = await R34.help('method');
|
||||
|
||||
// Output example:
|
||||
{
|
||||
base: '/random',
|
||||
alias: '/r',
|
||||
method: 'GET',
|
||||
description: 'Get random data from Rule34',
|
||||
query: {
|
||||
type: {
|
||||
description: 'It delivers images just like that in a random way',
|
||||
variable: [Array],
|
||||
example: 'type=png'
|
||||
},
|
||||
limit: {
|
||||
description: 'Obtain a limit of data from the database',
|
||||
example: 'limit=3'
|
||||
}
|
||||
},
|
||||
routes: {
|
||||
all: {
|
||||
base: '/all',
|
||||
method: 'GET',
|
||||
description: 'Obtains all the data stored on the DB',
|
||||
query: [Object]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### tags:
|
||||
- Provides a list of the most popular tags from highest to lowest.
|
||||
```js
|
||||
|
||||
/**
|
||||
* @param {Number} [limit] The limit of data you want to obtain (By default 1)
|
||||
*/
|
||||
|
||||
const data = await R34.tags(2);
|
||||
|
||||
// Output example:
|
||||
{
|
||||
status: 200,
|
||||
msg: 'success',
|
||||
data: [ { post: 11111, name: 'xxxx', type: 'general' } ]
|
||||
}
|
||||
```
|
||||
|
||||
#### random:
|
||||
- Get random data from Rule34.
|
||||
```js
|
||||
|
||||
/**
|
||||
* @param {Number} [limit] The limit of data you want to obtain (By default 1)
|
||||
* @param {String} [type] Format of the image you want to obtain (Optional)
|
||||
*/
|
||||
|
||||
const data = await R34.random(1, 'gif');
|
||||
|
||||
// Output example:
|
||||
{
|
||||
status: 200,
|
||||
msg: 'success',
|
||||
data: [
|
||||
Image {
|
||||
id: 1,
|
||||
type: 'x',
|
||||
rating: 'x',
|
||||
dimension: '1 x 1',
|
||||
post: 'x',
|
||||
media: 'x',
|
||||
tags: [Array]
|
||||
}
|
||||
]
|
||||
}
|
||||
//Note: Inside the data property there are objects that are an Image class that have a function called getBuffer that returns the image buffer.
|
||||
```
|
||||
|
||||
|
||||
#### search:
|
||||
- Get data of the search randomnly.
|
||||
```js
|
||||
|
||||
/**
|
||||
* @param {String} [tag] Tag from where you want to get an image
|
||||
*/
|
||||
const data = await R34.search('Anime');
|
||||
|
||||
// Output example:
|
||||
{
|
||||
status: 200,
|
||||
msg: 'Success',
|
||||
data: Image {
|
||||
id: 1,
|
||||
type: 'PNG',
|
||||
rating: 'Explicit',
|
||||
dimension: '1 x 1',
|
||||
post: 'x',
|
||||
media: 'x',
|
||||
tags: []
|
||||
}
|
||||
}
|
||||
//Note: Inside the data property there are objects that are an Image class that have a function called getBuffer that returns the image buffer.
|
||||
```
|
50
node_modules/r34api.js/package.json
generated
vendored
Normal file
50
node_modules/r34api.js/package.json
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"_from": "r34api.js@1.1.1",
|
||||
"_id": "r34api.js@1.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-SC4Or9gbDypQ7q0+6G7PJwNHx3isfdm1AQweJUAvqVn0qdHnSufR3haS/Pk+6hC/X7Q3t6YLZVQX3PqiQ4AGdw==",
|
||||
"_location": "/r34api.js",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "r34api.js@1.1.1",
|
||||
"name": "r34api.js",
|
||||
"escapedName": "r34api.js",
|
||||
"rawSpec": "1.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/r34api.js/-/r34api.js-1.1.1.tgz",
|
||||
"_shasum": "cd1d66d3717c94edad22c80f76a0d4844586f44e",
|
||||
"_spec": "r34api.js@1.1.1",
|
||||
"_where": "C:\\Users\\mibkn\\Desktop\\a",
|
||||
"author": {
|
||||
"name": "esponjosin"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"ky": "^0.25.1",
|
||||
"ky-universal": "^0.8.2"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "R34Api.js is an API to interact with the Rule34 page.",
|
||||
"keywords": [
|
||||
"rule34",
|
||||
"rule",
|
||||
"34",
|
||||
"nsfw",
|
||||
"api"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "r34api.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"version": "1.1.6"
|
||||
}
|
7
node_modules/r34api.js/src/Lib/Error.js
generated
vendored
Normal file
7
node_modules/r34api.js/src/Lib/Error.js
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
module.exports = class R34Error extends TypeError {
|
||||
constructor(message) {
|
||||
super()
|
||||
this.message = message;
|
||||
this.name = `R34Error`
|
||||
}
|
||||
}
|
37
node_modules/r34api.js/src/Lib/Image.js
generated
vendored
Normal file
37
node_modules/r34api.js/src/Lib/Image.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
const ky = require('ky-universal');
|
||||
|
||||
module.exports = class Image {
|
||||
|
||||
constructor(info) {
|
||||
Object.assign(this, info)
|
||||
}
|
||||
|
||||
/**
|
||||
* getBuffer function
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
|
||||
getBuffer() {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
let self = this;
|
||||
|
||||
setImmediate(async () => {
|
||||
|
||||
try {
|
||||
|
||||
let res = await ky.get(self.media);
|
||||
|
||||
resolve(await res.buffer());
|
||||
|
||||
} catch(e) {
|
||||
return reject(new Error(e.toString()))
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
186
node_modules/r34api.js/src/Lib/R34.js
generated
vendored
Normal file
186
node_modules/r34api.js/src/Lib/R34.js
generated
vendored
Normal file
|
@ -0,0 +1,186 @@
|
|||
const path = require('path'),
|
||||
package = require(path.resolve(__dirname, '../../package.json')),
|
||||
Error = require(path.resolve(__dirname, './Error.js')),
|
||||
Image = require(path.resolve(__dirname, './Image.js')),
|
||||
api = require('ky-universal').create({
|
||||
prefixUrl: `https://r34.bulzyland.xyz/`,
|
||||
headers: {
|
||||
'User-Agent': `R34.js Client v${package.version}`
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Client for rule 34 api
|
||||
*/
|
||||
|
||||
class R34 {
|
||||
|
||||
/**
|
||||
* @property {Array} Api methods
|
||||
*/
|
||||
|
||||
constructor() {
|
||||
|
||||
this.methods = [ 'random', 'search', 'tags', 'help' ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Help function
|
||||
* @param {String} method Name of the method you want to obtain information
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
|
||||
help(method) {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
if(!method) return reject(new Error('You must enter the method you want to obtain information from'));
|
||||
if(!this.methods.includes(method.toLowerCase())) return reject(new Error('The method does not exist'));
|
||||
|
||||
setImmediate(async () => {
|
||||
|
||||
try {
|
||||
|
||||
let res = await api.get('help').catch(e => e);
|
||||
|
||||
let status = (res.response || res).status;
|
||||
if(status >= 400) return resolve(JSON.parse(await res.response.text()));
|
||||
|
||||
let json = await res.json();
|
||||
|
||||
if(!json.routes.hasOwnProperty(method.toLowerCase())) return reject(new Error('The method does not exist'));
|
||||
|
||||
resolve(json.routes[method.toLowerCase()]);
|
||||
|
||||
} catch(e) {
|
||||
return reject(new Error(e.toString()))
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags function
|
||||
* @param {Number} limit The limit of data you want to obtain (By default 1)
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
|
||||
tags(limit=1) {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
if(typeof limit !== 'number') return reject(new Error('The limit must be a number'));
|
||||
limit = Math.round(limit);
|
||||
|
||||
setImmediate(async () => {
|
||||
|
||||
try {
|
||||
|
||||
let res = await api.get('tags', {
|
||||
searchParams: {
|
||||
"limit": limit
|
||||
}
|
||||
}).catch(e => e);
|
||||
|
||||
let status = (res.response || res).status;
|
||||
|
||||
resolve(status >= 400 ? JSON.parse(await res.response.text()) : await res.json());
|
||||
|
||||
} catch(e) {
|
||||
return reject(new Error(e.toString()))
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Random function
|
||||
* @param {Number} limit The limit of data you want to obtain (By default 1)
|
||||
* @param {String} type Format of the image you want to obtain (Optional)
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
|
||||
random(limit=1, type = false) {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
if(typeof limit !== 'number') return reject(new Error('The limit must be a number'));
|
||||
limit = Math.round(limit);
|
||||
|
||||
setImmediate(async () => {
|
||||
|
||||
try {
|
||||
|
||||
let params = {
|
||||
"limit": limit
|
||||
}
|
||||
|
||||
if(type) params['type'] = type;
|
||||
|
||||
let res = await api.get('random', {
|
||||
searchParams: params
|
||||
}).catch(e => e);
|
||||
|
||||
let status = (res.response || res).status;
|
||||
let json = status >= 400 ? JSON.parse(await res.response.text()) : await res.json();
|
||||
|
||||
if(status == 200) {
|
||||
json.data = json.data.map(x => new Image(x))
|
||||
}
|
||||
|
||||
resolve(json);
|
||||
|
||||
} catch(e) {
|
||||
return reject(new Error(e.toString()))
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Search function
|
||||
* @param {String} tag Tag from where you want to get an image
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
|
||||
search(tag) {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
if(!tag) return reject(new Error('You need to enter a tag'));
|
||||
if(typeof tag !== 'string') return reject(new Error('The tag has to be a string'));
|
||||
|
||||
setImmediate(async () => {
|
||||
|
||||
try {
|
||||
|
||||
let res = await api.get(`search/tag/${encodeURIComponent(tag)}`).catch(e => e);
|
||||
|
||||
let status = (res.response || res).status;
|
||||
let json = status >= 400 ? JSON.parse(await res.response.text()) : await res.json();
|
||||
|
||||
if(status == 200) {
|
||||
json.data = new Image(json.data)
|
||||
}
|
||||
|
||||
resolve(json)
|
||||
|
||||
} catch(e) {
|
||||
return reject(new Error(e.toString()))
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = R34;
|
1
node_modules/r34api.js/src/index.js
generated
vendored
Normal file
1
node_modules/r34api.js/src/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = require('./Lib/R34.js');
|
Loading…
Add table
Add a link
Reference in a new issue