mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-03-21 17:24:38 -05:00
style: lint ALL the files
This commit is contained in:
parent
47d799b339
commit
5998e511ea
|
|
@ -24,4 +24,4 @@ export default class Cache<T> {
|
|||
get(): T | undefined {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import fs from 'fs-extra';
|
||||
import mongoose from 'mongoose';
|
||||
import dotenv from 'dotenv';
|
||||
import { LOG_INFO, LOG_WARN, LOG_ERROR } from '@/logger';
|
||||
import { Config } from '@/types/common/config';
|
||||
import type mongoose from 'mongoose';
|
||||
import type { Config } from '@/types/common/config';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ if (!config.cdn_url) {
|
|||
|
||||
try {
|
||||
new URL(config.cdn_url);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
LOG_ERROR('Invalid CDN URL, URL must be a valid URL with a protocol (http/https) and domain');
|
||||
process.exit(0);
|
||||
}
|
||||
|
|
@ -138,4 +138,4 @@ if (!config.grpc.account.api_key) {
|
|||
if (!config.aes_key) {
|
||||
LOG_ERROR('Token AES key is not set. Set the PN_MIIVERSE_API_CONFIG_AES_KEY environment variable to your AES-256-CBC key');
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ import { Endpoint } from '@/models/endpoint';
|
|||
import { Post } from '@/models/post';
|
||||
import { Settings } from '@/models/settings';
|
||||
import { config } from '@/config-manager';
|
||||
import { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import { HydratedPostDocument, IPost } from '@/types/mongoose/post';
|
||||
import { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
|
||||
import { HydratedSettingsDocument } from '@/types/mongoose/settings';
|
||||
import { HydratedContentDocument } from '@/types/mongoose/content';
|
||||
import { HydratedConversationDocument } from '@/types/mongoose/conversation';
|
||||
import type { HydratedConversationDocument } from '@/types/mongoose/conversation';
|
||||
import type { HydratedContentDocument } from '@/types/mongoose/content';
|
||||
import type { HydratedSettingsDocument } from '@/types/mongoose/settings';
|
||||
import type { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
|
||||
import type { HydratedPostDocument, IPost } from '@/types/mongoose/post';
|
||||
import type { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
|
||||
const { mongoose: mongooseConfig } = config;
|
||||
|
||||
|
|
@ -176,4 +176,4 @@ export async function getFriendMessages(pid: string, search_key: string[], limit
|
|||
parent: null,
|
||||
removed: false
|
||||
}).sort({ created_at: 1 }).limit(limit);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@ export function LOG_INFO(input: string): void {
|
|||
streams.info.write(`${input}\n`);
|
||||
|
||||
console.log(`${input}`.cyan.bold);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import express from 'express';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import moment from 'moment';
|
||||
import { z } from 'zod';
|
||||
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import { getEndpoint, getUserSettings } from '@/database';
|
||||
import { getUserAccountData, getValueFromHeaders, decodeParamPack, getPIDFromServiceToken } from '@/util';
|
||||
import { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
|
||||
import { getEndpoint, getUserSettings } from '@/database';
|
||||
import type express from 'express';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import type { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
|
||||
|
||||
const ParamPackSchema = z.object({
|
||||
title_id: z.string(),
|
||||
|
|
@ -112,7 +112,6 @@ async function auth(request: express.Request, response: express.Response, next:
|
|||
} else {
|
||||
return badAuth(response, 7, 'PNID_PERM_BAN');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return next();
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import express from 'express';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { getValueFromHeaders } from '@/util';
|
||||
import type express from 'express';
|
||||
|
||||
const VALID_CLIENT_ID_SECRET_PAIRS: { [key: string]: string } = {
|
||||
// * 'Key' is the client ID, 'Value' is the client secret
|
||||
'a2efa818a34fa16b8afbc8a74eba3eda': 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
|
||||
'daf6227853bcbdce3d75baee8332b': '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
|
||||
'ea25c66c26b403376b4c5ed94ab9cdea': 'd137be62cb6a2b831cad8c013b92fb55', // * Possibly 3DS exclusive?
|
||||
a2efa818a34fa16b8afbc8a74eba3eda: 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
|
||||
daf6227853bcbdce3d75baee8332b: '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
|
||||
ea25c66c26b403376b4c5ed94ab9cdea: 'd137be62cb6a2b831cad8c013b92fb55' // * Possibly 3DS exclusive?
|
||||
};
|
||||
|
||||
|
||||
function nintendoClientHeaderCheck(request: express.Request, response: express.Response, next: express.NextFunction): void {
|
||||
response.type('text/xml');
|
||||
response.set('Server', 'Nintendo 3DS (http)');
|
||||
|
|
@ -41,4 +40,4 @@ function nintendoClientHeaderCheck(request: express.Request, response: express.R
|
|||
return next();
|
||||
}
|
||||
|
||||
export default nintendoClientHeaderCheck;
|
||||
export default nintendoClientHeaderCheck;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { CommunityData } from '@/types/miiverse/community';
|
||||
import { ICommunity, ICommunityMethods, CommunityModel, ICommunityPermissions, HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import type { CommunityData } from '@/types/miiverse/community';
|
||||
import type { ICommunity, ICommunityMethods, CommunityModel, ICommunityPermissions, HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
|
||||
const PermissionsSchema = new Schema<ICommunityPermissions>({
|
||||
open: {
|
||||
|
|
@ -18,7 +18,7 @@ const PermissionsSchema = new Schema<ICommunityPermissions>({
|
|||
minimum_new_community_access_level: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
const CommunitySchema = new Schema<ICommunity, CommunityModel, ICommunityMethods>({
|
||||
|
|
@ -54,7 +54,7 @@ const CommunitySchema = new Schema<ICommunity, CommunityModel, ICommunityMethods
|
|||
owner: Number,
|
||||
created_at: {
|
||||
type: Date,
|
||||
default: new Date(),
|
||||
default: new Date()
|
||||
},
|
||||
empathy_count: {
|
||||
type: Number,
|
||||
|
|
@ -120,4 +120,4 @@ CommunitySchema.method<HydratedCommunityDocument>('json', function json(): Commu
|
|||
};
|
||||
});
|
||||
|
||||
export const Community = model<ICommunity, CommunityModel>('Community', CommunitySchema);
|
||||
export const Community = model<ICommunity, CommunityModel>('Community', CommunitySchema);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { IContent, ContentModel } from '@/types/mongoose/content';
|
||||
import type { IContent, ContentModel } from '@/types/mongoose/content';
|
||||
|
||||
const ContentSchema = new Schema<IContent, ContentModel>({
|
||||
pid: Number,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { Snowflake } from 'node-snowflake';
|
||||
import { IConversation, IConversationMethods, ConversationModel, HydratedConversationDocument } from '@/types/mongoose/conversation';
|
||||
import type { IConversation, IConversationMethods, ConversationModel, HydratedConversationDocument } from '@/types/mongoose/conversation';
|
||||
|
||||
const ConversationSchema = new Schema<IConversation, ConversationModel, IConversationMethods>({
|
||||
id: {
|
||||
|
|
@ -9,11 +9,11 @@ const ConversationSchema = new Schema<IConversation, ConversationModel, IConvers
|
|||
},
|
||||
created_at: {
|
||||
type: Date,
|
||||
default: new Date(),
|
||||
default: new Date()
|
||||
},
|
||||
last_updated: {
|
||||
type: Date,
|
||||
default: new Date(),
|
||||
default: new Date()
|
||||
},
|
||||
message_preview: {
|
||||
type: String,
|
||||
|
|
@ -42,4 +42,4 @@ ConversationSchema.method<HydratedConversationDocument>('newMessage', async func
|
|||
await this.save();
|
||||
});
|
||||
|
||||
export const Conversation = model<IConversation, ConversationModel>('Conversation', ConversationSchema);
|
||||
export const Conversation = model<IConversation, ConversationModel>('Conversation', ConversationSchema);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { IEndpoint, EndpointModel } from '@/types/mongoose/endpoint';
|
||||
import type { IEndpoint, EndpointModel } from '@/types/mongoose/endpoint';
|
||||
|
||||
const endpointSchema = new Schema<IEndpoint, EndpointModel>({
|
||||
status: Number,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { INotification, NotificationModel } from '@/types/mongoose/notification';
|
||||
import type { INotification, NotificationModel } from '@/types/mongoose/notification';
|
||||
|
||||
const NotificationSchema = new Schema<INotification, NotificationModel>({
|
||||
pid: String,
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ import crypto from 'node:crypto';
|
|||
import moment from 'moment';
|
||||
import { Schema, model } from 'mongoose';
|
||||
import { INVALID_POST_BODY_REGEX } from '@/util';
|
||||
import { HydratedPostDocument, IPost, IPostMethods, PostModel } from '@/types/mongoose/post';
|
||||
import { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import { PostToJSONOptions } from '@/types/mongoose/post-to-json-options';
|
||||
import { PostData, PostPainting, PostScreenshot, PostTopicTag } from '@/types/miiverse/post';
|
||||
import type { HydratedPostDocument, IPost, IPostMethods, PostModel } from '@/types/mongoose/post';
|
||||
import type { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import type { PostToJSONOptions } from '@/types/mongoose/post-to-json-options';
|
||||
import type { PostData, PostPainting, PostScreenshot, PostTopicTag } from '@/types/miiverse/post';
|
||||
|
||||
const PostSchema = new Schema<IPost, PostModel, IPostMethods>({
|
||||
id: String,
|
||||
|
|
@ -88,7 +88,6 @@ const PostSchema = new Schema<IPost, PostModel, IPostMethods>({
|
|||
id: false // * Disables the .id() getter used by Mongoose in TypeScript. Needed to have our own .id field
|
||||
});
|
||||
|
||||
|
||||
PostSchema.method<HydratedPostDocument>('del', async function del(reason: string) {
|
||||
this.removed = true;
|
||||
this.removed_reason = reason;
|
||||
|
|
@ -178,7 +177,7 @@ PostSchema.method<HydratedPostDocument>('json', function json(options: PostToJSO
|
|||
screen_name: this.screen_name,
|
||||
screenshot: this.formatScreenshot(),
|
||||
topic_tag: undefined, // * Conditionally set later
|
||||
title_id: this.title_id,
|
||||
title_id: this.title_id
|
||||
};
|
||||
|
||||
if (options.app_data) {
|
||||
|
|
@ -206,7 +205,7 @@ PostSchema.method<HydratedPostDocument>('json', function json(options: PostToJSO
|
|||
return post;
|
||||
});
|
||||
|
||||
PostSchema.pre('save', async function(next) {
|
||||
PostSchema.pre('save', async function (next) {
|
||||
if (!this.id) {
|
||||
await this.generatePostUID(21);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { IReport, ReportModel } from '@/types/mongoose/report';
|
||||
import type { IReport, ReportModel } from '@/types/mongoose/report';
|
||||
|
||||
const ReportSchema = new Schema<IReport, ReportModel>({
|
||||
pid: String,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Schema, model } from 'mongoose';
|
||||
import { SettingsData } from '@/types/miiverse/settings';
|
||||
import { HydratedSettingsDocument, ISettings, ISettingsMethods, SettingsModel } from '@/types/mongoose/settings';
|
||||
import type { SettingsData } from '@/types/miiverse/settings';
|
||||
import type { HydratedSettingsDocument, ISettings, ISettingsMethods, SettingsModel } from '@/types/mongoose/settings';
|
||||
|
||||
const SettingsSchema = new Schema<ISettings, SettingsModel, ISettingsMethods>({
|
||||
pid: Number,
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
process.title = 'Pretendo - Miiverse';
|
||||
process.on('SIGTERM', () => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
import express from 'express';
|
||||
import morgan from 'morgan';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { connect as connectDatabase } from '@/database';
|
||||
import { LOG_INFO, LOG_SUCCESS } from '@/logger';
|
||||
import auth from '@/middleware/auth';
|
||||
|
||||
import discovery from '@/services/discovery';
|
||||
import api from '@/services/api';
|
||||
|
||||
import { config } from '@/config-manager';
|
||||
|
||||
process.title = 'Pretendo - Miiverse';
|
||||
process.on('SIGTERM', () => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
const { http: { port } } = config;
|
||||
const app = express();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import express from 'express';
|
||||
import subdomain from 'express-subdomain';
|
||||
import { LOG_INFO } from '@/logger';
|
||||
|
||||
import postsHandlers from '@/services/api/routes/posts';
|
||||
import friendMessagesHandlers from '@/services/api/routes/friend_messages';
|
||||
import communitiesHandlers from '@/services/api/routes/communities';
|
||||
|
|
@ -32,4 +31,4 @@ api.use('/v1/topics/', topicsHandlers);
|
|||
api.use('/v1/users/', usersHandlers);
|
||||
api.use('/v1/status/', statusHandlers);
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
|
|
|||
|
|
@ -2,23 +2,23 @@ import express from 'express';
|
|||
import xmlbuilder from 'xmlbuilder';
|
||||
import multer from 'multer';
|
||||
import { z } from 'zod';
|
||||
import { Post } from '@/models/post';
|
||||
import { Community } from '@/models/community';
|
||||
import { LOG_WARN } from '@/logger';
|
||||
import { getValueFromQueryString, getUserAccountData } from '@/util';
|
||||
import {
|
||||
getMostPopularCommunities,
|
||||
getNewCommunities,
|
||||
getCommunityByTitleID,
|
||||
getUserContent,
|
||||
getUserContent
|
||||
} from '@/database';
|
||||
import { getValueFromQueryString, getUserAccountData } from '@/util';
|
||||
import { LOG_WARN } from '@/logger';
|
||||
import { Community } from '@/models/community';
|
||||
import { Post } from '@/models/post';
|
||||
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import { SubCommunityQuery } from '@/types/mongoose/subcommunity-query';
|
||||
import { CommunityPostsQuery } from '@/types/mongoose/community-posts-query';
|
||||
import { HydratedPostDocument, IPost } from '@/types/mongoose/post';
|
||||
import { ParamPack } from '@/types/common/param-pack';
|
||||
import { CommunitiesResult, CommunityPostsResult } from '@/types/miiverse/community';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import type { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import type { SubCommunityQuery } from '@/types/mongoose/subcommunity-query';
|
||||
import type { CommunityPostsQuery } from '@/types/mongoose/community-posts-query';
|
||||
import type { HydratedPostDocument, IPost } from '@/types/mongoose/post';
|
||||
import type { ParamPack } from '@/types/common/param-pack';
|
||||
import type { CommunitiesResult, CommunityPostsResult } from '@/types/miiverse/community';
|
||||
|
||||
const createNewCommunitySchema = z.object({
|
||||
name: z.string(),
|
||||
|
|
@ -46,7 +46,6 @@ function respondCommunityNotFound(response: express.Response): void {
|
|||
}
|
||||
|
||||
async function commonGetSubCommunity(paramPack: ParamPack, communityID: string | undefined): Promise<HydratedCommunityDocument | null> {
|
||||
|
||||
const parentCommunity = await getCommunityByTitleID(paramPack.title_id);
|
||||
|
||||
if (!parentCommunity) {
|
||||
|
|
@ -191,7 +190,7 @@ router.get('/:communityID/posts', async function (request: express.Request, resp
|
|||
query.is_spoiler = 0;
|
||||
}
|
||||
|
||||
//TODO: There probably is a type for text and screenshots too, will have to investigate
|
||||
// TODO: There probably is a type for text and screenshots too, will have to investigate
|
||||
if (postType === 'memo') {
|
||||
query.painting = { $ne: null };
|
||||
}
|
||||
|
|
@ -272,8 +271,8 @@ router.post('/', multer().none(), async function (request: express.Request, resp
|
|||
let pnid: GetUserDataResponse;
|
||||
|
||||
try {
|
||||
pnid = await getUserAccountData(request.pid);
|
||||
} catch (error) {
|
||||
pnid = await getUserAccountData(request.pid);
|
||||
} catch (ignored) {
|
||||
// TODO - Log this error
|
||||
response.sendStatus(403);
|
||||
return;
|
||||
|
|
@ -455,7 +454,6 @@ router.post('/:community_id.unfavorite', multer().none(), async function (reques
|
|||
}));
|
||||
});
|
||||
|
||||
|
||||
router.post('/:community_id', multer().none(), async function (request: express.Request, response: express.Response): Promise<void> {
|
||||
response.type('application/xml');
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { Snowflake } from 'node-snowflake';
|
|||
import moment from 'moment';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { z } from 'zod';
|
||||
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import {
|
||||
getUserFriendPIDs,
|
||||
getUserAccountData,
|
||||
|
|
@ -17,8 +16,9 @@ import { getConversationByUsers, getUserSettings, getFriendMessages } from '@/da
|
|||
import { LOG_WARN } from '@/logger';
|
||||
import { Post } from '@/models/post';
|
||||
import { Conversation } from '@/models/conversation';
|
||||
import { FormattedMessage } from '@/types/common/formatted-message';
|
||||
import { config } from '@/config-manager';
|
||||
import type { FormattedMessage } from '@/types/common/formatted-message';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
|
||||
const sendMessageSchema = z.object({
|
||||
body: z.string().optional(),
|
||||
|
|
@ -28,7 +28,7 @@ const sendMessageSchema = z.object({
|
|||
feeling_id: z.string(),
|
||||
is_autopost: z.string(),
|
||||
number: z.string(),
|
||||
message_to_pid: z.string().transform(Number),
|
||||
message_to_pid: z.string().transform(Number)
|
||||
});
|
||||
|
||||
const router = express.Router();
|
||||
|
|
@ -62,7 +62,7 @@ router.post('/', upload.none(), async function (request: express.Request, respon
|
|||
|
||||
try {
|
||||
sender = await getUserAccountData(request.pid);
|
||||
} catch (error) {
|
||||
} catch (ignored) {
|
||||
LOG_WARN('[Messages] Cannot find sender');
|
||||
response.sendStatus(422);
|
||||
return;
|
||||
|
|
@ -79,7 +79,7 @@ router.post('/', upload.none(), async function (request: express.Request, respon
|
|||
|
||||
try {
|
||||
recipient = await getUserAccountData(recipientPID);
|
||||
} catch (error) {
|
||||
} catch (ignored) {
|
||||
// TODO - Log this error
|
||||
LOG_WARN('[Messages] Cannot find recipient');
|
||||
response.type('application/xml');
|
||||
|
|
@ -121,7 +121,7 @@ router.post('/', upload.none(), async function (request: express.Request, respon
|
|||
pid: recipient.pid,
|
||||
official: (recipient.accessLevel === 2 || recipient.accessLevel === 3),
|
||||
read: false
|
||||
},
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
|
@ -330,4 +330,4 @@ router.post('/:post_id/empathies', upload.none(), async function (_request: expr
|
|||
*/
|
||||
});
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import moment from 'moment';
|
|||
import { getUserContent, getFollowedUsers } from '@/database';
|
||||
import { getValueFromQueryString, getUserFriendPIDs } from '@/util';
|
||||
import { Post } from '@/models/post';
|
||||
import { CommunityPostsQuery } from '@/types/mongoose/community-posts-query';
|
||||
import { HydratedPostDocument, IPost } from '@/types/mongoose/post';
|
||||
import { PeopleFollowingResult, PeoplePostsResult } from '@/types/miiverse/people';
|
||||
import type { CommunityPostsQuery } from '@/types/mongoose/community-posts-query';
|
||||
import type { HydratedPostDocument, IPost } from '@/types/mongoose/post';
|
||||
import type { PeopleFollowingResult, PeoplePostsResult } from '@/types/miiverse/people';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
|
@ -68,9 +68,9 @@ router.get('/', async function (request: express.Request, response: express.Resp
|
|||
|
||||
posts = unhydratedPosts.map((post: IPost) => Post.hydrate(post));
|
||||
} else if (request.query.is_hot === '1') {
|
||||
posts = await Post.find(query).sort({ empathy_count: -1}).limit(limit);
|
||||
posts = await Post.find(query).sort({ empathy_count: -1 }).limit(limit);
|
||||
} else {
|
||||
posts = await Post.find(query).sort({ created_at: -1}).limit(limit);
|
||||
posts = await Post.find(query).sort({ created_at: -1 }).limit(limit);
|
||||
}
|
||||
|
||||
const result: PeoplePostsResult = {
|
||||
|
|
@ -148,4 +148,4 @@ router.get('/:pid/following', async function (request: express.Request, response
|
|||
}));
|
||||
});
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import express from 'express';
|
|||
import multer from 'multer';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { z } from 'zod';
|
||||
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import {
|
||||
getUserAccountData,
|
||||
processPainting,
|
||||
|
|
@ -22,9 +21,10 @@ import {
|
|||
import { LOG_WARN } from '@/logger';
|
||||
import { Post } from '@/models/post';
|
||||
import { Community } from '@/models/community';
|
||||
import { HydratedPostDocument } from '@/types/mongoose/post';
|
||||
import { PostRepliesResult } from '@/types/miiverse/post';
|
||||
import { config } from '@/config-manager';
|
||||
import type { PostRepliesResult } from '@/types/miiverse/post';
|
||||
import type { HydratedPostDocument } from '@/types/mongoose/post';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
|
||||
const newPostSchema = z.object({
|
||||
community_id: z.string().optional(),
|
||||
|
|
@ -220,7 +220,7 @@ async function newPost(request: express.Request, response: express.Response): Pr
|
|||
|
||||
try {
|
||||
user = await getUserAccountData(request.pid);
|
||||
} catch (error) {
|
||||
} catch (ignored) {
|
||||
// TODO - Log this error
|
||||
response.sendStatus(403);
|
||||
return;
|
||||
|
|
@ -429,4 +429,4 @@ async function newPost(request: express.Request, response: express.Response): Pr
|
|||
}).end({ pretty: true, allowEmpty: true }));
|
||||
}
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ import { getEndpoints } from '@/database';
|
|||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', function(_request: express.Request, response: express.Response): void {
|
||||
router.get('/', function (_request: express.Request, response: express.Response): void {
|
||||
response.send('Pong!');
|
||||
});
|
||||
|
||||
router.get('/database', async function(_request: express.Request, response: express.Response): Promise<void> {
|
||||
router.get('/database', async function (_request: express.Request, response: express.Response): Promise<void> {
|
||||
const endpoints = await getEndpoints();
|
||||
|
||||
if (endpoints && endpoints.length <= 0) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import xmlbuilder from 'xmlbuilder';
|
|||
import Cache from '@/cache';
|
||||
import { Post } from '@/models/post';
|
||||
import { Community } from '@/models/community';
|
||||
import { IPost } from '@/types/mongoose/post';
|
||||
import { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import { WWPResult, WWPTopic } from '@/types/miiverse/wara-wara-plaza';
|
||||
import type { IPost } from '@/types/mongoose/post';
|
||||
import type { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import type { WWPResult, WWPTopic } from '@/types/miiverse/wara-wara-plaza';
|
||||
|
||||
const router = express.Router();
|
||||
const ONE_HOUR = 60 * 60 * 1000;
|
||||
|
|
@ -23,28 +23,28 @@ router.get('/', async function (request: express.Request, response: express.Resp
|
|||
// * 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;
|
||||
// let user: GetUserDataResponse;
|
||||
//
|
||||
//try {
|
||||
// try {
|
||||
// user = await getUserAccountData(request.pid);
|
||||
//} catch (error) {
|
||||
// } catch (error) {
|
||||
// // TODO - Log this error
|
||||
// response.sendStatus(403);
|
||||
// return;
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//let discovery: HydratedEndpointDocument | null;
|
||||
// let discovery: HydratedEndpointDocument | null;
|
||||
//
|
||||
//if (user) {
|
||||
// if (user) {
|
||||
// discovery = await getEndpoint(user.serverAccessLevel);
|
||||
//} else {
|
||||
// } else {
|
||||
// discovery = await getEndpoint('prod');
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//if (!discovery || !discovery.topics) {
|
||||
// if (!discovery || !discovery.topics) {
|
||||
// response.sendStatus(404);
|
||||
// return;
|
||||
//}
|
||||
// }
|
||||
|
||||
if (!WARA_WARA_PLAZA_CACHE.valid()) {
|
||||
const communities = await calculateMostPopularCommunities(24, 10);
|
||||
|
|
@ -80,7 +80,7 @@ async function generateTopicsData(communities: HydratedCommunityDocument[]): Pro
|
|||
for (let i = 0; i < communities.length; i++) {
|
||||
const community = communities[i];
|
||||
|
||||
const empathies = await Post.aggregate<{ _id: null; total: number; }>([
|
||||
const empathies = await Post.aggregate<{ _id: null; total: number }>([
|
||||
{
|
||||
$match: {
|
||||
community_id: community.olive_community_id
|
||||
|
|
@ -109,10 +109,10 @@ async function generateTopicsData(communities: HydratedCommunityDocument[]): Pro
|
|||
is_recommended: community.is_recommended ? 1 : 0,
|
||||
name: community.name,
|
||||
people: [],
|
||||
position: i+1
|
||||
position: i + 1
|
||||
};
|
||||
|
||||
community.title_id.forEach(title_id => {
|
||||
community.title_id.forEach((title_id) => {
|
||||
// * Just in case
|
||||
if (title_id) {
|
||||
topic.title_ids.push({ title_id });
|
||||
|
|
@ -219,7 +219,7 @@ async function calculateMostPopularCommunities(hours: number, limit: number): Pr
|
|||
throw new Error('Invalid date');
|
||||
}
|
||||
|
||||
const validCommunities = await Community.aggregate<{ _id: null; communities: string[]; }>([
|
||||
const validCommunities = await Community.aggregate<{ _id: null; communities: string[] }>([
|
||||
{
|
||||
$match: {
|
||||
type: 0,
|
||||
|
|
@ -242,7 +242,7 @@ async function calculateMostPopularCommunities(hours: number, limit: number): Pr
|
|||
throw new Error('No communities found');
|
||||
}
|
||||
|
||||
const popularCommunities = await Post.aggregate<{ _id: null; count: number; }>([
|
||||
const popularCommunities = await Post.aggregate<{ _id: null; count: number }>([
|
||||
{
|
||||
$match: {
|
||||
created_at: {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { getValueFromQueryString } from '@/util';
|
|||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/:pid/notifications', function(request: express.Request, response: express.Response): void {
|
||||
router.get('/:pid/notifications', function (request: express.Request, response: express.Response): void {
|
||||
const type = getValueFromQueryString(request.query, 'type')[0];
|
||||
const titleID = getValueFromQueryString(request.query, 'title_id')[0];
|
||||
const pid = getValueFromQueryString(request.query, 'pid')[0];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import express from 'express';
|
||||
import subdomain from 'express-subdomain';
|
||||
import { LOG_INFO } from '@/logger';
|
||||
|
||||
import discoveryHandlers from '@/services/discovery/routes/discovery';
|
||||
|
||||
// Main router for endpointsindex.js
|
||||
|
|
@ -19,4 +18,4 @@ router.use(subdomain('discovery-dev.olv', discovery));
|
|||
// Setup routes
|
||||
discovery.use('/v1/endpoint', discoveryHandlers);
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import express from 'express';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import { getUserAccountData } from '@/util';
|
||||
import { getEndpoint } from '@/database';
|
||||
import { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import type { HydratedEndpointDocument } from '@/types/mongoose/endpoint';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ router.get('/', async function (request: express.Request, response: express.Resp
|
|||
|
||||
try {
|
||||
user = await getUserAccountData(request.pid);
|
||||
} catch (error) {
|
||||
} catch (ignored) {
|
||||
// TODO - Log this error
|
||||
response.sendStatus(404);
|
||||
return;
|
||||
|
|
@ -52,7 +52,7 @@ router.get('/', async function (request: express.Request, response: express.Resp
|
|||
}
|
||||
}).end({ pretty: true }));
|
||||
|
||||
return ;
|
||||
return;
|
||||
case 1:
|
||||
message = 'SYSTEM_UPDATE_REQUIRED';
|
||||
errorCode = 1;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import mongoose from 'mongoose';
|
||||
import type mongoose from 'mongoose';
|
||||
|
||||
export interface Config {
|
||||
http: {
|
||||
|
|
@ -30,4 +30,4 @@ export interface Config {
|
|||
};
|
||||
};
|
||||
aes_key: string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ export interface FormattedMessage {
|
|||
screen_name: string;
|
||||
topic_tag: {
|
||||
name: string;
|
||||
title_id: number
|
||||
title_id: number;
|
||||
};
|
||||
title_id: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@ export interface ParamPack {
|
|||
transferable_id: string;
|
||||
tz_name: string;
|
||||
utc_offset: string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ export interface Token {
|
|||
access_level: number;
|
||||
title_id: bigint;
|
||||
expire_time: bigint;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
src/types/express-subdomain.d.ts
vendored
2
src/types/express-subdomain.d.ts
vendored
|
|
@ -13,4 +13,4 @@ declare module 'express-subdomain'{
|
|||
subdomain: string,
|
||||
fn: Router
|
||||
): (req: Request, res: Response, next: () => void) => void | typeof fn;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
src/types/express.d.ts
vendored
6
src/types/express.d.ts
vendored
|
|
@ -1,10 +1,10 @@
|
|||
import { ParamPack } from '@/types/common/param-pack';
|
||||
import type { ParamPack } from '@/types/common/param-pack';
|
||||
|
||||
declare global {
|
||||
namespace Express {
|
||||
interface Request {
|
||||
pid: number;
|
||||
paramPack: ParamPack
|
||||
paramPack: ParamPack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { PostData } from '@/types/miiverse/post';
|
||||
import type { PostData } from '@/types/miiverse/post';
|
||||
|
||||
export type CommunityData = {
|
||||
community_id: string;
|
||||
|
|
@ -30,4 +30,4 @@ export type CommunityPostsResult = {
|
|||
posts: {
|
||||
post: PostData;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { PostData } from '@/types/miiverse/post';
|
||||
import { SettingsData } from '@/types/miiverse/settings';
|
||||
import type { PostData } from '@/types/miiverse/post';
|
||||
import type { SettingsData } from '@/types/miiverse/settings';
|
||||
|
||||
export type PersonPosts = {
|
||||
person: {
|
||||
posts: {
|
||||
post: PostData;
|
||||
}[];
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export type PeoplePostsResult = {
|
||||
|
|
@ -24,4 +24,4 @@ export type PeopleFollowingResult = {
|
|||
people: {
|
||||
person: SettingsData;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,4 +50,4 @@ export type PostRepliesResult = {
|
|||
posts: {
|
||||
post: PostData;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export type SettingsData = {
|
||||
pid: number;
|
||||
screen_name: string;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { PersonPosts } from '@/types/miiverse/people';
|
||||
import type { PersonPosts } from '@/types/miiverse/people';
|
||||
|
||||
export type WWPTopic = {
|
||||
empathy_count: number;
|
||||
|
|
@ -24,4 +24,3 @@ export type WWPResult = {
|
|||
topic: WWPTopic;
|
||||
}[];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ export interface CommunityPostsQuery {
|
|||
$in: number[];
|
||||
};
|
||||
parent?: {
|
||||
$eq: null
|
||||
$eq: null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import { CommunityData } from '@/types/miiverse/community';
|
||||
import type { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import type { CommunityData } from '@/types/miiverse/community';
|
||||
|
||||
enum COMMUNITY_TYPE {
|
||||
Main = 0,
|
||||
|
|
@ -37,7 +37,7 @@ export interface ICommunity {
|
|||
is_recommended: number;
|
||||
app_data: string;
|
||||
user_favorites: Types.Array<number>;
|
||||
permissions: ICommunityPermissions
|
||||
permissions: ICommunityPermissions;
|
||||
}
|
||||
|
||||
export interface ICommunityMethods {
|
||||
|
|
@ -48,4 +48,4 @@ export interface ICommunityMethods {
|
|||
|
||||
export type CommunityModel = Model<ICommunity, object, ICommunityMethods>;
|
||||
|
||||
export type HydratedCommunityDocument = HydratedDocument<ICommunity, ICommunityMethods>;
|
||||
export type HydratedCommunityDocument = HydratedDocument<ICommunity, ICommunityMethods>;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import type { Model, Types, HydratedDocument } from 'mongoose';
|
||||
|
||||
export interface IContent {
|
||||
pid: number;
|
||||
followed_communities: Types.Array<string>;
|
||||
followed_users: Types.Array<number>;
|
||||
following_users: Types.Array<number>;
|
||||
followed_communities: Types.Array<string>;
|
||||
followed_users: Types.Array<number>;
|
||||
following_users: Types.Array<number>;
|
||||
}
|
||||
|
||||
export type ContentModel = Model<IContent>;
|
||||
|
||||
export type HydratedContentDocument = HydratedDocument<IContent>;
|
||||
export type HydratedContentDocument = HydratedDocument<IContent>;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import type { Model, Types, HydratedDocument } from 'mongoose';
|
||||
|
||||
export type ConversationUser = {
|
||||
pid: number;
|
||||
official: boolean;
|
||||
read: boolean;
|
||||
official: boolean;
|
||||
read: boolean;
|
||||
};
|
||||
|
||||
export interface IConversation {
|
||||
id: string;
|
||||
created_at: Date;
|
||||
last_updated: Date;
|
||||
message_preview: string,
|
||||
users: Types.Array<ConversationUser>;
|
||||
created_at: Date;
|
||||
last_updated: Date;
|
||||
message_preview: string;
|
||||
users: Types.Array<ConversationUser>;
|
||||
}
|
||||
|
||||
export interface IConversationMethods {
|
||||
|
|
@ -20,4 +20,4 @@ export interface IConversationMethods {
|
|||
|
||||
export type ConversationModel = Model<IConversation, object, IConversationMethods>;
|
||||
|
||||
export type HydratedConversationDocument = HydratedDocument<IConversation, IConversationMethods>;
|
||||
export type HydratedConversationDocument = HydratedDocument<IConversation, IConversationMethods>;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import { Model, HydratedDocument } from 'mongoose';
|
||||
import type { Model, HydratedDocument } from 'mongoose';
|
||||
|
||||
export interface IEndpoint {
|
||||
status: number;
|
||||
server_access_level: string;
|
||||
topics: boolean;
|
||||
guest_access: boolean;
|
||||
host: string;
|
||||
api_host: string;
|
||||
portal_host: string;
|
||||
n3ds_host: string;
|
||||
server_access_level: string;
|
||||
topics: boolean;
|
||||
guest_access: boolean;
|
||||
host: string;
|
||||
api_host: string;
|
||||
portal_host: string;
|
||||
n3ds_host: string;
|
||||
}
|
||||
|
||||
export type EndpointModel = Model<IEndpoint>;
|
||||
|
||||
export type HydratedEndpointDocument = HydratedDocument<IEndpoint>;
|
||||
export type HydratedEndpointDocument = HydratedDocument<IEndpoint>;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
import { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import type { Model, Types, HydratedDocument } from 'mongoose';
|
||||
|
||||
export type NotificationUser = {
|
||||
user: string;
|
||||
timestamp: number;
|
||||
}
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
export interface INotification {
|
||||
pid: string;
|
||||
type: string;
|
||||
link: string;
|
||||
objectID: string;
|
||||
users: Types.Array<NotificationUser>;
|
||||
read: boolean;
|
||||
lastUpdated: number;
|
||||
type: string;
|
||||
link: string;
|
||||
objectID: string;
|
||||
users: Types.Array<NotificationUser>;
|
||||
read: boolean;
|
||||
lastUpdated: number;
|
||||
}
|
||||
|
||||
export type NotificationModel = Model<INotification>;
|
||||
|
||||
export type HydratedNotificationDocument = HydratedDocument<INotification>;
|
||||
export type HydratedNotificationDocument = HydratedDocument<INotification>;
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ export interface PostToJSONOptions {
|
|||
with_mii: boolean;
|
||||
app_data?: boolean;
|
||||
topic_tag?: boolean;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import { PostToJSONOptions } from '@/types/mongoose/post-to-json-options';
|
||||
import { PostData, PostPainting, PostScreenshot, PostTopicTag } from '@/types/miiverse/post';
|
||||
import type { Model, Types, HydratedDocument } from 'mongoose';
|
||||
import type { HydratedCommunityDocument } from '@/types/mongoose/community';
|
||||
import type { PostToJSONOptions } from '@/types/mongoose/post-to-json-options';
|
||||
import type { PostData, PostPainting, PostScreenshot, PostTopicTag } from '@/types/miiverse/post';
|
||||
|
||||
export interface IPost {
|
||||
id: string;
|
||||
|
|
@ -54,4 +54,4 @@ export interface IPostMethods {
|
|||
|
||||
export type PostModel = Model<IPost, object, IPostMethods>;
|
||||
|
||||
export type HydratedPostDocument = HydratedDocument<IPost, IPostMethods>;
|
||||
export type HydratedPostDocument = HydratedDocument<IPost, IPostMethods>;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Model, HydratedDocument } from 'mongoose';
|
||||
import type { Model, HydratedDocument } from 'mongoose';
|
||||
|
||||
export interface IReport {
|
||||
pid: string;
|
||||
post_id: string;
|
||||
reason: number;
|
||||
created_at: Date;
|
||||
post_id: string;
|
||||
reason: number;
|
||||
created_at: Date;
|
||||
}
|
||||
|
||||
export type ReportModel = Model<IReport>;
|
||||
|
||||
export type HydratedReportDocument = HydratedDocument<IReport>;
|
||||
export type HydratedReportDocument = HydratedDocument<IReport>;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import { Model, HydratedDocument } from 'mongoose';
|
||||
import { SettingsData } from '@/types/miiverse/settings';
|
||||
import type { Model, HydratedDocument } from 'mongoose';
|
||||
import type { SettingsData } from '@/types/miiverse/settings';
|
||||
|
||||
export interface ISettings {
|
||||
pid: number;
|
||||
screen_name: string;
|
||||
account_status: number;
|
||||
ban_lift_date: Date;
|
||||
ban_reason: string;
|
||||
profile_comment: string;
|
||||
profile_comment_visibility: boolean;
|
||||
game_skill: number;
|
||||
game_skill_visibility: boolean;
|
||||
birthday_visibility: boolean;
|
||||
relationship_visibility: boolean;
|
||||
country_visibility: boolean;
|
||||
profile_favorite_community_visibility: boolean;
|
||||
receive_notifications: boolean;
|
||||
screen_name: string;
|
||||
account_status: number;
|
||||
ban_lift_date: Date;
|
||||
ban_reason: string;
|
||||
profile_comment: string;
|
||||
profile_comment_visibility: boolean;
|
||||
game_skill: number;
|
||||
game_skill_visibility: boolean;
|
||||
birthday_visibility: boolean;
|
||||
relationship_visibility: boolean;
|
||||
country_visibility: boolean;
|
||||
profile_favorite_community_visibility: boolean;
|
||||
receive_notifications: boolean;
|
||||
}
|
||||
|
||||
export interface ISettingsMethods {
|
||||
|
|
@ -24,4 +24,4 @@ export interface ISettingsMethods {
|
|||
|
||||
export type SettingsModel = Model<ISettings, object, ISettingsMethods>;
|
||||
|
||||
export type HydratedSettingsDocument = HydratedDocument<ISettings, ISettingsMethods>;
|
||||
export type HydratedSettingsDocument = HydratedDocument<ISettings, ISettingsMethods>;
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ export interface SubCommunityQuery {
|
|||
user_favorites?: number;
|
||||
olive_community_id?: string;
|
||||
community_id?: string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
src/types/node-snowflake.d.ts
vendored
2
src/types/node-snowflake.d.ts
vendored
|
|
@ -11,4 +11,4 @@ declare module 'node-snowflake' {
|
|||
init: (config: SnowflakeInitConfig) => void;
|
||||
nextId: (workerId?: number, dataCenterId?: number, sequence?: number) => string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
src/types/tga.d.ts
vendored
2
src/types/tga.d.ts
vendored
|
|
@ -55,4 +55,4 @@ declare module 'tga' {
|
|||
|
||||
public pixels: Uint8Array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
src/util.ts
18
src/util.ts
|
|
@ -1,22 +1,20 @@
|
|||
import crypto from 'node:crypto';
|
||||
import { IncomingHttpHeaders } from 'node:http';
|
||||
import TGA from 'tga';
|
||||
import BMP from 'bmp-js';
|
||||
import pako from 'pako';
|
||||
import { PNG } from 'pngjs';
|
||||
import aws from 'aws-sdk';
|
||||
import { createChannel, createClient, Metadata } from 'nice-grpc';
|
||||
import { ParsedQs } from 'qs';
|
||||
import crc32 from 'crc/crc32';
|
||||
import { ParamPack } from '@/types/common/param-pack';
|
||||
import { config } from '@/config-manager';
|
||||
import { Token } from '@/types/common/token';
|
||||
|
||||
import { FriendsDefinition } from '@pretendonetwork/grpc/friends/friends_service';
|
||||
import { FriendRequest } from '@pretendonetwork/grpc/friends/friend_request';
|
||||
|
||||
import { AccountDefinition } from '@pretendonetwork/grpc/account/account_service';
|
||||
import { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import { config } from '@/config-manager';
|
||||
import type { FriendRequest } from '@pretendonetwork/grpc/friends/friend_request';
|
||||
import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
|
||||
import type { ParsedQs } from 'qs';
|
||||
import type { IncomingHttpHeaders } from 'node:http';
|
||||
import type { ParamPack } from '@/types/common/param-pack';
|
||||
import type { Token } from '@/types/common/token';
|
||||
|
||||
// * nice-grpc doesn't export ChannelImplementation so this can't be typed
|
||||
const gRPCFriendsChannel = createChannel(`${config.grpc.friends.ip}:${config.grpc.friends.port}`);
|
||||
|
|
@ -224,4 +222,4 @@ export function getValueFromHeaders(headers: IncomingHttpHeaders, key: string):
|
|||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
31
test/test.ts
31
test/test.ts
|
|
@ -1,6 +1,5 @@
|
|||
import crypto from 'node:crypto';
|
||||
import newman from 'newman';
|
||||
import { Collection, CollectionDefinition } from 'postman-collection';
|
||||
import qs from 'qs';
|
||||
import axios from 'axios';
|
||||
import { create as parseXML } from 'xmlbuilder2';
|
||||
|
|
@ -8,9 +7,9 @@ import { table } from 'table';
|
|||
import ora from 'ora';
|
||||
import dotenv from 'dotenv';
|
||||
import colors from 'colors';
|
||||
|
||||
import communitiesCollection from '../postman/collections/Communities.json';
|
||||
import peopleCollection from '../postman/collections/People.json';
|
||||
import type { Collection, CollectionDefinition } from 'postman-collection';
|
||||
|
||||
const PeopleCollection: CollectionDefinition = peopleCollection as CollectionDefinition;
|
||||
const CommunitiesCollection: CollectionDefinition = communitiesCollection as CollectionDefinition;
|
||||
|
|
@ -24,7 +23,7 @@ interface TestResult {
|
|||
url: string;
|
||||
query: string;
|
||||
assertion: string;
|
||||
error?: string
|
||||
error?: string;
|
||||
}
|
||||
|
||||
const USERNAME = process.env.PN_MIIVERSE_API_TESTING_USERNAME?.trim() || '';
|
||||
|
|
@ -102,7 +101,7 @@ async function apiGetRequest(url: string, headers = {}): Promise<Record<string,
|
|||
async function apiPostRequest(url: string, body: string): Promise<Record<string, any>> {
|
||||
const response = await axios.post(url, body, {
|
||||
headers: DEFAULT_HEADERS,
|
||||
validateStatus: () => true,
|
||||
validateStatus: () => true
|
||||
});
|
||||
|
||||
const data: Record<string, any> = parseXML(response.data).end({ format: 'object' });
|
||||
|
|
@ -129,7 +128,7 @@ async function getAccessToken(username: string, passwordHash: string): Promise<s
|
|||
grant_type: 'password',
|
||||
user_id: username,
|
||||
password: passwordHash,
|
||||
password_type: 'hash',
|
||||
password_type: 'hash'
|
||||
});
|
||||
|
||||
const response = await apiPostRequest(ACCESS_TOKEN_URL, data);
|
||||
|
|
@ -140,7 +139,7 @@ async function getAccessToken(username: string, passwordHash: string): Promise<s
|
|||
async function getMiiverseServiceToken(accessToken: string): Promise<string> {
|
||||
const response = await apiGetRequest(SERVICE_TOKEN_URL, {
|
||||
'X-Nintendo-Title-ID': '0005001010040100',
|
||||
Authorization: `Bearer ${accessToken}`
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
});
|
||||
|
||||
return response.service_token.token;
|
||||
|
|
@ -153,7 +152,7 @@ function runNewmanTest(collection: string | Collection | CollectionDefinition, v
|
|||
reporters: ['json'],
|
||||
envVar: Object.entries(variables).map(entry => ({ key: entry[0], value: entry[1] })),
|
||||
globals: variables,
|
||||
globalVar: Object.entries(variables).map(entry => ({ key: entry[0], value: entry[1] })),
|
||||
globalVar: Object.entries(variables).map(entry => ({ key: entry[0], value: entry[1] }))
|
||||
}, (error, summary) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
|
|
@ -167,13 +166,13 @@ function runNewmanTest(collection: string | Collection | CollectionDefinition, v
|
|||
function communitiesRoutesTest(serviceToken: string): Promise<TestResult[]> {
|
||||
// TODO - Make this more dynamic?
|
||||
return runNewmanTest(CommunitiesCollection, {
|
||||
DOMAIN: 'api.olv.pretendo.cc',
|
||||
ServiceToken: serviceToken,
|
||||
'DOMAIN': 'api.olv.pretendo.cc',
|
||||
'ServiceToken': serviceToken,
|
||||
// TODO - Change these names. Should not be game-specific
|
||||
PP_Splatoon: 'XHRpdGxlX2lkXDE0MDczNzUxNTM1MjI5NDRcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
PP_MarioVsDK: 'XHRpdGxlX2lkXDE0MDczNzUxNTMzMzcwODhcYWNjZXNzX2tleVw2OTI0NzQ1MTBccGxhdGZvcm1faWRcMVxyZWdpb25faWRcMlxsYW5ndWFnZV9pZFwxXGNvdW50cnlfaWRcNDlcYXJlYV9pZFwwXG5ldHdvcmtfcmVzdHJpY3Rpb25cMFxmcmllbmRfcmVzdHJpY3Rpb25cMFxyYXRpbmdfcmVzdHJpY3Rpb25cMTdccmF0aW5nX29yZ2FuaXphdGlvblwxXHRyYW5zZmVyYWJsZV9pZFw3NjA4MjAyOTE2MDc1ODg0NDI1XHR6X25hbWVcUGFjaWZpYy9NaWR3YXlcdXRjX29mZnNldFwtMzk2MDBc',
|
||||
PP_Bad_TID: 'XHRpdGxlX2lkXDEyMzRcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
PP_ACPlaza: 'XHRpdGxlX2lkXDE0MDczNzUxNTMzMjE0NzJcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
'PP_Splatoon': 'XHRpdGxlX2lkXDE0MDczNzUxNTM1MjI5NDRcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
'PP_MarioVsDK': 'XHRpdGxlX2lkXDE0MDczNzUxNTMzMzcwODhcYWNjZXNzX2tleVw2OTI0NzQ1MTBccGxhdGZvcm1faWRcMVxyZWdpb25faWRcMlxsYW5ndWFnZV9pZFwxXGNvdW50cnlfaWRcNDlcYXJlYV9pZFwwXG5ldHdvcmtfcmVzdHJpY3Rpb25cMFxmcmllbmRfcmVzdHJpY3Rpb25cMFxyYXRpbmdfcmVzdHJpY3Rpb25cMTdccmF0aW5nX29yZ2FuaXphdGlvblwxXHRyYW5zZmVyYWJsZV9pZFw3NjA4MjAyOTE2MDc1ODg0NDI1XHR6X25hbWVcUGFjaWZpYy9NaWR3YXlcdXRjX29mZnNldFwtMzk2MDBc',
|
||||
'PP_Bad_TID': 'XHRpdGxlX2lkXDEyMzRcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
'PP_ACPlaza': 'XHRpdGxlX2lkXDE0MDczNzUxNTMzMjE0NzJcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
'PP_Bad Format': 'XHR'
|
||||
});
|
||||
}
|
||||
|
|
@ -184,7 +183,7 @@ function peopleRoutesTest(serviceToken: string): Promise<TestResult[]> {
|
|||
DOMAIN: 'api.olv.pretendo.cc',
|
||||
ServiceToken: serviceToken,
|
||||
// TODO - Change this name. Should not be game-specific
|
||||
PP_Splatoon: 'XHRpdGxlX2lkXDE0MDczNzUxNTM1MjI5NDRcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc',
|
||||
PP_Splatoon: 'XHRpdGxlX2lkXDE0MDczNzUxNTM1MjI5NDRcYWNjZXNzX2tleVwwXHBsYXRmb3JtX2lkXDFccmVnaW9uX2lkXDJcbGFuZ3VhZ2VfaWRcMVxjb3VudHJ5X2lkXDExMFxhcmVhX2lkXDBcbmV0d29ya19yZXN0cmljdGlvblwwXGZyaWVuZF9yZXN0cmljdGlvblwwXHJhdGluZ19yZXN0cmljdGlvblwyMFxyYXRpbmdfb3JnYW5pemF0aW9uXDBcdHJhbnNmZXJhYmxlX2lkXDEyNzU2MTQ0ODg0NDUzODk4NzgyXHR6X25hbWVcQW1lcmljYS9OZXdfWW9ya1x1dGNfb2Zmc2V0XC0xNDQwMFxyZW1hc3Rlcl92ZXJzaW9uXDBc'
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -275,7 +274,7 @@ function createTestResults(summary: newman.NewmanRunSummary): TestResult[] {
|
|||
collection: summary.collection.name,
|
||||
name: execution.item.name,
|
||||
url: `${request.url.protocol}://${request.url.host?.join('.')}/${request.url.path?.join('/')}`,
|
||||
query: qs.stringify(request.url.query.all().reduce((object: Record<string, string>, item: { disabled?: boolean; key: string | null; value: string | null; }) => {
|
||||
query: qs.stringify(request.url.query.all().reduce((object: Record<string, string>, item: { disabled?: boolean; key: string | null; value: string | null }) => {
|
||||
if (!item.disabled && item.key && item.value) {
|
||||
object[item.key] = item.value;
|
||||
}
|
||||
|
|
@ -293,4 +292,4 @@ function createTestResults(summary: newman.NewmanRunSummary): TestResult[] {
|
|||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user