mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-07-05 01:51:05 -05:00
added more functionality to the filler web interface
This commit is contained in:
parent
1905b91d98
commit
a3bbf8ee29
6
src/consts.json
Normal file
6
src/consts.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"3DS_Platform_Tag": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAYCAMAAAAVmYlOAAAAYFBMVEXeAADeAADeAADeAADeAADeAADeAADeAADeAADeAADeAADeAADeAADeAADeAAAAAAD////iP0XrjI/76en99PTzt7ngIyrnam7um53qfH/eAADlVlvwqaz0xMb30dL53d79/Q8IAAAAEHRSTlP40fRty2/589AHbs8bBscAkjyqfwAAAXVJREFUeAG91ofuqyAAhXG6dz1sOa73f8tbIP7JzbKD+MvoUPncKprmcX2euILT8/poGtHcb1zN7d6Ix40rOl/EjqvaiSff4PoJ0NYzajMl56nS6ji14xue4shlnUGm+IKZdYx8mbpMCL5BA4P3FoBMQd22wwRgikVnAFumLnkn6IGBLxYIKTimf3X+EoA+7WkYXylI2co8JFQJpk3z6d/ANFmySrCYgK4ESQVYMqRdm1QMSu/VlPdsCTpgyhtqbKgcbBH1LMHIACQ7DcSmrB+E+j84AozUVKZWCSZOmXKWZoD5O600gFD5pOlSKgfL75kFhspBapgSTImWdDbMp5CuFOyNLkOWoAKMIw20K+dsleAAWJIu7bQ52FkAbd7OSX6wS4/v3bu1HQzmC3/Wpy2bAIyjBuC56PTW46nTSExgCWL0TNyIxKi3Hk9XviO0L8Ex8pkrU7s4VTm+4SouZ65oc1n3Jep8b+Jr4mG/5Qq2+8Ojaf4B1loD7JWMRIAAAAAASUVORK5CYII=",
|
||||
"Wii_U_Platform_Tag": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAYCAMAAAAVmYlOAAAAYFBMVEUAl84Al84Al84Al84Al84Al84Al84Al84Al84Al84Al84Al84Al84Al84Al84AAAD///8Al87R5/NottyazOY7p9QZn9Ho8/i22e16vd/0+fxTr9jc7PaKxeKo0+nD4O8ehbUvAAAAEHRSTlP40fRty2/589AHbs8bBscAkjyqfwAAAUZJREFUeAG9lgWCwjAURIN7MxOv3/+Wm/3ri0v7gM6PPqwFpfVhW6w4Aqtie9Ba6f2Oo7Hba3XYcUTWGzXjqMxUwYtY5ywzzjlPyZZe+qz0fPUJ0nWZQi2vCIEuRw3AfTWt1A6wFABDQbouoxQvE4AmRwvIrg4onxJS8QoNQLIDUOXsAc9grSe9tWEIYZJNDDI1GRF5xGuFLeBIIAItA5A48FvqgV4UQJIcWsgKkQ6oGzSSgwt7ICRUTDlzzcGFDigjDNucFczwQgt0gGMNpJzDCwlANqqQKU8KI4XuNUKDTPjJI2EE/FcRXiDsADQUAyKPhFI1IWcCDK+hlrxGCSCJR/JYGCJQGfN+rHmFlSp4jQARfOWxkN5AiFd9LNSWV7HWhl95dPHO1C5T8jpbtVlzRCabcf9ErfdaaX1YzKccgel8cdD6DVFutGn/B7MbAAAAAElFTkSuQmCC",
|
||||
"Both_Platform_Tag": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAYCAMAAAAVmYlOAAABWVBMVEXeAADeAADeAAAAl87eAADeAADeAADeAAAAl87eAADeAAAAl84Al87eAADeAAAAl87eAAAAl84Al84Al84Al84Al84Al84Al87eAAAAl87eAAAAAAD///+azOYAl87lVlv99PSKxeLnam7gIyr30dJottzum53qfH/zt7neAADrjI/R5/Pwqaz53d70xMa22e2o0+lTr9jiP0U7p9Tc7PbD4O/76en0+fwZn9Ho8/j//v7fAAB6vd8Amc8AndD1rbJkwuPtcXmN0er++fn509bvg4szsdr0+v3gAQDrXGah2e3ym6H98fLlMDzlMz02sdrd8fl6yub3wMTiGCTqWmRMud604fB4yeXb8Pn85eb8/v7vhY0AotP98PGj2u761dhhweKL0enH6fQZqdb++vrp9vruc3vgDBT1r7T1+/33wsbiGyfq9vvoSFJKuN7J6vUcqtbgCxLymJ7gw+6QAAAAHHRSTlPL8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8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAECSURBVChTbZI9DoJAEIUfnkEbEyw8gr2oB4CEA8kh7C2MUStjAp2NLth4AivttFDPIL4dNutCfGHJ7MzHZH5A6eiSJHvf3wJ8aFymUxMQeTwAHlmmosgD+nHcnkzoeR8Ot93uA4zTtBuG9Ois9zRdAsfBQD6uqQiCBUCAtkbXwvH9Op0EqIn0SjKC9W3EIjcHnkoJUBMBYrr8cxxXrmee/6UJ7Hs93ex1NjM+S+e5uYsIEGvp1hx1hsNQqSwIXkVhXFZuAVaswc1tCrBtNVRVUs3EtEWLs+BEBKiJnJ0jr/pwwpzzX5oct1Ot4LfYYxSxx8ZiGRu5i7Vq/i5JYgJUWX4BvHp+Bl51PbYAAAAASUVORK5CYII="
|
||||
}
|
||||
|
|
@ -74,6 +74,14 @@ async function getPostByID(postID) {
|
|||
});
|
||||
}
|
||||
|
||||
async function getPostsByUserID(userID) {
|
||||
verifyConnected();
|
||||
|
||||
return POST.find({
|
||||
pid: userID
|
||||
});
|
||||
}
|
||||
|
||||
async function getPostsByCommunity(community, numberOfPosts) {
|
||||
verifyConnected();
|
||||
return POST.find({
|
||||
|
|
@ -119,7 +127,7 @@ module.exports = {
|
|||
getDiscoveryHosts,
|
||||
getPostsByCommunity,
|
||||
getPostsByCommunityKey,
|
||||
getPostsByUserID,
|
||||
getPostByID,
|
||||
getUserByPID,
|
||||
getServerConfig
|
||||
};
|
||||
|
|
@ -28,6 +28,9 @@ const CommunitySchema = new Schema({
|
|||
default: 0
|
||||
},
|
||||
name: String,
|
||||
browser_icon: String,
|
||||
browser_header: String,
|
||||
description: String,
|
||||
});
|
||||
|
||||
CommunitySchema.methods.upEmpathy = async function() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ router.use(subdomain('portal.olv', api));
|
|||
api.use('/', routes.PORTAL);
|
||||
api.use('/titles/show', routes.PORTAL);
|
||||
api.use('/v1/communities/', routes.COMMUNITY);
|
||||
api.use('/v1/post/', routes.POST);
|
||||
api.use('/v1/posts/', routes.POST);
|
||||
api.use('/posts/', routes.POST);
|
||||
api.use('/users/', routes.USERS);
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const database = require('../../../database');
|
||||
var multer = require('multer');
|
||||
const snowflake = require('node-snowflake').Snowflake;
|
||||
var upload = multer();
|
||||
const { COMMUNITY } = require('../../../models/communities');
|
||||
const comPostGen = require('../../../util/CommunityPostGen');
|
||||
const processHeaders = require('../../../util/authentication');
|
||||
|
||||
|
|
@ -25,5 +29,25 @@ router.get('/list', function (req, res) {
|
|||
|
||||
});
|
||||
});
|
||||
router.post('/new', upload.none(), async function (req, res, next) {
|
||||
const document = {
|
||||
empathy_count: 0,
|
||||
id: snowflake.nextId(),
|
||||
has_shop_page: req.body.has_shop_page,
|
||||
icon: req.body.icon,
|
||||
title_ids: req.body.title_ids,
|
||||
title_id: req.body.title_ids,
|
||||
community_id: snowflake.nextId(),
|
||||
is_recommended: req.body.is_recommended,
|
||||
name: req.body.name,
|
||||
browser_icon: req.body.browser_icon[0],
|
||||
browser_header: req.body.browser_header,
|
||||
description: req.body.description,
|
||||
};
|
||||
const newCommunity = new COMMUNITY(document);
|
||||
newCommunity.save();
|
||||
res.sendStatus(200)
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = {
|
||||
//DISCOVERY: require('./discovery'),
|
||||
USERS: require('./users'),
|
||||
POST: require('./post'),
|
||||
COMMUNITY: require('./communities'),
|
||||
PORTAL: require('./portal'),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ router.get('/', function (req, res) {
|
|||
'<div id="Posts"></div>\n' +
|
||||
'\n' +
|
||||
'<script>\n' +
|
||||
'if (typeof wiiuBrowser !== \'undefined\' && typeof wiiuBrowser.endStartUp !== \'undefined\') {\n' +
|
||||
'wiiuBrowser.endStartUp();\n' +
|
||||
'}\n' +
|
||||
' function getCommunities() {\n' +
|
||||
' var xhttp;\n' +
|
||||
' xhttp = new XMLHttpRequest();\n' +
|
||||
|
|
@ -55,7 +58,7 @@ router.get('/', function (req, res) {
|
|||
' document.getElementById("Posts").innerHTML = this.responseText;\n' +
|
||||
' }\n' +
|
||||
' };\n' +
|
||||
' xhttp.open("GET", "/v1/post?community_id=" + str + "&limit=100", true);\n' +
|
||||
' xhttp.open("GET", "/v1/posts?community_id=" + str + "&limit=100", true);\n' +
|
||||
' xhttp.send();\n' +
|
||||
' }\n' +
|
||||
'getCommunities()' +
|
||||
|
|
@ -66,4 +69,56 @@ router.get('/', function (req, res) {
|
|||
)
|
||||
});
|
||||
|
||||
router.get('/admin/communities/new', function (req, res) {
|
||||
res.send(
|
||||
'<!DOCTYPE html>\n' +
|
||||
'<html>\n' +
|
||||
'<body>\n' +
|
||||
'\n' +
|
||||
'<h2>New Community Form</h2>\n' +
|
||||
'\n' +
|
||||
'<p>Fill out all the information below. Title ID\'s must be in the decimal value form, not the hex form</p>\n' +
|
||||
'\n' +
|
||||
'<form action="/v1/communities/new" target="_blank" method="post">\n' +
|
||||
' <label for="name">Community Name:</label><br>\n' +
|
||||
' <input type="text" id="name" name="name"><br>\n' +
|
||||
' \n' +
|
||||
' <label for="description">Description:</label><br>\n' +
|
||||
' <input type="text" id="description" name="description"><br>\n' +
|
||||
' \n' +
|
||||
' <label for="title_ids">USA Title ID:</label><br>\n' +
|
||||
' <input type="text" id="title_ids" name="title_ids"><br>\n' +
|
||||
' \n' +
|
||||
' <label for="title_ids">EUR Title ID:</label><br>\n' +
|
||||
' <input type="text" id="title_ids" name="title_ids"><br>\n' +
|
||||
' \n' +
|
||||
' <label for="title_ids">JPN Title ID:</label><br>\n' +
|
||||
' <input type="text" id="title_ids" name="title_ids"><br>\n' +
|
||||
' \n' +
|
||||
' <label for="icon">System Icon (B64 TGA):</label><br>\n' +
|
||||
' <input type="text" id="icon" name="icon"><br>\n' +
|
||||
' \n' +
|
||||
' <label for="browser_icon">Browser Icon URI:</label><br>\n' +
|
||||
' <input type="text" id="browser_icon" name="browser_icon"><br>\n' +
|
||||
' \n' +
|
||||
' Is Recommended?\n' +
|
||||
' <input type="radio" id="isRecomended" name="is_recommended" value="1">\n' +
|
||||
' <label for="isRecomended">True</label>\n' +
|
||||
' <input type="radio" id="isNotRecomended" name="is_recommended" value="0">\n' +
|
||||
' <label for="isNotRecomended">False</label><br>\n' +
|
||||
' \n' +
|
||||
' Has Shop Page? \n' +
|
||||
' <input type="radio" id="hasShopPage" name="has_shop_page" value="1">\n' +
|
||||
' <label for="hasShopPage">True</label>\n' +
|
||||
' <input type="radio" id="noShopPage" name="has_shop_page" value="0">\n' +
|
||||
' <label for="noShopPage">False</label><br>\n' +
|
||||
' \n' +
|
||||
' <input type="submit" value="Submit">\n' +
|
||||
'</form>\n' +
|
||||
'\n' +
|
||||
'</body>\n' +
|
||||
'</html>\n'
|
||||
)
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const database = require('../../../database');
|
||||
const consts = require('../../../consts.json');
|
||||
|
||||
router.get('/', function (req, res) {
|
||||
database.connect().then(async e => {
|
||||
|
|
@ -10,17 +11,31 @@ router.get('/', function (req, res) {
|
|||
let community = await database.getCommunityByID(req.query.community_id);
|
||||
let posts = await database.getPostsByCommunity(community, parseInt(req.query.limit));
|
||||
let body = '<table id="posts"><tbody><tr>' +
|
||||
'<th onClick="sortTable(0)">Screen Name</th>' +
|
||||
'<th onClick="sortTable(1)">Body Text</th>' +
|
||||
'<th onClick="sortTable(2)">Yeah Count</th>' +
|
||||
'<th onClick="sortTable(3)">Painting</th>' +
|
||||
'<th>Icon</th>' +
|
||||
'<th>Description</th></tr>' +
|
||||
'<tr><td><img src="' + community.browser_icon + '" width=auto height=auto></td>' +
|
||||
'<td>' + community.description +'</td></tr>' +
|
||||
'<th>Screen Name</th>' +
|
||||
'<th>Body Text</th>' +
|
||||
'<th>Yeah Count</th>' +
|
||||
'<th">Painting</th>' +
|
||||
'</tr>';
|
||||
for(let i = 0; i < posts.length; i++)
|
||||
{
|
||||
body += '<tr id="' + posts[i]._id + '_row">' + '<td>' + posts[i].screen_name + '</td>' +
|
||||
'<td>' + posts[i].body + '</td>' +
|
||||
let paintingURI;
|
||||
if(posts[i].painting_uri === undefined)
|
||||
paintingURI = consts.No_Painting;
|
||||
else
|
||||
paintingURI = posts[i].painting_uri;
|
||||
let postBody;
|
||||
if(posts[i].body === undefined)
|
||||
postBody = 'No text';
|
||||
else
|
||||
postBody = posts[i].body;
|
||||
body += '<tr id="' + posts[i].id + '">' + '<td><a href="/users/' + posts[i].pid + '">' + posts[i].screen_name + '</a></td>' +
|
||||
'<td>' + '<a href="/posts/' + posts[i].id + '">' + postBody + '</a></td>' +
|
||||
'<td>' + posts[i].empathy_count + '</td>' +
|
||||
'<td><img src="' + posts[i].painting_uri + '" width=auto height=auto></td>';
|
||||
'<td><img src="' + paintingURI + '" width=auto height=auto></td>';
|
||||
}
|
||||
body += '</tbody>' + '</table>';
|
||||
res.send('<!DOCTYPE html>'
|
||||
|
|
@ -29,4 +44,44 @@ router.get('/', function (req, res) {
|
|||
});
|
||||
});
|
||||
|
||||
router.get('/*', function (req, res) {
|
||||
let post_id = req.originalUrl.replace('/posts/', '').trim();
|
||||
database.connect().then(async emp => {
|
||||
const post = await database.getPostByID(post_id);
|
||||
let post_body;
|
||||
if(post.body === undefined)
|
||||
post_body = 'No Text';
|
||||
else
|
||||
post_body = post.body;
|
||||
let post_painting_uri;
|
||||
if(post.painting_uri === undefined)
|
||||
post_painting_uri = consts.No_Painting;
|
||||
else
|
||||
post_painting_uri = post.painting_uri;
|
||||
let body =
|
||||
'<style>\n' +
|
||||
' table,th,td {\n' +
|
||||
' border : 1px solid black;\n' +
|
||||
' border-collapse: collapse;\n' +
|
||||
' }\n' +
|
||||
' th,td {\n' +
|
||||
' padding: 5px;\n' +
|
||||
' }\n' +
|
||||
'</style>\n' +
|
||||
'<table id="posts"><tbody><tr>' +
|
||||
'<th>Screen Name</th>' +
|
||||
'<th>Body Text</th>' +
|
||||
'<th>Yeah Count</th>' +
|
||||
'<th>Painting</th>' +
|
||||
'</tr>' +
|
||||
'<tr id="' + post.id + '">' + '<td><a href="/users/' + post.pid + '">' + post.screen_name + '</a></td>' +
|
||||
'<td>' + post_body + '</td>' +
|
||||
'<td>' + post.empathy_count + '</td>' +
|
||||
'<td><img src="' + post_painting_uri + '" width=auto height=auto></td>' +
|
||||
'</tbody>' + '</table>';
|
||||
res.send('<!DOCTYPE html>'
|
||||
+ '<html><head>' + '</head><body>' + body + '</body></html>');
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
58
src/services/web-api/routes/users.js
Normal file
58
src/services/web-api/routes/users.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const database = require('../../../database');
|
||||
const consts = require('../../../consts.json');
|
||||
|
||||
router.get('/*', function (req, res) {
|
||||
database.connect().then(async e => {
|
||||
let PID = req.originalUrl.replace('/users/', '').trim();
|
||||
let posts = await database.getPostsByUserID(PID);
|
||||
let userPosts = '';
|
||||
let totalEmpathy = 0;
|
||||
for(let i = 0; i < posts.length; i++)
|
||||
{
|
||||
totalEmpathy += posts[i].empathy_count;
|
||||
let paintingURI;
|
||||
if(posts[i].painting_uri === undefined)
|
||||
paintingURI = consts.No_Painting;
|
||||
else
|
||||
paintingURI = posts[i].painting_uri;
|
||||
let postBody;
|
||||
if(posts[i].body === undefined)
|
||||
postBody = 'No text';
|
||||
else
|
||||
postBody = posts[i].body;
|
||||
userPosts += '<tr id="' + posts[i].id + '">' + '<td><a href="/posts/' + posts[i].id + '">' + postBody + '</a></td>' +
|
||||
'<td>' + posts[i].empathy_count + '</td>' +
|
||||
'<td><img src="' + paintingURI + '" width=auto height=auto></td>';
|
||||
}
|
||||
let body =
|
||||
'<style>\n' +
|
||||
' table,th,td {\n' +
|
||||
' border : 1px solid black;\n' +
|
||||
' border-collapse: collapse;\n' +
|
||||
' }\n' +
|
||||
' th,td {\n' +
|
||||
' padding: 5px;\n' +
|
||||
' }\n' +
|
||||
'</style>\n' +
|
||||
'<table id="posts"><tbody><tr>' +
|
||||
'<tr>' +
|
||||
'<th>User Name</th>' +
|
||||
'<th>Total Yeah!</th>' +
|
||||
'</tr>\n<tr>' +
|
||||
'<td>' + posts[0].screen_name + '</td>' +
|
||||
'<td>' + totalEmpathy + '</td></tr>' +
|
||||
'<th>Body Text</th>' +
|
||||
'<th>Yeah Count</th>' +
|
||||
'<th>Painting</th>' +
|
||||
'</tr>';
|
||||
body += userPosts + '</tbody></table>';
|
||||
res.send('<!DOCTYPE html>'
|
||||
+ '<html><head>' + '</head><body>' + body + '</body></html>');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
Loading…
Reference in New Issue
Block a user