style: lint ALL the files

This commit is contained in:
William Oldham
2025-01-16 13:03:07 +00:00
parent 47d799b339
commit 5998e511ea
51 changed files with 218 additions and 231 deletions

View File

@@ -24,4 +24,4 @@ export default class Cache<T> {
get(): T | undefined {
return this.data;
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -44,4 +44,4 @@ export function LOG_INFO(input: string): void {
streams.info.write(`${input}\n`);
console.log(`${input}`.cyan.bold);
}
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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,

View File

@@ -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);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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();

View File

@@ -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;

View File

@@ -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');

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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: {

View File

@@ -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];

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -21,8 +21,8 @@ export interface FormattedMessage {
screen_name: string;
topic_tag: {
name: string;
title_id: number
title_id: number;
};
title_id: string;
};
}
}

View File

@@ -13,4 +13,4 @@ export interface ParamPack {
transferable_id: string;
tz_name: string;
utc_offset: string;
}
}

View File

@@ -5,4 +5,4 @@ export interface Token {
access_level: number;
title_id: bigint;
expire_time: bigint;
}
}

View File

@@ -13,4 +13,4 @@ declare module 'express-subdomain'{
subdomain: string,
fn: Router
): (req: Request, res: Response, next: () => void) => void | typeof fn;
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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;
}[];
};
};

View File

@@ -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;
}[];
};
};

View File

@@ -50,4 +50,4 @@ export type PostRepliesResult = {
posts: {
post: PostData;
}[];
};
};

View File

@@ -1,4 +1,4 @@
export type SettingsData = {
pid: number;
screen_name: string;
};
};

View File

@@ -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;
}[];
};

View File

@@ -19,6 +19,6 @@ export interface CommunityPostsQuery {
$in: number[];
};
parent?: {
$eq: null
$eq: null;
};
}
}

View File

@@ -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>;

View File

@@ -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>;

View File

@@ -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>;

View File

@@ -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>;

View File

@@ -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>;

View File

@@ -2,4 +2,4 @@ export interface PostToJSONOptions {
with_mii: boolean;
app_data?: boolean;
topic_tag?: boolean;
}
}

View File

@@ -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>;

View File

@@ -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>;

View File

@@ -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>;

View File

@@ -6,4 +6,4 @@ export interface SubCommunityQuery {
user_favorites?: number;
olive_community_id?: string;
community_id?: string;
}
}

View File

@@ -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
View File

@@ -55,4 +55,4 @@ declare module 'tga' {
public pixels: Uint8Array;
}
}
}

View File

@@ -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;
}
}