chore: remove default exports

This commit is contained in:
Michael Wolfendale 2024-05-23 22:21:48 +01:00
parent fbccb0a76d
commit 901d6a61a7
No known key found for this signature in database
25 changed files with 89 additions and 224 deletions

View File

@ -579,62 +579,4 @@ export async function getReportById(id: number): Promise<HydratedReportDocument
verifyConnected();
return REPORT.findById(id);
}
export default {
connect,
getCommunities,
getMostPopularCommunities,
getNewCommunities,
getSubCommunities,
getCommunityByTitleID,
getCommunityByID,
getTotalPostsByCommunity,
getPostsByCommunity,
getHotPostsByCommunity,
getNumberNewCommunityPostsByID,
getNumberPopularCommunityPostsByID,
getNumberVerifiedCommunityPostsByID,
getNewPostsByCommunity,
getPostsByCommunityKey,
getPostsByUserID,
getPostReplies,
getUserPostRepliesAfterTimestamp,
getNumberUserPostsByID,
getTotalPostsByUserID,
getPostByID,
getDuplicatePosts,
getEndpoints,
getEndPoint,
getUserPostsAfterTimestamp,
getUserPostsOffset,
getCommunityPostsAfterTimestamp,
getNewsFeed,
getNewsFeedAfterTimestamp,
getNewsFeedOffset,
getFollowingUsers,
getFollowedUsers,
getConversations,
getConversationByID,
getConversationByUsers,
getConversationMessages,
getUnreadConversationCount,
getLatestMessage,
getUsersSettings,
getUsersContent,
getUserSettings,
getUserContent,
getNotifications,
getUnreadNotificationCount,
getNotification,
getLastNotification,
getAllUserPosts,
getRemovedUserPosts,
getAllReports,
getAllOpenReports,
getReportsByUser,
getReportsByPost,
getReportById,
getUserSettingsFuzzySearch,
getDuplicateReports
};
}

View File

@ -1,5 +1,5 @@
import moment from 'moment/moment';
import db from '@/database';
import * as db from '@/database';
import type { Request, Response, NextFunction } from 'express';
import config from '../../config.json';
@ -58,8 +58,4 @@ export async function checkBan(request: Request, response: Response, next: NextF
}
}
next();
}
export default {
checkBan
};
}

View File

@ -1,4 +1,4 @@
import util from '@/util';
import * as util from '@/util';
import type { User } from '@/types/common/user';
import type { Request, Response, NextFunction } from 'express';
import config from '../../config.json';
@ -74,8 +74,4 @@ export async function auth(request: Request, response: Response, next: NextFunct
request.lang = util.processLanguage(request?.paramPackData ?? undefined);
//console.timeEnd(`Time Request ${request.timerDate}`);
return next();
}
export default {
auth
};
}

View File

@ -1,4 +1,4 @@
import util from '@/util';
import * as util from '@/util';
import type { Request, Response, NextFunction } from 'express';
export async function detectVersion(request: Request, response: Response, next: NextFunction): Promise<void> {
@ -19,8 +19,4 @@ export async function detectVersion(request: Request, response: Response, next:
function includes(request: Request, domain: string): boolean {
return request.subdomains.findIndex(element => element.includes(domain)) !== -1;
}
export default {
detectVersion
};
}

View File

@ -1,4 +1,4 @@
import db from '@/database';
import * as db from '@/database';
import type { Request, Response, NextFunction } from 'express';
import config from '../../config.json';
@ -33,8 +33,4 @@ export async function checkDiscovery(request: Request, response: Response, next:
}
next();
}
export default {
checkDiscovery
};
}

View File

