Fixed topics and communities response

This commit is contained in:
Jemma Poffinbarger 2023-04-16 18:18:16 -05:00
parent 58f11a21b1
commit aeb07a2f38
6 changed files with 19 additions and 14 deletions

View File

@ -68,7 +68,7 @@ async function getCommunityByTitleID(title_id) {
async function getCommunityByID(community_id) {
verifyConnected();
return COMMUNITY.findOne({
olive_community_id: community_id
community_id: community_id
});
}

View File

@ -80,7 +80,8 @@ router.get('/:appID/posts', async function (req, res) {
let options = {
name: 'posts',
with_mii: req.query.with_mii === '1',
app_data: true
app_data: true,
topic_tag: true
}
res.contentType("application/xml");
res.send(await comPostGen.PostsResponse(posts, community, options));

View File

@ -8,7 +8,7 @@ const util = require('../../../util/util')
/* GET post titles. */
router.get('/', async function (req, res) {
let userContent = await database.getUserContent(req.pid);
if(!userContent) return res.sendStatus(404);
let query = {
removed: false,
is_spoiler: 0,
@ -45,7 +45,8 @@ router.get('/', async function (req, res) {
/* Build formatted response and send it off. */
let options = {
name: 'posts',
with_mii: req.query.with_mii === '1'
with_mii: req.query.with_mii === '1',
topic_tag: true
}
res.contentType("application/xml");
res.send(await xmlGenerator.People(posts, options));

View File

@ -21,6 +21,8 @@ router.post('/:post_id/replies', upload.none(), async function (req, res) { awai
router.post('/:post_id.delete', async function (req, res) {
const post = await database.getPostByID(req.params.post_id);
let user = await database.getUserContent(req.pid);
if(!post || !user)
return res.sendStatus(504);
if(post.pid === user.pid) {
await post.remove('User requested removal');
res.sendStatus(200);
@ -77,7 +79,8 @@ router.get('/:post_id/replies', async function (req, res) {
return res.sendStatus(404);
let options = {
name: 'replies',
with_mii: req.query.with_mii === 1
with_mii: req.query.with_mii === 1,
topic_tag: true
}
/* Build formatted response and send it off. */
let response = await communityPostGen.RepliesResponse(posts, options)

View File

@ -17,7 +17,7 @@ router.get('/', async function (req, res) {
if(!discovery.topics) return res.sendStatus(404);
let communities = await calculateMostPopularCommunities(24, 10);
if(communities === null) return res.sendStatus(404);
if(communities === null || communities.length < 10) return res.sendStatus(404);
let response = await memoized(communities);
res.contentType("application/xml");
@ -27,9 +27,8 @@ router.get('/', async function (req, res) {
async function calculateMostPopularCommunities(hours, limit) {
const now = new Date();
const last24Hours = new Date(now.getTime() - hours * 60 * 60 * 1000);
const posts = await POST.find({ created_at: { $gte: last24Hours }, message_to_pid: null }).lean();
const posts = await POST.find({ created_at: { $gte: last24Hours }, message_to_pid: null });
if(!posts) return;
const communityIds = {};
for (const post of posts) {
const communityId = post.community_id;
@ -39,7 +38,7 @@ async function calculateMostPopularCommunities(hours, limit) {
.sort((a, b) => b[1] - a[1])
.map((entry) => entry[0]);
if(communities.size < limit)
return calculateMostPopularCommunities(hours + hours, limit);
return COMMUNITY.find().limit(limit).sort({followers: -1});
let response = await COMMUNITY.aggregate([
{ $match: { olive_community_id: { $in: communities }, parent: null } },

View File

@ -152,7 +152,7 @@ class XmlResponseGenerator {
for (const post of posts) {
xml = xml.e("person")
.e("posts")
postObj(xml, post, { with_mii: true, app_data: false });
postObj(xml, post, { with_mii: true, app_data: false, topic_tag: false, topics: true }, community);
xml = xml.up().up();
}
xml = xml.up().up()
@ -212,14 +212,15 @@ class XmlResponseGenerator {
* @param xml
* @param post
* @param options
* @param community
*/
function postObj(xml, post, options) {
function postObj(xml, post, options, community) {
xml = xml.e("post");
if (post.app_data && options.app_data) {
xml.e("app_data", post.app_data.replace(/[^A-Za-z0-9+/=]/g, "").replace(/[\n\r]+/gm, '').trim()).up();
}
xml.e("body", post.body ? post.body.replace(/[^A-Za-z\d\s-_!@#$%^&*(){}+=,.<>/?;:'"\[\]]/g, "").replace(/[\n\r]+/gm, '') : "").up()
.e("community_id", post.community_id).up()
.e("community_id", options.topics ? community.community_id : post.community_id).up()
.e("country_id", post.country_id ? post.country_id : 254).up()
.e("created_at", new moment(post.created_at).format('YYYY-MM-DD HH:MM:SS')).up()
.e("feeling_id", post.feeling_id).up()
@ -254,7 +255,7 @@ function postObj(xml, post, options) {
.e("url", `https://pretendo-cdn.b-cdn.net/screenshots/${post.pid}/${post.id}.jpg`).up()
.up();
}
if (post.topic_tag) {
if (post.topic_tag && options.topic_tag) {
xml.e("topic_tag")
.e("name", post.topic_tag).up()
.e("title_id", post.title_id).up()