convert processJsonSubredditsExplore to async function
This commit is contained in:
parent
6ced924bc8
commit
e1df2ea8ae
|
@ -1,52 +1,58 @@
|
||||||
module.exports = function() {
|
const config = require('../config');
|
||||||
const config = require('../config');
|
|
||||||
this.processJsonSubredditsExplore = (json, from, subreddit_front, user_preferences) => {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
(async () => {
|
|
||||||
if(from === 'redis') {
|
|
||||||
json = JSON.parse(json)
|
|
||||||
}
|
|
||||||
if(json.error) {
|
|
||||||
resolve({ error: true, error_data: json })
|
|
||||||
} else {
|
|
||||||
let before = json.data.before
|
|
||||||
let after = json.data.after
|
|
||||||
|
|
||||||
let ret = {
|
async function processJsonSubredditsExplore(
|
||||||
info: {
|
json,
|
||||||
before: before,
|
from,
|
||||||
after: after
|
subreddit_front,
|
||||||
},
|
user_preferences
|
||||||
links: []
|
) {
|
||||||
}
|
if (from === 'redis') {
|
||||||
|
json = JSON.parse(json);
|
||||||
|
}
|
||||||
|
if (json.error) {
|
||||||
|
return { error: true, error_data: json };
|
||||||
|
} else {
|
||||||
|
let before = json.data.before;
|
||||||
|
let after = json.data.after;
|
||||||
|
|
||||||
let children_len = json.data.children.length
|
let ret = {
|
||||||
|
info: {
|
||||||
|
before: before,
|
||||||
|
after: after,
|
||||||
|
},
|
||||||
|
links: [],
|
||||||
|
};
|
||||||
|
|
||||||
for(var i = 0; i < children_len; i++) {
|
let children_len = json.data.children.length;
|
||||||
let data = json.data.children[i].data
|
|
||||||
|
|
||||||
if(data.over_18)
|
for (var i = 0; i < children_len; i++) {
|
||||||
if((config.nsfw_enabled === false && user_preferences.nsfw_enabled != 'true') || user_preferences.nsfw_enabled === 'false')
|
let data = json.data.children[i].data;
|
||||||
continue
|
|
||||||
|
|
||||||
let obj = {
|
if (data.over_18)
|
||||||
created: data.created_utc,
|
if (
|
||||||
id: data.id,
|
(config.nsfw_enabled === false &&
|
||||||
over_18: data.over_18,
|
user_preferences.nsfw_enabled != 'true') ||
|
||||||
display_name: data.display_name,
|
user_preferences.nsfw_enabled === 'false'
|
||||||
display_name_prefixed: data.display_name_prefixed,
|
)
|
||||||
public_description: data.public_description,
|
continue;
|
||||||
url: replaceDomains(data.url, user_preferences),
|
|
||||||
subscribers: data.subscribers,
|
let obj = {
|
||||||
over_18: data.over18,
|
created: data.created_utc,
|
||||||
title: data.title,
|
id: data.id,
|
||||||
subreddit_front: subreddit_front,
|
over_18: data.over_18,
|
||||||
}
|
display_name: data.display_name,
|
||||||
ret.links.push(obj)
|
display_name_prefixed: data.display_name_prefixed,
|
||||||
}
|
public_description: data.public_description,
|
||||||
resolve(ret)
|
url: replaceDomains(data.url, user_preferences),
|
||||||
}
|
subscribers: data.subscribers,
|
||||||
})()
|
over_18: data.over18,
|
||||||
})
|
title: data.title,
|
||||||
|
subreddit_front: subreddit_front,
|
||||||
|
};
|
||||||
|
ret.links.push(obj);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = processJsonSubredditsExplore;
|
||||||
|
|
|
@ -11,8 +11,7 @@ const processSearchResults = require('../inc/processSearchResults.js');
|
||||||
const processJsonSubreddit = require('../inc/processJsonSubreddit.js');
|
const processJsonSubreddit = require('../inc/processJsonSubreddit.js');
|
||||||
const tedditApiSubreddit = require('../inc/teddit_api/handleSubreddit.js')();
|
const tedditApiSubreddit = require('../inc/teddit_api/handleSubreddit.js')();
|
||||||
const processMoreComments = require('../inc/processMoreComments.js')();
|
const processMoreComments = require('../inc/processMoreComments.js')();
|
||||||
const processSubredditsExplore =
|
const processJsonSubredditsExplore = require('../inc/processSubredditsExplore.js');
|
||||||
require('../inc/processSubredditsExplore.js')();
|
|
||||||
|
|
||||||
subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
|
subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
|
||||||
let subreddit = req.params.subreddit;
|
let subreddit = req.params.subreddit;
|
||||||
|
|
Loading…
Reference in New Issue