From a0acf0e22b20777bfaa6fefc38e1862599ba9e97 Mon Sep 17 00:00:00 2001 From: BIOLOGY SCIENCE Date: Sun, 19 Feb 2023 21:56:14 +0530 Subject: [PATCH] v3 --- .gitignore | 1 - README.md | 28 +- main/index.js | 57 +-- main/methods/getList.js | 46 ++ main/methods/getList/ofCategory.js | 20 - main/methods/getList/ofCollection.js | 20 - main/methods/getList/ofGroup.js | 21 - main/methods/getList/ofSubCategory.js | 21 - main/methods/getRandomWallpaper.js | 58 --- main/methods/getSpecificWallpapers.js | 98 ++++ main/methods/getWallpaperCount/inCategory.js | 25 - .../methods/getWallpaperCount/inCollection.js | 25 - main/methods/getWallpaperCount/inEntireDB.js | 24 - main/methods/getWallpaperCount/inFeatured.js | 24 - main/methods/getWallpaperCount/inGroup.js | 25 - main/methods/getWallpaperCount/inPopular.js | 24 - .../getWallpaperCount/inSubCategory.js | 25 - main/methods/getWallpaperCount/inTag.js | 25 - main/methods/getWallpaperCount/inUser.js | 25 - main/methods/getWallpaperInfo.js | 39 -- main/methods/getWallpapers/bySort.js | 69 --- main/methods/getWallpapers/fromCategory.js | 63 --- main/methods/getWallpapers/fromCollection.js | 63 --- main/methods/getWallpapers/fromFeatured.js | 62 --- main/methods/getWallpapers/fromGroup.js | 63 --- main/methods/getWallpapers/fromPopular.js | 61 --- main/methods/getWallpapers/fromSubCategory.js | 63 --- main/methods/getWallpapers/fromTag.js | 63 --- main/methods/getWallpapers/fromUser.js | 63 --- main/methods/others.js | 97 ++++ main/methods/queryCount.js | 27 -- main/methods/search.js | 62 --- main/misc/errorHandler.js | 10 - main/misc/misc.json | 16 - main/types.d.ts | 427 +++++++++--------- main/utils.js | 135 ++++++ package.json | 2 +- 37 files changed, 615 insertions(+), 1362 deletions(-) delete mode 100644 .gitignore create mode 100644 main/methods/getList.js delete mode 100644 main/methods/getList/ofCategory.js delete mode 100644 main/methods/getList/ofCollection.js delete mode 100644 main/methods/getList/ofGroup.js delete mode 100644 main/methods/getList/ofSubCategory.js delete mode 100644 main/methods/getRandomWallpaper.js create mode 100644 main/methods/getSpecificWallpapers.js delete mode 100644 main/methods/getWallpaperCount/inCategory.js delete mode 100644 main/methods/getWallpaperCount/inCollection.js delete mode 100644 main/methods/getWallpaperCount/inEntireDB.js delete mode 100644 main/methods/getWallpaperCount/inFeatured.js delete mode 100644 main/methods/getWallpaperCount/inGroup.js delete mode 100644 main/methods/getWallpaperCount/inPopular.js delete mode 100644 main/methods/getWallpaperCount/inSubCategory.js delete mode 100644 main/methods/getWallpaperCount/inTag.js delete mode 100644 main/methods/getWallpaperCount/inUser.js delete mode 100644 main/methods/getWallpaperInfo.js delete mode 100644 main/methods/getWallpapers/bySort.js delete mode 100644 main/methods/getWallpapers/fromCategory.js delete mode 100644 main/methods/getWallpapers/fromCollection.js delete mode 100644 main/methods/getWallpapers/fromFeatured.js delete mode 100644 main/methods/getWallpapers/fromGroup.js delete mode 100644 main/methods/getWallpapers/fromPopular.js delete mode 100644 main/methods/getWallpapers/fromSubCategory.js delete mode 100644 main/methods/getWallpapers/fromTag.js delete mode 100644 main/methods/getWallpapers/fromUser.js create mode 100644 main/methods/others.js delete mode 100644 main/methods/queryCount.js delete mode 100644 main/methods/search.js delete mode 100644 main/misc/errorHandler.js delete mode 100644 main/misc/misc.json create mode 100644 main/utils.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b512c09..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/README.md b/README.md index a4387d3..300af25 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Cover

