mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-08-19 23:24:05 -05:00
added support for web terminal again, tweaks to /v1/posts
This commit is contained in:
@@ -26,6 +26,10 @@ router.post('/', upload.none(), async function (req, res, next) {
|
||||
if (req.body.painting) {
|
||||
painting = req.body.painting.replace(/\0/g, "").trim();
|
||||
}
|
||||
let paintingURI = "";
|
||||
if (req.body.painting) {
|
||||
paintingURI = await util.data.processPainting(painting);
|
||||
}
|
||||
let screenshot = "";
|
||||
if (req.body.screenshot) {
|
||||
screenshot = req.body.screenshot.replace(/\0/g, "").trim();
|
||||
@@ -36,6 +40,7 @@ router.post('/', upload.none(), async function (req, res, next) {
|
||||
body: req.body.body,
|
||||
app_data: appData,
|
||||
painting: painting,
|
||||
painting_uri: paintingURI,
|
||||
screenshot: screenshot,
|
||||
url: req.body.url,
|
||||
search_key: req.body.search_key,
|
||||
@@ -57,6 +62,7 @@ router.post('/', upload.none(), async function (req, res, next) {
|
||||
};
|
||||
const newPost = new POST(document);
|
||||
newPost.save();
|
||||
console.log('post completed');
|
||||
res.sendStatus(200);
|
||||
}
|
||||
catch (e)
|
||||
|
||||
@@ -11,7 +11,6 @@ router.get('/list', function (req, res) {
|
||||
//const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]);
|
||||
//"[0:1]=1407375153523200"
|
||||
let community = await database.getCommunities(5);
|
||||
console.log(community.length);
|
||||
let body = '<form action="">\n' +
|
||||
' <select id="communities" onchange="getPosts(this.value)">' +
|
||||
' <option value="">Select a community:</option>\n';
|
||||
|
||||
@@ -8,9 +8,7 @@ router.get('/', function (req, res) {
|
||||
//const paramPack = processHeaders.data.decodeParamPack(req.headers["x-nintendo-parampack"]);
|
||||
//"[0:1]=1407375153523200"
|
||||
let community = await database.getCommunityByID(req.query.community_id);
|
||||
console.log(community);
|
||||
let posts = await database.getPostsByCommunity(community, parseInt(req.query.limit));
|
||||
console.log(posts.length);
|
||||
let body = '<table id="posts"><tbody><tr>' +
|
||||
'<th onClick="sortTable(0)">Screen Name</th>' +
|
||||
'<th onClick="sortTable(1)">Body Text</th>' +
|
||||
|
||||
@@ -7,6 +7,9 @@ const xmlParser = require('xml2json');
|
||||
const request = require("request");
|
||||
const moment = require('moment');
|
||||
const { USER } = require('../models/user');
|
||||
let TGA = require('tga');
|
||||
let pako = require('pako');
|
||||
let PNG = require('pngjs').PNG;
|
||||
|
||||
let methods = {
|
||||
processUser: function(pid) {
|
||||
@@ -59,11 +62,8 @@ let methods = {
|
||||
return out;
|
||||
},
|
||||
processServiceToken: function(token) {
|
||||
console.log(token);
|
||||
let B64token = Buffer.from(token, 'base64');
|
||||
console.log(B64token);
|
||||
let decryptedToken = this.decryptToken(B64token);
|
||||
console.log(decryptedToken);
|
||||
return decryptedToken.readUInt32LE(0x2);
|
||||
|
||||
},
|
||||
@@ -113,18 +113,35 @@ let methods = {
|
||||
|
||||
let decryptedBody = decipher.update(encryptedBody);
|
||||
decryptedBody = Buffer.concat([decryptedBody, decipher.final()]);
|
||||
console.log("secret: " + cryptoOptions.hmac_secret);
|
||||
const hmac = crypto.createHmac('sha1', cryptoOptions.hmac_secret).update(decryptedBody);
|
||||
|
||||
const calculatedSignature = hmac.digest();
|
||||
console.log(calculatedSignature);
|
||||
console.log(signature);
|
||||
if (!calculatedSignature.equals(signature)) {
|
||||
console.log('Token signature did not match');
|
||||
return null;
|
||||
}
|
||||
|
||||
return decryptedBody;
|
||||
}
|
||||
},
|
||||
processPainting: function (painting) {
|
||||
let paintingBuffer = Buffer.from(painting, 'base64');
|
||||
let output = '';
|
||||
try
|
||||
{
|
||||
output = pako.inflate(paintingBuffer);
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
console.log(err);
|
||||
}
|
||||
let tga = new TGA(Buffer.from(output));
|
||||
let png = new PNG({
|
||||
width: tga.width,
|
||||
height: tga.height
|
||||
});
|
||||
png.data = tga.pixels;
|
||||
let pngBuffer = PNG.sync.write(png);
|
||||
return `data:image/png;base64,${pngBuffer.toString('base64')}`;
|
||||
},
|
||||
};
|
||||
exports.data = methods;
|
||||
Reference in New Issue
Block a user