mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-08-23 09:04:13 -05:00
added support for /v1/topics
This commit is contained in:
committed by
jay.poff@outlook.com
parent
9221ab4851
commit
7175e20364
@@ -8,7 +8,8 @@ const endpointSchema = new Schema({
|
||||
api_host: String,
|
||||
portal_host: String,
|
||||
n3ds_host: String
|
||||
}
|
||||
},
|
||||
guest: Boolean,
|
||||
});
|
||||
|
||||
endpointSchema.methods.updateHosts = async function({host, api_host, portal_host, n3ds_host}) {
|
||||
@@ -19,6 +20,11 @@ endpointSchema.methods.updateHosts = async function({host, api_host, portal_host
|
||||
await this.save();
|
||||
};
|
||||
|
||||
endpointSchema.methods.updateGuest = async function(mode) {
|
||||
this.set('guest', mode);
|
||||
await this.save();
|
||||
}
|
||||
|
||||
const ENDPOINT = model('ENDPOINT', endpointSchema);
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -17,7 +17,6 @@ logger.info('[MIIVERSE] Creating \'discovery\' subdomain');
|
||||
router.use(subdomain('discovery.olv', discovery));
|
||||
logger.info('[MIIVERSE] Creating \'api\' subdomain');
|
||||
router.use(subdomain('api.olv', api));
|
||||
router.use(subdomain('f57cd744', discovery));
|
||||
|
||||
|
||||
logger.info('[MIIVERSE] Importing middleware');
|
||||
@@ -29,6 +28,7 @@ discovery.use('/v1/endpoint', routes.DISCOVERY);
|
||||
api.use('/v1/posts', routes.POST);
|
||||
api.use('/v1/communities/', routes.COMMUNITY);
|
||||
api.use('/v1/people/', routes.PEOPLE);
|
||||
api.use('/v1/topics/', routes.TOPICS);
|
||||
discovery.use('/p01/', routes.POLICY);
|
||||
|
||||
module.exports = router;
|
||||
@@ -4,4 +4,5 @@ module.exports = {
|
||||
COMMUNITY: require('./communities'),
|
||||
PEOPLE: require('./people'),
|
||||
POLICY: require('./policyLists'),
|
||||
TOPICS: require('./topics')
|
||||
};
|
||||
@@ -3,53 +3,19 @@ var router = express.Router();
|
||||
const database = require('../../../database');
|
||||
const comPostGen = require('../../../util/CommunityPostGen');
|
||||
const processHeaders = require('../../../util/authentication');
|
||||
const xmlbuilder = require("xmlbuilder");
|
||||
const moment = require("moment");
|
||||
|
||||
/* GET post titles. */
|
||||
router.get('/', function (req, res) {
|
||||
database.connect().then(async e => {
|
||||
const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]);
|
||||
let community = await database.getCommunityByTitleID(paramPack.title_id);
|
||||
if (community != null) {
|
||||
let response = await comPostGen.Communities(community);
|
||||
res.contentType("application/xml");
|
||||
res.send(response);
|
||||
} else {
|
||||
res.status(404);
|
||||
res.send();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/0/posts', function (req, res) {
|
||||
database.connect().then(async e => {
|
||||
/* Parse out parameters from URL and headers */
|
||||
const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]);
|
||||
//"[0:1]=1407375153523200"
|
||||
let community = await database.getCommunityByTitleID(paramPack.title_id);
|
||||
if(community != null)
|
||||
{
|
||||
let posts;
|
||||
if(req.query.search_key)
|
||||
posts = await database.getPostsByCommunityKey(community, parseInt(req.query.limit), req.query.search_key);
|
||||
else
|
||||
posts = await database.getPostsByCommunity(community, parseInt(req.query.limit));
|
||||
|
||||
/* Build formatted response and send it off. */
|
||||
let response;
|
||||
if(req.query.with_mii === 1)
|
||||
response = await comPostGen.PostsResponseWithMii(posts, community);
|
||||
else
|
||||
response = await comPostGen.PostsResponse(posts, community);
|
||||
res.contentType("application/xml");
|
||||
res.send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(404);
|
||||
res.send();
|
||||
}
|
||||
|
||||
let communities = await database.getCommunities(10);
|
||||
if(communities === null)
|
||||
return res.sendStatus(404);
|
||||
let response = await comPostGen.topics(communities);
|
||||
res.contentType("application/xml");
|
||||
res.send(response);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const xmlbuilder = require("xmlbuilder");
|
||||
const moment = require("moment");
|
||||
const database = require('../database');
|
||||
|
||||
class CommunityPostGen {
|
||||
/* TODO lots of stubs and constants in here */
|
||||
@@ -188,6 +189,71 @@ class CommunityPostGen {
|
||||
.up();
|
||||
return xml.end({ pretty: true, allowEmpty: true });
|
||||
}
|
||||
|
||||
static async topics(communities) {
|
||||
const expirationDate = moment().add(1, 'days');
|
||||
let xml = xmlbuilder.create("result")
|
||||
.e("has_error", "0").up()
|
||||
.e("version", "1").up()
|
||||
.e("request_name", "topics").up()
|
||||
.e("expire", expirationDate.format('YYYY-MM-DD HH:MM:SS')).up()
|
||||
.e("topics").up();
|
||||
for (const community of communities) {
|
||||
let posts = await database.getPostsByCommunity(community, 30);
|
||||
console.log(posts.length);
|
||||
xml = xml.e('topic')
|
||||
.e('empathy_count', community.empathy_count).up()
|
||||
.e('has_shop_page', community.has_shop_page).up()
|
||||
.e('icon', community.icon).up()
|
||||
.e('title_ids');
|
||||
community.title_ids.forEach(function (title_id) {
|
||||
xml = xml.e('title_id', title_id).up()
|
||||
})
|
||||
xml = xml.up()
|
||||
.e('title_id', community.title_ids[0]).up()
|
||||
.e('community_id', community.community_id).up()
|
||||
.e('is_recommended', community.is_recommended).up()
|
||||
.e('name', community.name).up()
|
||||
.e("people");
|
||||
for (const post of posts) {
|
||||
xml = xml.e("person")
|
||||
.e("posts")
|
||||
.e("post")
|
||||
.e("body", post.body).up()
|
||||
.e("community_id", community.community_id).up()
|
||||
.e("country_id", post.country_id).up()
|
||||
.e("created_at", moment(post.created_at).format('YYYY-MM-DD HH:MM:SS')).up()
|
||||
.e("feeling_id", post.feeling_id).up()
|
||||
.e("id", post.id).up()
|
||||
.e("is_autopost", post.is_autopost).up()
|
||||
.e("is_community_private_autopost", post.is_community_private_autopost).up()
|
||||
.e("is_spoiler", post.is_spoiler).up()
|
||||
.e("is_app_jumpable", post.is_app_jumpable).up()
|
||||
.e("empathy_count", post.empathy_count).up()
|
||||
.e("language_id", post.language_id).up()
|
||||
.e("mii", post.mii).up()
|
||||
.e("mii_face_url", "https://s3.amazonaws.com/olv-public/pap/WVW69koebmETvBVqm1").up();
|
||||
xml = xml.e("number", "0").up();
|
||||
if (post.painting) {
|
||||
xml = xml.e("painting")
|
||||
.e("format", "tga").up()
|
||||
.e("content", post.painting).up()
|
||||
.e("size", post.painting.length).up()
|
||||
.e("url", "https://s3.amazonaws.com/olv-public/pap/WVW69koebmETvBVqm1").up()
|
||||
.up();
|
||||
}
|
||||
xml = xml.e("pid", post.pid).up()
|
||||
.e("platform_id", post.platform_id).up()
|
||||
.e("region_id", post.region_id).up()
|
||||
.e("reply_count", post.reply_count).up()
|
||||
.e("screen_name", post.screen_name).up()
|
||||
.e("title_id", post.title_id).up()
|
||||
.up().up().up();
|
||||
}
|
||||
xml = xml.up().up()
|
||||
}
|
||||
return xml.end({ pretty: true, allowEmpty: true });
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof module !== "undefined") {
|
||||
|
||||
Reference in New Issue
Block a user