# About -A complete package used to interact with the [Wallpaper Abyss / The Alpha Coders API](https://api.alphacoders.com/api/instructions) to get wallpapers, wallpaper count, collections, and much more ! +A complete package used to interact with the [Wallpaper Abyss / The Alpha Coders API](https://api.alphacoders.com/api/instructions) to get wallpapers, wallpaper count, and much more ! You will need an API key which can obtained from [The Alpha Coders API](https://api.alphacoders.com/api/instructions) to use this package. @@ -10,11 +10,6 @@ You will need an API key which can obtained from [The Alpha Coders API](https:// npm i alpha-coders ``` - - # Features - Made with JavaScript. - Easy to use. @@ -33,32 +28,17 @@ The default installation of the package uses the v3 of the Alpha Coders API. --> **M** - Method - [Alpha](https://biologyscience.gitbook.io/alpha-coders/reference/classes/alpha) **C** - - [getWallpapers](https://biologyscience.gitbook.io/alpha-coders/reference/properties/getwallpapers) **P** + - [getSpecificWallpapers](https://biologyscience.gitbook.io/alpha-coders/reference/properties/getspecificwallpapers) **P** - [bySort](https://biologyscience.gitbook.io/alpha-coders/reference/methods/bysort) **M** - [fromCategory](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromcategory) **M** - - [fromCollection](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromcollection) **M** - - [fromGroup](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromgroup) **M** - [fromSubCategory](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromsubcategory) **M** - - [fromFeatured](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromfeatured) **M** - - [fromPopular](https://biologyscience.gitbook.io/alpha-coders/reference/methods/frompopular) **M** - [fromTag](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromtag) **M** - - [fromUser](https://biologyscience.gitbook.io/alpha-coders/reference/methods/fromuser) **M** - - [getWallpaperCount](https://biologyscience.gitbook.io/alpha-coders/reference/properties/getwallpapercount) **P** - - [inEntireDB](https://biologyscience.gitbook.io/alpha-coders/reference/methods/inentiredb) **M** - - [inCategory](https://biologyscience.gitbook.io/alpha-coders/reference/methods/incategory) **M** - - [inCollection](https://biologyscience.gitbook.io/alpha-coders/reference/methods/incollection) **M** - - [inGroup](https://biologyscience.gitbook.io/alpha-coders/reference/methods/ingroup) **M** - - [inSubCategory](https://biologyscience.gitbook.io/alpha-coders/reference/methods/insubcategory) **M** - - [inTag](https://biologyscience.gitbook.io/alpha-coders/reference/methods/intag) **M** - - [inUser](https://biologyscience.gitbook.io/alpha-coders/reference/methods/inuser) **M** - [getList](https://biologyscience.gitbook.io/alpha-coders/reference/properties/getlist) **P** - [ofCategory](https://biologyscience.gitbook.io/alpha-coders/reference/methods/ofcategory) **M** - - [ofCollection](https://biologyscience.gitbook.io/alpha-coders/reference/methods/ofcollection) **M** - - [ofGroup](https://biologyscience.gitbook.io/alpha-coders/reference/methods/ofgroup) **M** - [ofSubCategory](https://biologyscience.gitbook.io/alpha-coders/reference/methods/ofsubcategory) **M** - [search](https://biologyscience.gitbook.io/alpha-coders/reference/methods/search) **M** - - [getWallpaperInfo](https://biologyscience.gitbook.io/alpha-coders/reference/methods/getwallpaperinfo) **M** - - [getRandomWallpaper](https://biologyscience.gitbook.io/alpha-coders/reference/methods/getrandomwallpaper) **M** + - [getWallpaper](https://biologyscience.gitbook.io/alpha-coders/reference/methods/getwallpaper) **M** + - [getRandomWallpapers](https://biologyscience.gitbook.io/alpha-coders/reference/methods/getrandomwallpapers) **M** - [queryCount](https://biologyscience.gitbook.io/alpha-coders/reference/methods/querycount) **M**
diff --git a/main/index.js b/main/index.js index 54a9d6b..83221fb 100644 --- a/main/index.js +++ b/main/index.js @@ -1,54 +1,25 @@ +const Others = require('./methods/others'); + class Alpha { - baseURL = new URL('https://wall.alphacoders.com/api2.0/get.php'); + baseURL = new URL('https://api.alphacoders.com/3.0'); constructor(apiToken) { - this.apiToken = apiToken; - this.baseURL.searchParams.set('auth', this.apiToken); - } + if (apiToken === undefined) throw new Error('API Key is not provided !'); - getWallpapers = - { - baseURL: this.baseURL, - bySort: require('./methods/getWallpapers/bySort'), - fromCategory: require('./methods/getWallpapers/fromCategory'), - fromCollection: require('./methods/getWallpapers/fromCollection'), - fromGroup: require('./methods/getWallpapers/fromGroup'), - fromSubCategory: require('./methods/getWallpapers/fromSubCategory'), - fromFeatured: require('./methods/getWallpapers/fromFeatured'), - fromPopular: require('./methods/getWallpapers/fromPopular'), - fromTag: require('./methods/getWallpapers/fromTag'), - fromUser: require('./methods/getWallpapers/fromUser') - } + this.baseURL.searchParams.set('auth', apiToken); - getWallpaperCount = - { - baseURL: this.baseURL, - inEntireDB: require('./methods/getWallpaperCount/inEntireDB'), - inCategory: require('./methods/getWallpaperCount/inCategory'), - inCollection: require('./methods/getWallpaperCount/inCollection'), - inGroup: require('./methods/getWallpaperCount/inGroup'), - inSubCategory: require('./methods/getWallpaperCount/inSubCategory'), - inFeatured: require('./methods/getWallpaperCount/inFeatured'), - inPopular: require('./methods/getWallpaperCount/inPopular'), - inTag: require('./methods/getWallpaperCount/inTag'), - inUser: require('./methods/getWallpaperCount/inUser') - } + require('./utils').setBaseURL(this.baseURL); + }; - getList = - { - baseURL: this.baseURL, - ofCategory: require('./methods/getList/ofCategory'), - ofCollection: require('./methods/getList/ofCollection'), - ofGroup: require('./methods/getList/ofGroup'), - ofSubCategory: require('./methods/getList/ofSubCategory') - } + getSpecificWallpapers = require('./methods/getSpecificWallpapers'); + getList = require('./methods/getList'); - search = require('./methods/search'); - getWallpaperInfo = require('./methods/getWallpaperInfo'); - getRandomWallpaper = require('./methods/getRandomWallpaper'); - queryCount = require('./methods/queryCount'); -} + search = Others.search; + getWallpaper = Others.getWallpaper; + getRandomWallpapers = Others.getRandomWallpaper; + queryCount = Others.queryCount; +}; module.exports = Alpha; \ No newline at end of file diff --git a/main/methods/getList.js b/main/methods/getList.js new file mode 100644 index 0000000..e34aeb6 --- /dev/null +++ b/main/methods/getList.js @@ -0,0 +1,46 @@ +const process = require('../utils'); + +function ofCategory() +{ + const url = process.getBaseURL(); + + url.searchParams.set('method', 'category_list'); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.categories, 'LIST'); + + resolve(send); + }); + }); +}; + +function ofSubCategory(id, page) +{ + const url = process.getBaseURL(); + + if (id === undefined) throw new Error('Category ID not provided !'); + + url.searchParams.set('method', 'sub_category_list'); + url.searchParams.set('id', id); + + page !== undefined ? url.searchParams.set('page', page) : null; + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.sub_categories, 'LIST'); + + resolve(send); + }); + }); +}; + +module.exports = { ofCategory, ofSubCategory }; \ No newline at end of file diff --git a/main/methods/getList/ofCategory.js b/main/methods/getList/ofCategory.js deleted file mode 100644 index 6f6f164..0000000 --- a/main/methods/getList/ofCategory.js +++ /dev/null @@ -1,20 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function ofCategory() -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'category_list'); - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.categories); - }); - }); -}; - -module.exports = ofCategory; \ No newline at end of file diff --git a/main/methods/getList/ofCollection.js b/main/methods/getList/ofCollection.js deleted file mode 100644 index 756fbdf..0000000 --- a/main/methods/getList/ofCollection.js +++ /dev/null @@ -1,20 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function ofCollection() -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'collection_list'); - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.collections); - }); - }); -}; - -module.exports = ofCollection; \ No newline at end of file diff --git a/main/methods/getList/ofGroup.js b/main/methods/getList/ofGroup.js deleted file mode 100644 index 887c6fd..0000000 --- a/main/methods/getList/ofGroup.js +++ /dev/null @@ -1,21 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function ofGroup(id) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'group_list'); - this.baseURL.searchParams.set('id', id) - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.groups); - }); - }); -}; - -module.exports = ofGroup; \ No newline at end of file diff --git a/main/methods/getList/ofSubCategory.js b/main/methods/getList/ofSubCategory.js deleted file mode 100644 index 10f6a74..0000000 --- a/main/methods/getList/ofSubCategory.js +++ /dev/null @@ -1,21 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function ofSubCategory(id) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'sub_category_list'); - this.baseURL.searchParams.set('id', id); - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response['sub-categories']); - }); - }); -}; - -module.exports = ofSubCategory; \ No newline at end of file diff --git a/main/methods/getRandomWallpaper.js b/main/methods/getRandomWallpaper.js deleted file mode 100644 index 0203d4f..0000000 --- a/main/methods/getRandomWallpaper.js +++ /dev/null @@ -1,58 +0,0 @@ -const misc = require('../misc/misc.json'); - -function getRandomWallpaper(options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'random'); - this.baseURL.searchParams.set('info_level', 3); - - if (options?.count !== undefined) { this.baseURL.searchParams.set('count', options.count); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = getRandomWallpaper; \ No newline at end of file diff --git a/main/methods/getSpecificWallpapers.js b/main/methods/getSpecificWallpapers.js new file mode 100644 index 0000000..a51aee2 --- /dev/null +++ b/main/methods/getSpecificWallpapers.js @@ -0,0 +1,98 @@ +const process = require('../utils'); + +function bySort(sorting, options) +{ + if (sorting === undefined) throw new Error('Sort type is not provided !'); + + const url = process.getBaseURL(); + + url.searchParams.set('method', sorting === 'rating' ? 'highest_rated' : sorting); + + process.params(options).forEach(x => url.searchParams.set(x[0], x[1])); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.wallpapers, 'WALLPAPER'); + + resolve(send); + }); + }); +}; + +function fromCategory(id, options) +{ + const url = process.getBaseURL(); + + if (id === undefined) throw new Error('Category ID not provided !'); + + url.searchParams.set('method', 'category'); + url.searchParams.set('id', id); + + process.params(options).forEach(x => url.searchParams.set(x[0], x[1])); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.wallpapers, 'WALLPAPER'); + + resolve(send); + }); + }); +}; + +function fromSubCategory(id, options) +{ + const url = process.getBaseURL(); + + if (id === undefined) throw new Error('Sub-Category ID not provided !'); + + url.searchParams.set('method', 'sub_category'); + url.searchParams.set('id', id); + + process.params(options).forEach(x => url.searchParams.set(x[0], x[1])); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.wallpapers, 'WALLPAPER'); + + resolve(send); + }); + }); +}; + +function fromTag(id, options) +{ + const url = process.getBaseURL(); + + if (id === undefined) throw new Error('Tag ID not provided !'); + + url.searchParams.set('method', 'tag'); + url.searchParams.set('id', id); + + process.params(options).forEach(x => url.searchParams.set(x[0], x[1])); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.wallpapers, 'WALLPAPER'); + + resolve(send); + }); + }); +}; + +module.exports = { bySort, fromCategory, fromSubCategory, fromTag }; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inCategory.js b/main/methods/getWallpaperCount/inCategory.js deleted file mode 100644 index 0524c56..0000000 --- a/main/methods/getWallpaperCount/inCategory.js +++ /dev/null @@ -1,25 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inCategory(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'category_count'); - this.baseURL.searchParams.set('id', id); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inCategory; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inCollection.js b/main/methods/getWallpaperCount/inCollection.js deleted file mode 100644 index d9261ae..0000000 --- a/main/methods/getWallpaperCount/inCollection.js +++ /dev/null @@ -1,25 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inCollection(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'collection_count'); - this.baseURL.searchParams.set('id', id); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inCollection; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inEntireDB.js b/main/methods/getWallpaperCount/inEntireDB.js deleted file mode 100644 index 981512f..0000000 --- a/main/methods/getWallpaperCount/inEntireDB.js +++ /dev/null @@ -1,24 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inEntireDB(options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'wallpaper_count'); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inEntireDB; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inFeatured.js b/main/methods/getWallpaperCount/inFeatured.js deleted file mode 100644 index 27eceae..0000000 --- a/main/methods/getWallpaperCount/inFeatured.js +++ /dev/null @@ -1,24 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inFeatured(options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'featured_count'); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inFeatured; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inGroup.js b/main/methods/getWallpaperCount/inGroup.js deleted file mode 100644 index 928c6cf..0000000 --- a/main/methods/getWallpaperCount/inGroup.js +++ /dev/null @@ -1,25 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inGroup(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'group_count'); - this.baseURL.searchParams.set('id', id); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inGroup; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inPopular.js b/main/methods/getWallpaperCount/inPopular.js deleted file mode 100644 index 2158b62..0000000 --- a/main/methods/getWallpaperCount/inPopular.js +++ /dev/null @@ -1,24 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inPopular(options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'popular_count'); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inPopular; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inSubCategory.js b/main/methods/getWallpaperCount/inSubCategory.js deleted file mode 100644 index eb82556..0000000 --- a/main/methods/getWallpaperCount/inSubCategory.js +++ /dev/null @@ -1,25 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inSubCategory(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'sub_category_count'); - this.baseURL.searchParams.set('id', id); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inSubCategory; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inTag.js b/main/methods/getWallpaperCount/inTag.js deleted file mode 100644 index e255a20..0000000 --- a/main/methods/getWallpaperCount/inTag.js +++ /dev/null @@ -1,25 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inTag(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'tag_count'); - this.baseURL.searchParams.set('id', id); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inTag; \ No newline at end of file diff --git a/main/methods/getWallpaperCount/inUser.js b/main/methods/getWallpaperCount/inUser.js deleted file mode 100644 index f86c7b3..0000000 --- a/main/methods/getWallpaperCount/inUser.js +++ /dev/null @@ -1,25 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function inUser(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'user_count'); - this.baseURL.searchParams.set('id', id); - - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - resolve(response.count); - }); - }); -}; - -module.exports = inUser; \ No newline at end of file diff --git a/main/methods/getWallpaperInfo.js b/main/methods/getWallpaperInfo.js deleted file mode 100644 index 2b775dd..0000000 --- a/main/methods/getWallpaperInfo.js +++ /dev/null @@ -1,39 +0,0 @@ -const misc = require('../misc/misc.json'); - -function getWallpaperInfo(id) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'wallpaper_info'); - this.baseURL.searchParams.set('id', id); - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../misc/errorHandler')(response); } - - let data = { wallpaper: {}, tags: [] }; - - data.wallpaper.id = response.wallpaper.id; - data.wallpaper.name = response.wallpaper.name; - data.wallpaper.featured = response.wallpaper.featured; - data.wallpaper.width = response.wallpaper.width; - data.wallpaper.height = response.wallpaper.height; - data.wallpaper.fileType = response.wallpaper.file_type; - data.wallpaper.fileSize = response.wallpaper.file_size; - data.wallpaper.url = { image: response.wallpaper.url_image, thumbnail: response.wallpaper.url_thumb, webpage: response.wallpaper.url_page }; - data.wallpaper.category = { name: response.wallpaper.category, id: response.wallpaper.category_id }; - data.wallpaper.subCategory = { name: response.wallpaper.sub_category, id: response.wallpaper.sub_category_id }; - data.wallpaper.user = { name: response.wallpaper.user_name, id: response.wallpaper.user_id }; - data.wallpaper.collection = { name: response.wallpaper.collection , id: response.wallpaper.collection_id }; - data.wallpaper.group = { name: response.wallpaper.group , id: response.wallpaper.group_id }; - - data.tags = response.tags; - - resolve(data); - }); - }); -}; - -module.exports = getWallpaperInfo; \ No newline at end of file diff --git a/main/methods/getWallpapers/bySort.js b/main/methods/getWallpapers/bySort.js deleted file mode 100644 index e1d90f8..0000000 --- a/main/methods/getWallpapers/bySort.js +++ /dev/null @@ -1,69 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function getWallpapers(sorting, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - const sorts = - { - newest: 'newest', - rating: 'highest_rated', - views: 'by_views', - favorites: 'by_favorites' - }; - - this.baseURL.searchParams.set('method', sorts[sorting]); - this.baseURL.searchParams.set('info_level', 3); - - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = getWallpapers; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromCategory.js b/main/methods/getWallpapers/fromCategory.js deleted file mode 100644 index 3da1626..0000000 --- a/main/methods/getWallpapers/fromCategory.js +++ /dev/null @@ -1,63 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromCategory(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'category'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('id', id); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromCategory; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromCollection.js b/main/methods/getWallpapers/fromCollection.js deleted file mode 100644 index ff5dcab..0000000 --- a/main/methods/getWallpapers/fromCollection.js +++ /dev/null @@ -1,63 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromCollection(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'collection'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('id', id); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromCollection; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromFeatured.js b/main/methods/getWallpapers/fromFeatured.js deleted file mode 100644 index be63c26..0000000 --- a/main/methods/getWallpapers/fromFeatured.js +++ /dev/null @@ -1,62 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromFeatured(options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'featured'); - this.baseURL.searchParams.set('info_level', 3); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromFeatured; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromGroup.js b/main/methods/getWallpapers/fromGroup.js deleted file mode 100644 index 956f214..0000000 --- a/main/methods/getWallpapers/fromGroup.js +++ /dev/null @@ -1,63 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromGroup(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'group'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('id', id); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromGroup; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromPopular.js b/main/methods/getWallpapers/fromPopular.js deleted file mode 100644 index e142e75..0000000 --- a/main/methods/getWallpapers/fromPopular.js +++ /dev/null @@ -1,61 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromPopular(options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'popular'); - this.baseURL.searchParams.set('info_level', 3); - - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromPopular; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromSubCategory.js b/main/methods/getWallpapers/fromSubCategory.js deleted file mode 100644 index 0038fef..0000000 --- a/main/methods/getWallpapers/fromSubCategory.js +++ /dev/null @@ -1,63 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromSubCategory(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'sub_category'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('id', id); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromSubCategory; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromTag.js b/main/methods/getWallpapers/fromTag.js deleted file mode 100644 index 186a5bb..0000000 --- a/main/methods/getWallpapers/fromTag.js +++ /dev/null @@ -1,63 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromTag(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'tag'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('id', id); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromTag; \ No newline at end of file diff --git a/main/methods/getWallpapers/fromUser.js b/main/methods/getWallpapers/fromUser.js deleted file mode 100644 index 5769571..0000000 --- a/main/methods/getWallpapers/fromUser.js +++ /dev/null @@ -1,63 +0,0 @@ -const misc = require('../../misc/misc.json'); - -function fromUser(id, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'user'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('id', id); - - if (options?.sort !== undefined) { this.baseURL.searchParams.set('sort', options.sort); } - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = fromUser; \ No newline at end of file diff --git a/main/methods/others.js b/main/methods/others.js new file mode 100644 index 0000000..654b679 --- /dev/null +++ b/main/methods/others.js @@ -0,0 +1,97 @@ +const process = require('../utils'); + +function search(term, options) +{ + const url = process.getBaseURL(); + + url.searchParams.set('method', 'search'); + + if (term === undefined) throw new Error('Search term not provided !'); + + url.searchParams.set('term', term); + + process.params(options).forEach(x => url.searchParams.set(x[0], x[1])); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.wallpapers, 'WALLPAPER'); + + resolve(send); + }); + }); +}; + +function getWallpaper(id) +{ + const url = process.getBaseURL(); + + if (id === undefined) throw new Error('Wallpaper ID not provided !'); + + url.searchParams.set('method', 'wallpaper_info'); + url.searchParams.set('id', id); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const data = process.data([response.wallpaper], 'WALLPAPER'); + + resolve({ wallpaper: data[0], tags: response.tags }); + }); + }); +}; + +function getRandomWallpaper(type) +{ + const url = process.getBaseURL(); + + url.searchParams.set('method', 'random'); + + type === undefined ? null : url.searchParams.set('type', type); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = process.data(response.wallpapers, 'WALLPAPER'); + + resolve(send); + }); + }); +}; + +function queryCount() +{ + const url = process.getBaseURL(); + + url.searchParams.set('method', 'query_count'); + + return new Promise((resolve) => + { + fetch(url).then(x => x.json()).then((response) => + { + if (process.response(response) === null) return resolve(null); + + const send = + { + used: response.count, + unused: 100000 - response.count, + percentUsed: `${(response.count / 1000)}%` + }; + + resolve(send); + }); + }); +}; + + + +module.exports = { search, getWallpaper, getRandomWallpaper, queryCount }; \ No newline at end of file diff --git a/main/methods/queryCount.js b/main/methods/queryCount.js deleted file mode 100644 index 7c7824e..0000000 --- a/main/methods/queryCount.js +++ /dev/null @@ -1,27 +0,0 @@ -const misc = require('../misc/misc.json'); - -function queryCount() -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'query_count'); - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../misc/errorHandler')(response); } - - let data = { currentMonth: {}, previousMonth: {} }; - - data.currentMonth.count = response.counts.month_count; - data.currentMonth.price = response.counts.month_price; - data.previousMonth.count = response.counts.last_month_count; - data.previousMonth.price = response.counts.last_month_price; - - resolve(data); - }); - }); -}; - -module.exports = queryCount; \ No newline at end of file diff --git a/main/methods/search.js b/main/methods/search.js deleted file mode 100644 index 517c46c..0000000 --- a/main/methods/search.js +++ /dev/null @@ -1,62 +0,0 @@ -const misc = require('../misc/misc.json'); - -function search(term, options) -{ - misc.params.forEach(x => x === 'auth' ? null : this.baseURL.searchParams.delete(x)); - - this.baseURL.searchParams.set('method', 'search'); - this.baseURL.searchParams.set('info_level', 3); - this.baseURL.searchParams.set('term', term); - - if (options?.page !== undefined) { this.baseURL.searchParams.set('page', options.page); } - if (options?.width !== undefined) { this.baseURL.searchParams.set('width', options.width); } - if (options?.height !== undefined) { this.baseURL.searchParams.set('height', options.height); } - if (options?.operator !== undefined) { this.baseURL.searchParams.set('operator', options.operator); } - - return new Promise((resolve) => - { - fetch(this.baseURL).then(x => x.json()).then((response) => - { - if (response.success === false) { return require('../misc/errorHandler')(response); } - - let - data = [], - temp = {}; - - response.wallpapers.forEach((item) => - { - temp.id = item.id; - temp.width = item.width; - temp.height = item.height; - temp.fileType = item.file_type; - temp.fileSize = item.file_size; - temp.url = { image: item.url_image, thumbnail: item.url_thumb, webpage: item.url_page }; - - if (options?.level === 2) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - } - - if (options?.level === 3) - { - temp.category = { name: item.category, id: item.category_id }; - temp.subCategory = { name: item.sub_category, id: item.sub_category_id }; - temp.user = { name: item.user_name, id: item.user_id }; - - temp.collection = { name: item.collection , id: item.collection_id }; - temp.group = { name: item.group , id: item.group_id }; - } - - data.push(temp); - - temp = {}; - }); - - resolve(data); - }); - }); -}; - -module.exports = search; \ No newline at end of file diff --git a/main/misc/errorHandler.js b/main/misc/errorHandler.js deleted file mode 100644 index 3967851..0000000 --- a/main/misc/errorHandler.js +++ /dev/null @@ -1,10 +0,0 @@ -const misc = require('./misc.json'); - -function errorHandler(response) -{ - const E = new Error(misc.description + '\nReason: ' + misc.errors[response.error]); - - throw E; -}; - -module.exports = errorHandler; \ No newline at end of file diff --git a/main/misc/misc.json b/main/misc/misc.json deleted file mode 100644 index ff1d1b4..0000000 --- a/main/misc/misc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "errors": - { - "auth_missing": "No authentication key provided.", - "invalid_auth": "Invalid authentication key.", - "method_missing": "No method name provided.", - "db_connect": "Failed to connect to database.", - "id_missing": "No ID is provided.", - "term_missing": "No search term provided.", - "term_empty": "The search term provided is empty." - }, - - "description": "This error originated from the package: alpha-coders", - - "params": ["auth", "method", "info_level", "page", "width", "height", "operator", "check_last", "id", "sort", "term", "count"] -} \ No newline at end of file diff --git a/main/types.d.ts b/main/types.d.ts index 049d411..1ca65a0 100644 --- a/main/types.d.ts +++ b/main/types.d.ts @@ -1,293 +1,306 @@ -type sort = 'newest' | 'rating' | 'views' | 'favorites' -type operator = 'min' | 'max' | 'equal' -type fileType = 'jpg' | 'png' | String -type level = 1 | 2 | 3 - -type url = +type BySortOptions = { - image: String; - thumbnail: String; - webpage: String; -} + /** + * Height of the wallpaper in pixels. + */ + height: Number; -type bySortOptions = -{ - level: level; + /** + * Filter out with respect to the Height and Width. + */ + operator: Operator; + + /** + * Different sets of results. + */ page: Number; + + /** + * [Min, Max] ratios of the wallpaper size. Applicable only to 'phone' type. + */ + ratio: [Number, Number]; + + /** + * Type of the device. + */ + type: DeviceType; + + /** + * Width of the wallpaper in pixels. + */ width: Number; - height: Number; - operator: operator; -} +}; -type getWallpapers = -{ - id: String; - width: String; - height: String; - fileType: fileType; - fileSize: String; - url: url; - category?: { name: String; id: String; }; - subCategory?: { name: String; id: String; } - user?: { name: String; id: String; } - collection?: { name: String | null; id: String | null; }; - group?: { name: String | null; id: String | null; }; -} +/** + * Type of the device. + */ +type DeviceType = 'desktop' | 'phone'; -type getWallpapersOptions = +type File = { - level: level; - sort: sort; - page: Number; - width: Number; - height: Number; - operator: operator; -} + /** + * Size of the file in MegaBytes (MB) + */ + size: Number; -type countOptions = + /** + * Type of the file. + */ + type: 'jpg' | 'png' | String; +}; + +type GetWallpapersOptions = { - width: Number; + /** + * Height of the wallpaper in pixels. + */ height: Number; - operator: operator; -} -type list = -{ - id: Number; - name: String; - count: Number; - url: String; -} + /** + * Filter out with respect to the Height and Width. + */ + operator: Operator; -type wallpaper = -{ - id: String; - name: String | null; - featured: Boolean | null; - width: String; - height: String; - fileType: fileType; - fileSize: String; - url: url; - category: { name: String; id: String; }; - subCategory: { name: String; id: String; }; - user: { name: String; id: String; }; - collection: { name: String | null; id: String | null; }; - group: { name: String | null; id: String | null; }; -} + /** + * Different sets of results. + */ + page: Number; -type wallpaperInfo = -{ - wallpaper: wallpaper; - tag: Array<{ id: Number; name: String; }>; -} + /** + * [Min, Max] ratios of the wallpaper size. Applicable only to 'phone' type. + */ + ratio: [Number, Number]; -type randomOptions = -{ - count: Number; - level: level; -} + /** + * A sorting method. + */ + sort: Sort; -type queryCount = -{ - currentMonth: - { - count: Number; - price: Number | Float64Array; - }; + /** + * Type of the device. + */ + type: DeviceType; - previousMonth: - { - count: Number; - price: Number | Float64Array; - } -} + /** + * Width of the wallpaper in pixels. + */ + width: Number; +}; -declare class Alpha +type List = { - constructor(apiToken: String); + /** + * ID of the Category or Sub-Category. + */ + id: Number; /** - * Get wallpapers + * Name of the Category or Sub-Category. */ - getWallpapers: + name: String; + + wallpaperCount: { /** - * Returns an Array of wallpapers by the given sort type. - * @param sorting A sorting method. - * @param options Optional parameters + * Number of wallpapers for desktop devices. */ - bySort(sorting: sort, options?: bySortOptions): Promise>; + desktop: Number; /** - * Returns an Array of wallpapers belonging to a single Category. - * @param id ID of the category. - * @param options Optional parameters + * Number of wallpapers for mobile devices. */ - fromCategory(id: Number, options?: getWallpapersOptions): Promise>; + phone: Number; + } +}; - /** - * Returns an Array of wallpapers belonging to a single Collection. - * @param id ID of the collection. - * @param options Optional parameters - */ - fromCollection(id: Number, options?: getWallpapersOptions): Promise>; +type NameID = +{ + /** + * ID of the preceding object. + */ + id?: Number; - /** - * Returns an Array of wallpapers belonging to a single Group. - * @param id ID of the group. - * @param options Optional parameters - */ - fromGroup(id: Number, options?: getWallpapersOptions): Promise>; + /** + * Name of the preceding object. + */ + name?: String | null; +}; - /** - * Returns an Array of wallpapers belonging to a single Sub-Category. - * @param id ID of the Sub-Category. - * @param options Optional parameters - */ - fromSubCategory(id: Number, options?: getWallpapersOptions): Promise>; +/** + * Filter out with respect to the Height and Width. + */ +type Operator = 'min' | 'max' | 'equal'; - /** - * Returns featured Wallpapers. - * @param options Optional Parameters - */ - fromFeatured(options?: getWallpapersOptions): Promise>; +type QueryCount = +{ + /** + * Percentage of the API calls used. + */ + percentUsed: String; - /** - * Returns recently popular Wallpapers. - * @param options Optional Parameters - */ - fromPopular(options?: getWallpapersOptions): Promise>; + /** + * Number of used API calls. + */ + used: Number; - /** - * Returns an Array of wallpapers belonging to a single Tag. - * @param id ID of the Tag. - * @param options Optional parameters - */ - fromTag(id: Number, options?: getWallpapersOptions): Promise>; + /** + * Number of unused API calls. + */ + unused: Number; +}; - /** - * Returns an Array of wallpapers uploaded by a single User. - * @param id ID of the User. - * @param options Optional parameters - */ - fromUser(id: Number, options?: getWallpapersOptions): Promise>; - }; +/** + * Sorting methods. + */ +type Sort = 'newest' | 'rating'; +type URL = +{ /** - * Get wallpapers Count + * Link to the image. */ - getWallpaperCount: - { - /** - * Returns the count of Wallpapers present all over on Wallpaper Abyss. - * @param options Optional parameters - */ - inEntireDB(options?: countOptions): Promise; + image: String; - /** - * Returns the count of Wallpapers in a given Category. - * @param id ID of the Category. - * @param options Optional parameters - */ - inCategory(id: Number, options?: countOptions): Promise; + /** + * Link to the thumbnail version of the image. + */ + thumbnail: String; - /** - * Returns the count of Wallpapers in a given Collection. - * @param id ID of the Collection. - * @param options Optional parameters - */ - inCollection(id: Number, options?: countOptions): Promise; + /** + * Link to the webpage where the image is held. + */ + webpage: String; +}; - /** - * Returns the count of Wallpapers in a given Group. - * @param id ID of the Group. - * @param options Optional parameters - */ - inGroup(id: Number, options?: countOptions): Promise; +type Wallpaper = +{ + file: File; + url: URL; + user: NameID; + + /** + * Height of the wallpaper in pixels. + */ + height: Number; + /** + * ID of the wallpaper. + */ + id: Number; + + /** + * Width of the wallpaper in pixels. + */ + width: Number; + + category: + { /** - * Returns the count of Wallpapers in a given Sub-Category. - * @param id ID of the Sub-Category. - * @param options Optional parameters + * ID of the category. */ - inSubCategory(id: Number, options?: countOptions): Promise; + id: Number; /** - * Returns the count of Featured Wallpapers. - * @param options Optional Parameters + * Name of the category. */ - inFeatured(options?: countOptions): Promise; + name: String; /** - * Returns the count of recently Popular Wallpapers. - * @param option Optional Parameters + * Sub-Category of the Wallpaper. */ - inPopular(option?: countOptions): Promise; + sub: NameID; + }; +}; + +type WallpaperInfo = +{ + /** + * Tags of the wallpaper + */ + tags: Array; + + wallpaper: Wallpaper; +}; +declare class Alpha +{ + constructor(apiToken: String); + + /** + * Get Lists + */ + getList: + { /** - * Returns the count of Wallpapers tagged with a given Tag. - * @param id ID of the Tag. - * @param options Optional parameters + * Get the list of Categories used on Wallpaper Abyss. */ - inTag(id: Number, options?: countOptions): Promise; + ofCategory(): Promise>; /** - * Returns the count of Wallpapers submitted a given User. - * @param id ID of the User. - * @param options Optional parameters + * Get the list of Sub-Categories in a given Category. + * @param id ID of a Category. + * @param page Which set of results to be obtained (1 - 200) */ - inUser(id: Number, options?: countOptions): Promise; + ofSubCategory(id: Number, page?: Number): Promise>; }; - getList: + /** + * Get wallpapers + */ + getSpecificWallpapers: { /** - * Returns the list of Categories used on Wallpaper Abyss. + * Get an array of random wallpapers in a specific sort. + * @param sorting A sorting method. + * @param options Optional parameters. */ - ofCategory(): Promise>; + bySort(sorting: Sort, options?: BySortOptions): Promise | null>; /** - * Returns the list of Collections used on Wallpaper Abyss. + * Gets an Array of wallpapers belonging to a single Category. + * @param id ID of the category. + * @param options Optional parameters. */ - ofCollection(): Promise>; + fromCategory(id: Number, options?: GetWallpapersOptions): Promise | null>; /** - * Returns the list of Groups in a given Collection. - * @param id ID of a Collection. + * Gets an Array of wallpapers belonging to a single Sub-Category. + * @param id ID of the Sub-Category. + * @param options Optional parameters. */ - ofGroup(id: Number): Promise>; + fromSubCategory(id: Number, options?: GetWallpapersOptions): Promise | null>; /** - * Returns the list of Sub-Categories in a given Category. - * @param id ID of a Category. + * Gets an Array of wallpapers belonging to a single Tag. + * @param id ID of the Tag. + * @param options Optional parameters. */ - ofSubCategory(id: Number): Promise>; + fromTag(id: Number, options?: GetWallpapersOptions): Promise | null>; }; /** - * Returns Wallpapers matching a given search term. - * @param term The search term used for the matching. (MAX 128 Characters) - * @param options Optional Parameters + * Get an array of random wallpapers. + * @param device Type of the device. */ - search(term: String, options?: bySortOptions): Promise>; + getRandomWallpapers(device?: DeviceType): Promise>; /** - * Returns advanced information about a Wallpaper. + * Get a specific Wallpaper with its Tags. * @param id ID of the wallpaper. */ - getWallpaperInfo(id: Number): Promise; + getWallpaper(id: Number): Promise; /** - * Returns a fixed amount of random wallpapers. - * @param options Optional Parameters + * Get Wallpapers matching a given search term. + * @param term The search term used for the matching. (MAX 128 Characters) + * @param options Optional Parameters. */ - getRandomWallpaper(options?: randomOptions): Promise>; + search(term: String, options?: BySortOptions): Promise | null>; /** - * Returns the API calls and pricing associated with an API key. + * Get the API calls associated with the API key. */ - queryCount(): Promise; + queryCount(): Promise; } export = Alpha; \ No newline at end of file diff --git a/main/utils.js b/main/utils.js new file mode 100644 index 0000000..a33857c --- /dev/null +++ b/main/utils.js @@ -0,0 +1,135 @@ +let BASEURL; + +function setBaseURL(url) { BASEURL = url }; + +function getBaseURL() { return new URL(BASEURL) }; + +function params(params) +{ + const dummy = new Map(); + + ['type', 'page', 'sort'].forEach((x) => + { + if (params?.[x] !== undefined) dummy.set(x, params[x]); + }); + + if (params?.ratio?.length === 2) + { + const min = params.ratio[0]; + const max = params.ratio[1]; + + if (min > max) return; + + dummy.set('min_ratio', min); + dummy.set('max_ratio', max); + + if (params?.type !== 'phone') dummy.set('type', 'phone'); + } + + if (params?.operator !== undefined) + { + if (params?.height !== undefined || params?.width !== undefined) + { + dummy.set('operator', params.operator); + + params?.height === undefined ? null : dummy.set('height', params.height); + params?.width === undefined ? null : dummy.set('width', params.width); + } + } + + else if (params?.height !== undefined && params?.width !== undefined) + { + dummy.set('height', params.height); + dummy.set('width', params.width); + } + + return [...dummy]; +}; + +function response(res) +{ + if (res.success) + { + if (res?.wallpapers?.length === 0) return null; + } + + else + { + if (res.error === 'invalid_auth') throw new Error('API Key is invalid !'); + + if (res.error === 'id_required') return null; + + if (res.error === 'tag_not_found') return null; + } +}; + +function data(obj, type) +{ + const send = []; + + if (type === 'LIST') + { + obj.forEach((x) => + { + send.push + ({ + id: x.id, + name: x.name, + + wallpaperCount: + { + desktop: x.desktop_wallpaper_count, + phone: x.phone_wallpaper_count + } + }); + }); + } + + if (type === 'WALLPAPER') + { + obj.forEach((x) => + { + send.push + ({ + id: x.id, + height: x.height, + width: x.width, + + category: + { + name: x.category, + id: x.category_id, + + sub: + { + name: x.sub_category, + id: x.sub_category_id + } + }, + + file: + { + type: x.file_type, + size: x.file_size / (1024 * 1000) + }, + + url: + { + image: x.url_image, + thumbnail: x.url_thumb, + webpage: x.url_page + }, + + user: + { + name: x.user_name, + id: x.user_id + } + }); + }); + } + + return send; +}; + +module.exports = { params, response, data, setBaseURL, getBaseURL }; \ No newline at end of file diff --git a/package.json b/package.json index d01c96f..63f79cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alpha-coders", - "version": "2.1.0", + "version": "3.0.0", "description": "A complete package used to interact with the Wallpaper Abyss / The Alpha Coders API to get wallpapers, wallpaper count, collections, and much more !", "main": "main/index.js",