@ -1,4 +1,4 @@
import util from '@/util';
import * as util from '@/util';
import type { Request, Response, NextFunction } from 'express';
export async function staticFiles(request: Request, response: Response, next: NextFunction): Promise<void> {
@ -29,9 +29,4 @@ export async function staticFiles(request: Request, response: Response, next: Ne
function isStartOfPath(path: string, value: string): boolean {
return path.indexOf(value) === 0;
}
export default {
staticFiles
};
}

View File

@ -1,4 +1,4 @@
import util from '@/util';
import * as util from '@/util';
import type { Request, Response, NextFunction } from 'express';
export async function webAuth(request: Request, response: Response, next: NextFunction): Promise<void> {
@ -61,8 +61,4 @@ function isStartOfPath(path: string, value: string): boolean {
(BigInt as any).prototype['toJSON'] = function (): string {
return this.toString();
}
export default {
webAuth
};
};

View File

@ -39,10 +39,4 @@ export async function removeValue(key: string): Promise<boolean> {
await redisClient.del(key);
return true;
}
export default {
setValue,
getValue,
removeValue
};
}

View File

@ -4,7 +4,7 @@ import cookieParser from 'cookie-parser';
import session from 'express-session';
import { default as RedisStore } from 'connect-redis';
import logger from '@/logger';
import database from '@/database';
import * as database from '@/database';
import { redisClient } from '@/redisCache';
import juxt_web from '@/services/juxt-web';
import config from '../config.json';

View File

@ -1,7 +1,7 @@
import express from 'express';
import subdomain from 'express-subdomain';
import logger from '../../logger';
import routes from './routes';
import * as routes from './routes';
import { webAuth } from '../../middleware/webAuth';
import { auth as consoleAuth } from '../../middleware/consoleAuth';
import { checkBan } from '../../middleware/checkBan';

View File

@ -1,9 +1,9 @@
import moment from 'moment';
import express from 'express';
import database from '@/database';
import * as database from '@/database';
import { POST } from '@/models/post';
import { SETTINGS } from '@/models/settings';
import util from '@/util';
import * as util from '@/util';
import type { HydratedPostDocument } from '@/types/mongoose/post';
import config from '../../../../../config.json';
@ -76,7 +76,6 @@ router.get('/accounts', async function (req, res) {
});
});
router.get('/accounts/:pid', async function (req, res): Promise<void> {
if (!req.moderator) {
return res.redirect('/titles/show');

View File

@ -1,11 +1,11 @@
import express from 'express';
import multer from 'multer';
import moment from 'moment';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import { POST } from '@/models/post';
import { COMMUNITY } from '@/models/communities';
import redis from '@/redisCache';
import * as redis from '@/redisCache';
import type { HydratedCommunityDocument, ICommunity } from '@/types/mongoose/communities';
import type { HydratedPostDocument } from '@/types/mongoose/post';
import config from '../../../../../config.json';
@ -303,4 +303,4 @@ async function calculateMostPopularCommunities(): Promise<string[]> {
.map((entry) => entry[0]);
}
export default router;
export default router;

View File

@ -1,7 +1,7 @@
import express from 'express';
import moment from 'moment';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import type { HydratedPostDocument } from '@/types/mongoose/post';
import config from '../../../../../config.json';
@ -95,4 +95,4 @@ router.get('/more', async function (req, res) {
}
});
export default router;
export default router;

View File

@ -2,8 +2,8 @@ import crypto from 'crypto';
import express from 'express';
import moment from 'moment';
import { Snowflake as snowflake } from 'node-snowflake';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import { POST } from '@/models/post';
import { CONVERSATION } from '@/models/conversation';
import type { IPost } from '@/types/mongoose/post';
@ -253,4 +253,4 @@ async function generatePostUID(length: number): Promise<string> {
return id;
}
export default router;
export default router;

View File

@ -1,7 +1,7 @@
import express from 'express';
import moment from 'moment';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import config from '../../../../../config.json';
const router = express.Router();
@ -67,4 +67,4 @@ router.get('/friend_requests', async function (req, res) {
});
});
export default router;
export default router;

View File

@ -3,9 +3,9 @@ import express from 'express';
import multer from 'multer';
import moment from 'moment';
import rateLimit from 'express-rate-limit';
import database from '../../../../database';
import util from '@/util';
import redis from '@/redisCache';
import * as database from '../../../../database';
import * as util from '@/util';
import * as redis from '@/redisCache';
import { POST } from '@/models/post';
import { REPORT } from '@/models/report';
import type { Request, Response } from 'express';
@ -370,5 +370,4 @@ async function generatePostUID(length: number): Promise<string> {
return id;
}
export default router;
export default router;

View File

