ignore token for WWP

This commit is contained in:
Jonathan Barrow
2023-10-03 13:34:13 -04:00
parent 2c477ec919
commit 88633eeb4c
2 changed files with 34 additions and 26 deletions

View File

@@ -29,6 +29,11 @@ async function auth(request: express.Request, response: express.Response, next:
return next();
}
// * Just don't care about the token here
if (request.path === '/v1/topics') {
return next();
}
let encryptedToken = getValueFromHeaders(request.headers, 'x-nintendo-servicetoken');
if (!encryptedToken) {
encryptedToken = getValueFromHeaders(request.headers, 'olive service token');

View File

@@ -1,14 +1,10 @@
import express from 'express';
import moment from 'moment';
import xmlbuilder from 'xmlbuilder';
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
import { getUserAccountData } from '@/util';
import Cache from '@/cache';
import { getEndpoint } from '@/database';
import { Post } from '@/models/post';
import { Community } from '@/models/community';
import { IPost } from '@/types/mongoose/post';
import { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
import { HydratedCommunityDocument } from '@/types/mongoose/community';
import { WWPResult, WWPTopic } from '@/types/miiverse/wara-wara-plaza';
@@ -20,28 +16,35 @@ const WARA_WARA_PLAZA_CACHE = new Cache<WWPResult>(ONE_HOUR);
router.get('/', async function (request: express.Request, response: express.Response): Promise<void> {
response.type('application/xml');
let user: GetUserDataResponse;
try {
user = await getUserAccountData(request.pid);
} catch (error) {
// TODO - Log this error
response.sendStatus(403);
return;
}
let discovery: HydratedEndpointDocument | null;
if (user) {
discovery = await getEndpoint(user.serverAccessLevel);
} else {
discovery = await getEndpoint('prod');
}
if (!discovery || !discovery.topics) {
response.sendStatus(404);
return;
}
// * Commented out for now because we just don't
// * need this data here. WWP does not use the
// * current users data atm. Also some users have
// * BOSS tasks with outdated tokens, which aren't
// * usable and thus break this request. This is
// * done as a quick/hacky fix around that
// TODO - Re-enable this and filter out the current users posts
//let user: GetUserDataResponse;
//
//try {
// user = await getUserAccountData(request.pid);
//} catch (error) {
// // TODO - Log this error
// response.sendStatus(403);
// return;
//}
//
//let discovery: HydratedEndpointDocument | null;
//
//if (user) {
// discovery = await getEndpoint(user.serverAccessLevel);
//} else {
// discovery = await getEndpoint('prod');
//}
//
//if (!discovery || !discovery.topics) {
// response.sendStatus(404);
// return;
//}
if (!WARA_WARA_PLAZA_CACHE.valid()) {
const communities = await calculateMostPopularCommunities(24, 10);