Comparing version 1.0.5 to 1.0.9
{ | ||
"sfw": { | ||
"kiss": "/sfw/kiss", | ||
"hug": "/sfw/hug", | ||
"kick": "/sfw/kick", | ||
"slap": "/sfw/slap", | ||
"dance": "/sfw/dance", | ||
"happy": "/sfw/happy", | ||
"confused": "/sfw/confused", | ||
"angry": "/sfw/angry", | ||
"cry": "/sfw/cry", | ||
"blush": "/sfw/blush", | ||
"sleep": "/sfw/sleep", | ||
"laugh": "/sfw/laugh", | ||
"feed": "/sfw/feed", | ||
"pat": "/sfw/pat", | ||
"bored": "/sfw/bored", | ||
"disgust": "/sfw/disgust", | ||
"greeting": "/sfw/greeting", | ||
"sad": "/sfw/sad", | ||
"think": "/sfw/think" | ||
}, | ||
"hentai": { | ||
"hentai": "/hentaj/hentai", | ||
"boobs": "/hentai/boobs", | ||
"ass": "/hentai/ass", | ||
"anal": "/hentai/anal", | ||
"blowjob": "/hentai/blowjob", | ||
"pussy": "/hentai/pussy", | ||
"cum": "/hentai/cum", | ||
"yuri": "/hentai/yuri", | ||
"double": "/hentai/double", | ||
"gif": "/hentai/gif", | ||
"futa": "/hentai/futanari", | ||
"yaoi": "/hentai/yaoi", | ||
"neko": "/hentai/neko", | ||
"femdom": "/hentai/femdom", | ||
"pokemon": "/hentai/poke", | ||
"yiff": "/real/yiff", | ||
"trap": "/real/trap" | ||
}, | ||
"real": { | ||
"bdsm": "/real/bdsm", | ||
"boobs": "/real/boobs", | ||
"bigass": "/real/bigass", | ||
"cosplay": "/real/cosplay", | ||
"ass": "/real/ass", | ||
"porngif": "/real/porngif/", | ||
"pussy": "/real/pussy", | ||
"black": "/real/black", | ||
"traps": "/real/traps", | ||
"lesbian": "/real/lesbian", | ||
"pawg": "/real/pawg" | ||
} | ||
"kiss": "kiss", | ||
"hug": "hug", | ||
"kick": "kick", | ||
"slap": "slap", | ||
"dance": "dance", | ||
"happy": "happy", | ||
"confused": "confused", | ||
"angry": "angry", | ||
"cry": "cry", | ||
"blush": "blush", | ||
"sleep": "sleep", | ||
"laugh": "laugh", | ||
"feed": "feed", | ||
"pat": "pat", | ||
"bored": "bored", | ||
"disgust": "disgust", | ||
"greeting": "greeting", | ||
"sad": "sad", | ||
"think": "think" | ||
} | ||
} |
60
index.js
@@ -8,36 +8,22 @@ /* | ||
const {get} = require('https'); | ||
const fetch = require('node-fetch'); | ||
const {URL, URLSearchParams} = require('url'); | ||
const endpoints = require('./endpoints.json'); | ||
function getContent(url) { | ||
return new Promise((resolve, reject) => { | ||
get(url, (res) => { | ||
const {statusCode} = res; | ||
if(statusCode !== 200) { | ||
res.resume(); | ||
reject(`Request failed. Status code: ${statusCode}`); | ||
} | ||
res.setEncoding('utf8'); | ||
let rawData = ''; | ||
res.on('data', (chunk) => {rawData += chunk}); | ||
res.on('end', () => { | ||
try { | ||
const parsedData = JSON.parse(rawData); | ||
resolve(parsedData); | ||
} catch(e) { | ||
reject(`Error: ${e.message}`); | ||
} | ||
}); | ||
}).on('error', (err) => { | ||
reject(`Error: ${err.message}`); | ||
}) | ||
}); | ||
async function getContent(url, token) { | ||
if(!token) throw new Error("[NO TOKEN INCLUDED] Didn't include an access token, get it on the website."); | ||
let options = { | ||
"headers": {"Authorization": token} | ||
} | ||
res = await fetch(url, options), | ||
body = await res.json(); | ||
if(res.status !== 200) throw new Error(body.message); | ||
return body; | ||
} | ||
class TnaiAPI { | ||
constructor() { | ||
constructor(token) { | ||
let self = this; | ||
self.sfw = {}; | ||
self.hentai = {}; | ||
self.real = {}; | ||
let baseURL = 'https://tnai.ml'; | ||
// self.hentai = {}; // They will be back soon! | ||
// self.real = {}; // Will be back soon! | ||
let baseURL = 'https://tnai.ml/api/image?type='; | ||
Object.keys(endpoints.sfw).forEach(async (endpoint) => { | ||
@@ -47,24 +33,8 @@ self.sfw[endpoint] = async function (queryParams = '') { | ||
queryParams !== '' ? url.search = new URLSearchParams(queryParams) : ''; | ||
let response = await getContent(url.toString()); | ||
let response = await getContent(url.toString(), token); | ||
return response.url; | ||
}; | ||
}); | ||
Object.keys(endpoints.hentai).forEach( async (endpoint) => { | ||
self.hentai[endpoint] = async function (queryParams = '') { | ||
let url = new URL(`${baseURL}${endpoints.hentai[endpoint]}`); | ||
queryParams !== '' ? url.search = new URLSearchParams(queryParams) : ''; | ||
let response = await getContent(url.toString()); | ||
return response.url; | ||
}; | ||
}); | ||
Object.keys(endpoints.real).forEach(async (endpoint) => { | ||
self.real[endpoint] = async function (queryParams = '') { | ||
let url = new URL(`${baseURL}${endpoints.real[endpoint]}`); | ||
queryParams !== '' ? url.search = new URLSearchParams(queryParams) : ''; | ||
let response = await getContent(url.toString()) | ||
return response.url; | ||
}; | ||
}); | ||
} | ||
} | ||
module.exports = TnaiAPI; |
{ | ||
"name": "tnai", | ||
"version": "1.0.5", | ||
"description": "An NSFW/Anime Wrapper API that helps how to get random images!", | ||
"version": "1.0.9", | ||
"description": "An Anime Wrapper API that helps how to get random images!", | ||
"main": "index.js", | ||
@@ -10,2 +10,5 @@ "scripts": { | ||
}, | ||
"dependencies": { | ||
"node-fetch": "2.6.1" | ||
}, | ||
"typings": "./guies/base.d.ts", | ||
@@ -12,0 +15,0 @@ "keywords": [ |
@@ -11,3 +11,3 @@ <div align="center"> | ||
</div> | ||
An NSFW/Anime Wrapper API that helps how to get random images! | ||
An Anime Wrapper API that helps how to get random images! | ||
@@ -21,2 +21,3 @@ | ||
* **[Read the documentation](https://docs.tnai.ml)** | ||
_**(The HENTAI and PORN category were temporarily disabled further updates on the support server.)**_ | ||
@@ -27,3 +28,2 @@ ## Support Server | ||
# Developers | ||
* Mairon31#8351 [API Owner] | ||
* Jean#3897 [Website Creator] | ||
* Mairon31#8351 |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3184
1
4
57
+ Addednode-fetch@2.6.1
+ Addednode-fetch@2.6.1(transitive)