@ -1,6 +1,6 @@
import express from 'express';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import config from '../../../../../config.json';
const router = express.Router();
@ -70,4 +70,4 @@ router.post('/newUser', async function (req, res) {
});
export default router;
export default router;

View File

@ -1,7 +1,7 @@
import express from 'express';
import moment from 'moment';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import { POST } from '@/models/post';
import config from '../../../../../config.json';
@ -118,4 +118,4 @@ router.get('/more', async function (req, res) {
}
});
export default router;
export default router;

View File

@ -1,9 +1,9 @@
import express from 'express';
import multer from 'multer';
import moment from 'moment';
import database from '@/database';
import util from '@/util';
import redis from '@/redisCache';
import * as database from '@/database';
import * as util from '@/util';
import * as redis from '@/redisCache';
import { POST } from '@/models/post';
import { SETTINGS } from '@/models/settings';
import type { Request, Response } from 'express';
@ -399,4 +399,4 @@ async function morePosts(req: Request, res: Response, userID: number): Promise<v
}
}
export default router;
export default router;

View File

@ -32,4 +32,4 @@ router.get('/favicon.ico', function (req, res) {
res.sendFile('/images/favicon.ico', {root: path.join(__dirname, '../../../../webfiles/' + req.directory)});
});
export default router;
export default router;

View File

@ -1,29 +1,13 @@
import PORTAL_SHOW from './console/show';
import PORTAL_COMMUNITIES from './console/communities';
import PORTAL_USER from './console/userpage';
import PORTAL_POST from './console/posts';
import PORTAL_FEED from './console/feed';
import PORTAL_NEWS from './console/notifications';
import PORTAL_MESSAGES from './console/messages';
import PORTAL_TOPICS from './console/topics';
import WEB_LOGIN from './web/login';
import ROBOTS from './web/robots';
import PWA from './web/pwa';
import ADMIN from './admin/admin';
import WEB_FILES from './console/web';
export default {
PORTAL_SHOW,
PORTAL_COMMUNITIES,
PORTAL_USER,
PORTAL_POST,
PORTAL_FEED,
PORTAL_NEWS,
PORTAL_MESSAGES,
PORTAL_TOPICS,
WEB_LOGIN,
ROBOTS,
PWA,
ADMIN,
WEB_FILES
};
export { default as PORTAL_SHOW } from '@/services/juxt-web/routes/console/show';
export { default as PORTAL_COMMUNITIES } from '@/services/juxt-web/routes/console/communities';
export { default as PORTAL_USER } from '@/services/juxt-web/routes/console/userpage';
export { default as PORTAL_POST } from '@/services/juxt-web/routes/console/posts';
export { default as PORTAL_FEED } from '@/services/juxt-web/routes/console/feed';
export { default as PORTAL_NEWS } from '@/services/juxt-web/routes/console/notifications';
export { default as PORTAL_MESSAGES } from '@/services/juxt-web/routes/console/messages';
export { default as PORTAL_TOPICS } from '@/services/juxt-web/routes/console/topics';
export { default as WEB_LOGIN } from '@/services/juxt-web/routes/web/login';
export { default as ROBOTS } from '@/services/juxt-web/routes/web/robots';
export { default as PWA } from '@/services/juxt-web/routes/web/pwa';
export { default as ADMIN } from '@/services/juxt-web/routes/admin/admin';
export { default as WEB_FILES } from '@/services/juxt-web/routes/console/web';

View File

@ -1,6 +1,6 @@
import express from 'express';
import database from '@/database';
import util from '@/util';
import * as database from '@/database';
import * as util from '@/util';
import config from '../../../../../config.json';
const router = express.Router();
@ -69,5 +69,4 @@ router.post('/', async (req, res) => {
res.redirect('/');
});
export default router;
export default router;

View File

@ -13,4 +13,4 @@ router.get('/manifest.json', function (req, res) {
res.sendFile('manifest.json', {root: path.join(__dirname, '../../../../webfiles/web')});
});
export default router;
export default router;

View File

@ -8,4 +8,4 @@ router.get('/', function (req, res) {
res.sendFile('robots.txt', {root: path.join(__dirname, '../../../../webfiles/web')});
});
export default router;
export default router;

