mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-08-20 07:34:06 -05:00
fixed error handling with invalid user tokens
This commit is contained in:
@@ -7,36 +7,44 @@ var router = express.Router();
|
||||
/* GET discovery server. */
|
||||
router.get('/', function (req, res) {
|
||||
database.connect().then(async e => {
|
||||
const discovery = await database.getDiscoveryHosts();
|
||||
try
|
||||
{
|
||||
let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]);
|
||||
let usrObj;
|
||||
usrObj = await util.data.processUser(pid);
|
||||
switch (usrObj.account_status) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
res.set("Content-Type", "application/xml");
|
||||
res.statusCode = 400;
|
||||
response = {
|
||||
result: {
|
||||
has_error: 1,
|
||||
version: 1,
|
||||
code: 400,
|
||||
error_code: 7,
|
||||
message: "POSTING_FROM_NNID"
|
||||
}
|
||||
};
|
||||
res.send("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xml(response));
|
||||
if(usrObj == null)
|
||||
{
|
||||
throw new Error('The User token was not valid');
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (usrObj.account_status) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
res.set("Content-Type", "application/xml");
|
||||
res.statusCode = 400;
|
||||
response = {
|
||||
result: {
|
||||
has_error: 1,
|
||||
version: 1,
|
||||
code: 400,
|
||||
error_code: 7,
|
||||
message: "POSTING_FROM_NNID"
|
||||
}
|
||||
};
|
||||
res.send("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xml(response));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
console.error(e);
|
||||
}
|
||||
const discovery = await database.getDiscoveryHosts();
|
||||
switch(discovery.has_error)
|
||||
{
|
||||
case 0 :
|
||||
|
||||
@@ -17,52 +17,59 @@ router.post('/', upload.none(), async function (req, res, next) {
|
||||
let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]);
|
||||
let usrObj;
|
||||
usrObj = await util.data.processUser(pid);
|
||||
const creationDate = moment().format('YYYY-MM-DD HH:MM:SS');
|
||||
let appData = "";
|
||||
if (req.body.app_data) {
|
||||
appData = req.body.app_data.replace(/\0/g, "").trim();
|
||||
if(usrObj == null)
|
||||
{
|
||||
throw new Error('The User token was not valid');
|
||||
}
|
||||
let painting = "";
|
||||
if (req.body.painting) {
|
||||
painting = req.body.painting.replace(/\0/g, "").trim();
|
||||
else
|
||||
{
|
||||
const creationDate = moment().format('YYYY-MM-DD HH:MM:SS');
|
||||
let appData = "";
|
||||
if (req.body.app_data) {
|
||||
appData = req.body.app_data.replace(/\0/g, "").trim();
|
||||
}
|
||||
let painting = "";
|
||||
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();
|
||||
}
|
||||
const document = {
|
||||
title_id: paramPackData.title_id,
|
||||
screen_name: usrObj.user_id,
|
||||
body: req.body.body,
|
||||
app_data: appData,
|
||||
painting: painting,
|
||||
painting_uri: paintingURI,
|
||||
screenshot: screenshot,
|
||||
url: req.body.url,
|
||||
search_key: req.body.search_key,
|
||||
topic_tag: req.body.topic_tag,
|
||||
community_id: req.body.community_id,
|
||||
country_id: paramPackData.country_id,
|
||||
created_at: creationDate,
|
||||
feeling_id: req.body.feeling_id,
|
||||
id: snowflake.nextId(),
|
||||
is_autopost: req.body.is_autopost,
|
||||
is_spoiler: req.body.is_spoiler,
|
||||
is_app_jumpable: req.body.is_app_jumpable,
|
||||
language_id: req.body.language_id,
|
||||
mii: usrObj.mii,
|
||||
mii_face_url: "http://mii-images.account.pretendo.cc/",
|
||||
pid: pid,
|
||||
platform_id: paramPackData.platform_id,
|
||||
region_id: paramPackData.region_id,
|
||||
};
|
||||
const newPost = new POST(document);
|
||||
newPost.save();
|
||||
res.sendStatus(200);
|
||||
}
|
||||
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();
|
||||
}
|
||||
const document = {
|
||||
title_id: paramPackData.title_id,
|
||||
screen_name: usrObj.user_id,
|
||||
body: req.body.body,
|
||||
app_data: appData,
|
||||
painting: painting,
|
||||
painting_uri: paintingURI,
|
||||
screenshot: screenshot,
|
||||
url: req.body.url,
|
||||
search_key: req.body.search_key,
|
||||
topic_tag: req.body.topic_tag,
|
||||
community_id: req.body.community_id,
|
||||
country_id: paramPackData.country_id,
|
||||
created_at: creationDate,
|
||||
feeling_id: req.body.feeling_id,
|
||||
id: snowflake.nextId(),
|
||||
is_autopost: req.body.is_autopost,
|
||||
is_spoiler: req.body.is_spoiler,
|
||||
is_app_jumpable: req.body.is_app_jumpable,
|
||||
language_id: req.body.language_id,
|
||||
mii: usrObj.mii,
|
||||
mii_face_url: "http://mii-images.account.pretendo.cc/",
|
||||
pid: pid,
|
||||
platform_id: paramPackData.platform_id,
|
||||
region_id: paramPackData.region_id,
|
||||
};
|
||||
const newPost = new POST(document);
|
||||
newPost.save();
|
||||
res.sendStatus(200);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
|
||||
@@ -73,7 +73,8 @@ let methods = {
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.error("The token was incorrect")
|
||||
console.error("The token was incorrect");
|
||||
return null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user