mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-09-09 09:05:14 -05:00
Early version of /v1/communities
This commit is contained in:
@@ -65,6 +65,13 @@ async function getCommunityByTitleID(title_id) {
|
||||
});
|
||||
}
|
||||
|
||||
async function getCommunityByTitleIDs(title_ids) {
|
||||
verifyConnected();
|
||||
return COMMUNITY.findOne({
|
||||
title_ids: {$in: title_ids}
|
||||
});
|
||||
}
|
||||
|
||||
async function getCommunityByID(community_id) {
|
||||
verifyConnected();
|
||||
return COMMUNITY.findOne({
|
||||
@@ -490,6 +497,7 @@ module.exports = {
|
||||
getNewCommunities,
|
||||
getSubCommunities,
|
||||
getCommunityByTitleID,
|
||||
getCommunityByTitleIDs,
|
||||
getCommunityByID,
|
||||
getTotalPostsByCommunity,
|
||||
getPostsByCommunity,
|
||||
|
||||
@@ -87,4 +87,17 @@ router.get('/:appID/posts', async function (req, res) {
|
||||
res.send(await comPostGen.PostsResponse(posts, community, options));
|
||||
});
|
||||
|
||||
// Handler for POST on '/v1/communities'
|
||||
router.post('/', async function (req, res) {
|
||||
console.error("AM I HERE ?.?.????");
|
||||
console.log(req.body);
|
||||
const paramPack = util.decodeParamPack(req.headers["x-nintendo-parampack"]);
|
||||
console.log(paramPack);
|
||||
let community = await database.getCommunityByTitleIDs(paramPack.title_id);
|
||||
if(!community) res.sendStatus(404);
|
||||
let response = await comPostGen.Community(community);
|
||||
res.contentType("application/xml");
|
||||
res.send(response);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -86,6 +86,31 @@ class XmlResponseGenerator {
|
||||
return xml.up().end({ pretty: true, allowEmpty: true});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates response to a acommunity request
|
||||
* @param communities
|
||||
* @returns xml
|
||||
* @constructor
|
||||
*/
|
||||
static async Community(community) {
|
||||
let xml = xmlbuilder.create("result", { encoding: 'UTF-8' })
|
||||
.e("has_error", "0").up()
|
||||
.e("version", "1").up()
|
||||
.e("request_name", "community").up()
|
||||
.e("community")
|
||||
.e('community_id', community.community_id).up()
|
||||
.e("name", community.name).up()
|
||||
.e("description", community.description).up()
|
||||
.e("icon").up()
|
||||
.e("icon_3ds").up()
|
||||
.e("pid").up()
|
||||
.e("app_data", community.app_data).up()
|
||||
.e("is_user_community", 0)
|
||||
.up()
|
||||
|
||||
return xml.up().end({ pretty: true, allowEmpty: true});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate response to request for single post
|
||||
* @param post
|
||||
|
||||
Reference in New Issue
Block a user