View File

@ -12,7 +12,7 @@ import { AccountDefinition } from '@pretendonetwork/grpc/account/account_service
import { APIDefinition } from '@pretendonetwork/grpc/api/api_service';
import { FriendsDefinition } from '@pretendonetwork/grpc/friends/friends_service';
import logger from '@/logger';
import database from '@/database';
import * as database from '@/database';
import { COMMUNITY } from '@/models/communities';
import { CONTENT } from '@/models/content';
import { NOTIFICATION } from '@/models/notifications';
@ -80,8 +80,8 @@ function nameCache(): void {
}
// TODO - This doesn't belong here, just hacking it in. Gonna redo this whole server anyway so fuck it
const INVALID_POST_BODY_REGEX = /[^\p{L}\p{P}\d\n\r$^¨¦¤¢£¥©®+×÷=±˘˙¸˛˜°¹²³¬¯¼½¾<> ]/gu;
async function create_user(pid: number, experience: number, notifications: boolean): Promise<void> {
export const INVALID_POST_BODY_REGEX = /[^\p{L}\p{P}\d\n\r$^¨¦¤¢£¥©®+×÷=±˘˙¸˛˜°¹²³¬¯¼½¾<> ]/gu;
export async function create_user(pid: number, experience: number, notifications: boolean): Promise<void> {
const pnid = await getUserDataFromPid(pid);
if (!pnid) {
return;
@ -119,7 +119,7 @@ export function decodeParamPack(paramPack: string): ParamPack {
return Object.fromEntries(entries);
}
function processServiceToken(encryptedToken: string | undefined): number | null {
export function processServiceToken(encryptedToken: string | undefined): number | null {
if (!encryptedToken) {
return null;
}
@ -141,7 +141,7 @@ function processServiceToken(encryptedToken: string | undefined): number | null
}
function decryptToken(token: Buffer): Buffer {
export function decryptToken(token: Buffer): Buffer {
if (!config.aes_key) {
throw new Error('Service token AES key not found. Set config.aes_key');
}
@ -166,7 +166,7 @@ function decryptToken(token: Buffer): Buffer {
return decrypted;
}
function unpackToken(token: Buffer): Token {
export function unpackToken(token: Buffer): Token {
return {
system_type: token.readUInt8(0x0),
token_type: token.readUInt8(0x1),
@ -177,7 +177,7 @@ function unpackToken(token: Buffer): Token {
};
}
function processPainting(painting: string | null, isTGA: boolean): string | null {
export function processPainting(painting: string | null, isTGA: boolean): string | null {
if (painting === null) {
return null;
@ -223,7 +223,7 @@ function processPainting(painting: string | null, isTGA: boolean): string | null
}
}
function nintendoPasswordHash(password: string, pid: number): string {
export function nintendoPasswordHash(password: string, pid: number): string {
const pidBuffer = Buffer.alloc(4);
pidBuffer.writeUInt32LE(pid);
@ -235,19 +235,19 @@ function nintendoPasswordHash(password: string, pid: number): string {
return crypto.createHash('sha256').update(unpacked).digest().toString('hex');
}
function getCommunityHash(): HashMap<string, string> {
export function getCommunityHash(): HashMap<string, string> {
return communityMap;
}
function getUserHash(): HashMap<number, string> {
export function getUserHash(): HashMap<number, string> {
return userMap;
}
function refreshCache(): void {
export function refreshCache(): void {
nameCache();
}
function setName(pid: number, name: string | undefined): void {
export function setName(pid: number, name: string | undefined): void {
if (!pid || !name) {
return;
}
@ -255,14 +255,14 @@ function setName(pid: number, name: string | undefined): void {
userMap.set(pid, name.replace(/[\u{0080}-\u{FFFF}]/gu,'').replace(/\u202e/g, ''));
}
// TODO is this used?
async function resizeImage(file: sharp.SharpOptions, width: number, height: number): Promise<Buffer> {
// ? TODO is this used?
export async function resizeImage(file: sharp.SharpOptions, width: number, height: number): Promise<Buffer> {
return sharp(file)
.resize({ height: height, width: width })
.toBuffer();
}
function createBMPTgaBuffer(width: number, height: number, pixels: Buffer, dontFlipY: boolean): Buffer {
export function createBMPTgaBuffer(width: number, height: number, pixels: Buffer, dontFlipY: boolean): Buffer {
const buffer = Buffer.alloc(18 + pixels.length);
// write header
buffer.writeInt8(0, 0);
@ -292,7 +292,7 @@ function createBMPTgaBuffer(width: number, height: number, pixels: Buffer, dontF
return buffer;
}
function processLanguage(paramPackData?: ParamPack): typeof translations.EN {
export function processLanguage(paramPackData?: ParamPack): typeof translations.EN {
if (!paramPackData) {
return translations.EN;
}
@ -326,7 +326,7 @@ function processLanguage(paramPackData?: ParamPack): typeof translations.EN {
}
}
async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: string): Promise<void> {
export async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: string): Promise<void> {
const awsPutParams = {
Body: data,
Key: key,
@ -337,7 +337,7 @@ async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: st
await s3.putObject(awsPutParams).promise();
}
async function newNotification(notification: Omit<INotification, 'read' | 'lastUpdated' | 'users'>): Promise<void> {
export async function newNotification(notification: Omit<INotification, 'read' | 'lastUpdated' | 'users'>): Promise<void> {
const now = new Date();
if (notification.type === 'follow') {
// { pid: userToFollowContent.pid, type: "follow", objectID: req.pid, link: `/users/${req.pid}` }
@ -377,7 +377,7 @@ async function newNotification(notification: Omit<INotification, 'read' | 'lastU
}
}
async function getFriends(pid: number): Promise<number[]> {
export async function getFriends(pid: number): Promise<number[]> {
try {
const pids = await friendsClient.getUserFriendPIDs({
pid: pid
@ -392,7 +392,7 @@ async function getFriends(pid: number): Promise<number[]> {
}
}
async function getFriendRequests(pid: number): Promise<FriendRequest[]> {
export async function getFriendRequests(pid: number): Promise<FriendRequest[]> {
try {
const requests = await friendsClient.getUserFriendRequestsIncoming({
pid: pid
@ -407,7 +407,7 @@ async function getFriendRequests(pid: number): Promise<FriendRequest[]> {
}
}
async function login(username: string, password: string): Promise<ApiLoginResponse> {
export async function login(username: string, password: string): Promise<ApiLoginResponse> {
return await apiClient.login({
username: username,
password: password,
@ -419,7 +419,7 @@ async function login(username: string, password: string): Promise<ApiLoginRespon
});
}
async function refreshLogin(refreshToken: string): Promise<ApiLoginResponse> {
export async function refreshLogin(refreshToken: string): Promise<ApiLoginResponse> {
return await apiClient.login({
refreshToken: refreshToken
}, {
@ -429,7 +429,7 @@ async function refreshLogin(refreshToken: string): Promise<ApiLoginResponse> {
});
}
async function getUserDataFromToken(token: string): Promise<User> {
export async function getUserDataFromToken(token: string): Promise<User> {
return apiClient.getUserData({}, {
metadata: grpc.Metadata({
'X-API-Key': apiKey,
@ -438,7 +438,7 @@ async function getUserDataFromToken(token: string): Promise<User> {
});
}
async function getUserDataFromPid(pid: number): Promise<User> {
export async function getUserDataFromPid(pid: number): Promise<User> {
return accountClient.getUserData({
pid: pid
}, {
@ -451,31 +451,4 @@ async function getUserDataFromPid(pid: number): Promise<User> {
export async function getPid(token: string): Promise<number> {
const user = await getUserDataFromToken(token);
return user.pid;
}
export default {
decodeParamPack,
processServiceToken,
decryptToken,
unpackToken,
processPainting,
nintendoPasswordHash,
getCommunityHash,
getUserHash,
refreshCache,
setName,
resizeImage,
createBMPTgaBuffer,
processLanguage,
uploadCDNAsset,
newNotification,
getFriends,
getFriendRequests,
login,
refreshLogin,
getUserDataFromToken,
getUserDataFromPid,
getPid,
create_user,
INVALID_POST_BODY_REGEX
};
}