Skip to content

Commit

Permalink
style: lint ALL the files
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryoverload committed Jan 16, 2025
1 parent a927404 commit 973aafc
Show file tree
Hide file tree
Showing 51 changed files with 220 additions and 235 deletions.
2 changes: 1 addition & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export default class Cache<T> {
get(): T | undefined {
return this.data;
}
}
}
8 changes: 4 additions & 4 deletions src/config-manager.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
14 changes: 7 additions & 7 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -176,4 +176,4 @@ export async function getFriendMessages(pid: string, search_key: string[], limit
parent: null,
removed: false
}).sort({ created_at: 1 }).limit(limit);
}
}
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export function LOG_INFO(input: string): void {
streams.info.write(`${input}\n`);

console.log(`${input}`.cyan.bold);
}
}
13 changes: 6 additions & 7 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down Expand Up @@ -90,9 +90,9 @@ async function auth(request: express.Request, response: express.Response, next:
// * This is a false positive from ESLint.
// * Since this middleware is only ever called
// * per every request instance
// eslint-disable-next-line require-atomic-updates

request.pid = pid;
// eslint-disable-next-line require-atomic-updates

request.paramPack = paramPackData;

const userSettings = await getUserSettings(request.pid);
Expand All @@ -117,7 +117,6 @@ async function auth(request: express.Request, response: express.Response, next:
} else {
return badAuth(response, 7, 'PNID_PERM_BAN');
}

}

return next();
Expand Down
11 changes: 5 additions & 6 deletions src/middleware/client-header.ts
Original file line number Diff line number Diff line change
@@ -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)');
Expand Down Expand Up @@ -41,4 +40,4 @@ function nintendoClientHeaderCheck(request: express.Request, response: express.R
return next();
}

export default nintendoClientHeaderCheck;
export default nintendoClientHeaderCheck;
10 changes: 5 additions & 5 deletions src/models/community.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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>({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/models/content.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/models/conversation.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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,
Expand Down Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/models/endpoint.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/models/notification.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 6 additions & 7 deletions src/models/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/report.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 5 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
3 changes: 1 addition & 2 deletions src/services/api/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
32 changes: 15 additions & 17 deletions src/services/api/routes/communities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 };
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');

Expand Down
Loading

0 comments on commit 973aafc

Please sign in to comment.