mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-12 16:44:54 +00:00
State update, havent tested
This commit is contained in:
+2
-1
@@ -15,4 +15,5 @@ api/assets/plugins/*.js
|
||||
|
||||
|
||||
*.log
|
||||
*.log.ansi
|
||||
*.log.ansi
|
||||
bundle/depclean.*
|
||||
+2
-15
@@ -39,52 +39,39 @@
|
||||
"@babel/core": "^7.18.9",
|
||||
"@babel/preset-env": "^7.18.9",
|
||||
"@babel/preset-typescript": "^7.15.0",
|
||||
"@ovos-media/ts-transform-paths": "^1.7.18-1",
|
||||
"@types/amqplib": "^0.8.1",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/express": "^4.17.9",
|
||||
"@types/i18next-node-fs-backend": "^2.1.0",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/jest-expect-message": "^1.0.3",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/morgan": "^1.9.3",
|
||||
"@types/multer": "^1.4.5",
|
||||
"@types/node": "^18.0.6",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"jest": "^28.1.3",
|
||||
"jest-expect-message": "^1.0.2",
|
||||
"jest-runtime": "^28.1.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"ts-patch": "^2.0.1",
|
||||
"typescript": "^4.4.2",
|
||||
"typescript-json-schema": "^0.54.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/preset-typescript": "^7.15.0",
|
||||
"@fosscord/util": "file:../util",
|
||||
"@sentry/node": "^7.7.0",
|
||||
"@sentry/tracing": "^7.7.0",
|
||||
"ajv": "8.6.2",
|
||||
"ajv-formats": "^2.1.1",
|
||||
"amqplib": "^0.10.0",
|
||||
"assert": "^2.0.0",
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"canvas": "^2.9.3",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.17.1",
|
||||
"form-data": "^4.0.0",
|
||||
"i18next": "^21.8.14",
|
||||
"i18next-http-middleware": "^3.1.3",
|
||||
"i18next-node-fs-backend": "^2.1.3",
|
||||
"image-size": "^1.0.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-server": "^1.2.12",
|
||||
"missing-native-js-functions": "^1.2.18",
|
||||
"morgan": "^1.10.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"node-2fa": "^2.0.3",
|
||||
"node-fetch": "^2.6.7",
|
||||
"patch-package": "^6.4.7",
|
||||
"picocolors": "^1.0.0",
|
||||
"proxy-agent": "^5.0.0",
|
||||
|
||||
+3
-5
@@ -1,7 +1,6 @@
|
||||
import "missing-native-js-functions";
|
||||
import { Server, ServerOptions } from "lambert-server";
|
||||
import { Authentication, CORS } from "./middlewares/";
|
||||
import { Config, initDatabase, initEvent } from "@fosscord/util";
|
||||
import { Config, initDatabase, initEvent, registerRoutes } from "@fosscord/util";
|
||||
import { ErrorHandler } from "./middlewares/ErrorHandler";
|
||||
import { BodyParser } from "./middlewares/BodyParser";
|
||||
import { Router, Request, Response, NextFunction } from "express";
|
||||
@@ -11,7 +10,6 @@ import TestClient from "./middlewares/TestClient";
|
||||
import { initTranslation } from "./middlewares/Translation";
|
||||
import morgan from "morgan";
|
||||
import { initInstance } from "./util/handlers/Instance";
|
||||
import { registerRoutes } from "@fosscord/util";
|
||||
import { red } from "picocolors"
|
||||
|
||||
export interface FosscordServerOptions extends ServerOptions {}
|
||||
@@ -50,7 +48,7 @@ export class FosscordServer extends Server {
|
||||
}
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
this.app.use(CORS);
|
||||
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
|
||||
@@ -91,4 +89,4 @@ export class FosscordServer extends Server {
|
||||
|
||||
return super.start();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { checkToken, Config, Rights } from "@fosscord/util";
|
||||
|
||||
export const NO_AUTHORIZATION_ROUTES = [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import bodyParser, { OptionsJson } from "body-parser";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
export function BodyParser(opts?: OptionsJson) {
|
||||
const jsonParser = bodyParser.json(opts);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { ApiError, FieldError } from "@fosscord/util";
|
||||
const EntityNotFoundErrorRegex = /"(\w+)"/;
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import express, { Request, Response, Application } from "express";
|
||||
import fs, { writeFile } from "fs";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import fetch, { Response as FetchResponse, Headers } from "node-fetch";
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import { Config } from "@fosscord/util";
|
||||
import { AssetCacheItem } from "../util/entities/AssetCacheItem"
|
||||
import { FileLogger } from "typeorm";
|
||||
|
||||
export default function TestClient(app: Application) {
|
||||
const agent = new ProxyAgent();
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Config, generateToken, Invite, FieldErrors, User, adjustEmail, trimSpecial } from "@fosscord/util";
|
||||
import { route, getIpAdress, IPAnalysis, isProxy } from "@fosscord/api";
|
||||
import "missing-native-js-functions";
|
||||
import bcrypt from "bcrypt";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { random } from "@fosscord/api";
|
||||
import { Channel, Invite, InviteCreateEvent, emitEvent, User, Guild, PublicInviteRelation } from "@fosscord/util";
|
||||
|
||||
@@ -19,7 +19,7 @@ import multer from "multer";
|
||||
import { route } from "@fosscord/api";
|
||||
import { handleMessage, postHandleMessage } from "@fosscord/api";
|
||||
import { MessageCreateSchema } from "../index";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
// TODO: message content/embed string length limit
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { Router, Response, Request } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { In } from "typeorm";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { Channel, Config, emitEvent, getPermission, getRights, MessageDeleteBulkEvent, Message } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { In } from "typeorm";
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
uploadFile,
|
||||
Member
|
||||
} from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
||||
import multer from "multer";
|
||||
import { FindManyOptions, LessThan, MoreThan } from "typeorm";
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
Role
|
||||
} from "@fosscord/util";
|
||||
import { Router, Response, Request } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
import { route } from "@fosscord/api";
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
DiscordApiErrors
|
||||
} from "@fosscord/util";
|
||||
import { Router, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { isTextChannel } from "./messages";
|
||||
import { FindManyOptions, Between, Not } from "typeorm";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { Channel, Config, getPermission, trimSpecial, Webhook } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { isTextChannel } from "./messages/index";
|
||||
import { DiscordApiErrors } from "@fosscord/util";
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Guild, Config } from "@fosscord/util";
|
||||
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { route } from "..";
|
||||
import { Like } from "typeorm";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Categories } from "@fosscord/util";
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { route } from "..";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { route } from "..";
|
||||
import { Release, Config } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { route } from "..";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import fetch from "node-fetch";
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import { route } from "@fosscord/api";
|
||||
import { Config } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Guild, Config } from "@fosscord/util";
|
||||
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { route } from "..";
|
||||
import {Like} from "typeorm"
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { ChannelModifySchema } from "../../channels/#channel_id";
|
||||
const router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { DiscordApiErrors, emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { getIpAdress, route } from "@fosscord/api";
|
||||
|
||||
export interface BanCreateSchema {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { ChannelModifySchema } from "../../channels/#channel_id";
|
||||
const router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Channel, emitEvent, GuildDeleteEvent, Guild, Member, Message, Role, Invite, Emoji } from "@fosscord/util";
|
||||
import { Router, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import "missing-native-js-functions";
|
||||
import { GuildCreateSchema } from "../index";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { ChannelModifySchema } from "../../channels/#channel_id";
|
||||
const router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Member, getPermission, getRights, Role, GuildMemberUpdateEvent, emitEvent, Sticker, Emoji, Rights, Guild } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Request, Response, Router } from "express";
|
||||
import { Guild, Member, PublicMemberProjection } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { MoreThan } from "typeorm";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { Role, Member, GuildRoleUpdateEvent, GuildRoleDeleteEvent, emitEvent, handleFile } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { RoleModifySchema } from "../";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
DiscordApiErrors,
|
||||
handleFile
|
||||
} from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import multer from "multer";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
const router = Router();
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Guild, Template } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { generateCode } from "@fosscord/api";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from "@fosscord/util";
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { ChannelModifySchema } from "../../channels/#channel_id";
|
||||
const router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Guild, getPermission, Snowflake, Member } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Config, Permissions, Guild, Invite, Channel, Member } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { random, route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Guild } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { emitEvent, getPermission, Guild, Invite, InviteDeleteEvent, User, PublicInviteRelation } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router, Request, Response } from "express";
|
||||
import { Guild, Member, User } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import bcrypt from "bcrypt";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { Guild, Member, User, GuildDeleteEvent, GuildMemberRemoveEvent, emitEvent, Config } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
Config
|
||||
} from "@fosscord/util";
|
||||
import { Router, Response, Request } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { DiscordApiErrors } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
process.on("uncaughtException", console.error);
|
||||
process.on("unhandledRejection", console.error);
|
||||
|
||||
import "missing-native-js-functions";
|
||||
import { config } from "dotenv";
|
||||
config();
|
||||
import { FosscordServer } from "./Server";
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
Attachment,
|
||||
Config,
|
||||
} from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import fetch from "node-fetch";
|
||||
import cheerio from "cheerio";
|
||||
import { MessageCreateSchema } from "../../routes/channels/#channel_id/messages";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Config } from "@fosscord/util";
|
||||
import "missing-native-js-functions";
|
||||
|
||||
const reNUMBER = /[0-9]/g;
|
||||
const reUPPERCASELETTER = /[A-Z]/g;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
"incremental": true /* Enable incremental compilation */,
|
||||
"incremental": false /* Enable incremental compilation */,
|
||||
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
|
||||
|
||||
Generated
BIN
Binary file not shown.
+6
-61
@@ -26,82 +26,27 @@
|
||||
},
|
||||
"homepage": "https://fosscord.com",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.9",
|
||||
"@babel/preset-env": "^7.18.9",
|
||||
"@babel/preset-typescript": "^7.15.0",
|
||||
"@ovos-media/ts-transform-paths": "^1.7.18-1",
|
||||
"@types/amqplib": "^0.8.1",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/btoa": "^1.2.3",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/express": "^4.17.12",
|
||||
"@types/fs-extra": "^9.0.12",
|
||||
"@types/i18next-node-fs-backend": "^2.1.0",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/jest-expect-message": "^1.0.3",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/morgan": "^1.9.3",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/node": "^18.0.6",
|
||||
"@types/node-os-utils": "^1.2.0",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@types/ws": "^8.5.3",
|
||||
"jest": "^28.1.3",
|
||||
"jest-expect-message": "^1.0.2",
|
||||
"jest-runtime": "^28.1.3",
|
||||
"@types/node-os-utils": "^1.3.0",
|
||||
"ts-node": "^10.2.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"ts-patch": "^2.0.1",
|
||||
"tsconfig-paths": "^3.12.0",
|
||||
"typescript": "^4.2.3",
|
||||
"typescript-json-schema": "^0.54.0"
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.36.1",
|
||||
"@aws-sdk/node-http-handler": "^3.36.0",
|
||||
"@babel/preset-env": "^7.15.8",
|
||||
"@babel/preset-typescript": "^7.15.0",
|
||||
"@fosscord/api": "file:../api",
|
||||
"@fosscord/cdn": "file:../cdn",
|
||||
"@fosscord/gateway": "file:../gateway",
|
||||
"@ovos-media/ts-transform-paths": "^1.7.18-1",
|
||||
"@sentry/node": "^7.7.0",
|
||||
"@sentry/tracing": "^7.7.0",
|
||||
"ajv": "8.6.2",
|
||||
"ajv-formats": "^2.1.1",
|
||||
"amqplib": "^0.10.0",
|
||||
"assert": "^2.0.0",
|
||||
"async-exit-hook": "^2.0.1",
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"btoa": "^1.2.1",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"dotenv": "^16.0.1",
|
||||
"exif-be-gone": "^1.2.0",
|
||||
"express": "^4.17.1",
|
||||
"express-async-errors": "^3.1.1",
|
||||
"file-type": "^17.1.2",
|
||||
"form-data": "^4.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"i18next": "^21.8.14",
|
||||
"i18next-http-middleware": "^3.1.3",
|
||||
"i18next-node-fs-backend": "^2.1.3",
|
||||
"image-size": "^1.0.0",
|
||||
"jest": "^28.1.3",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-db": "^1.2.3",
|
||||
"lambert-server": "^1.2.11",
|
||||
"missing-native-js-functions": "^1.2.18",
|
||||
"morgan": "^1.10.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"nan": "^2.15.0",
|
||||
"nanocolors": "^0.2.12",
|
||||
"node-2fa": "^2.0.3",
|
||||
"node-os-utils": "^1.3.5",
|
||||
"express": "^4.18.1",
|
||||
"node-fetch": "^2.6.7",
|
||||
"node-os-utils": "^1.3.7",
|
||||
"patch-package": "^6.4.7",
|
||||
"pg": "^8.7.3",
|
||||
"picocolors": "^1.0.0",
|
||||
"proxy-agent": "^5.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sqlite3": "^4.2.0",
|
||||
"supertest": "^6.1.6",
|
||||
|
||||
+4
-15
@@ -21,38 +21,27 @@
|
||||
},
|
||||
"homepage": "https://github.com/fosscord/fosscord-server#readme",
|
||||
"devDependencies": {
|
||||
"@ovos-media/ts-transform-paths": "^1.7.18-1",
|
||||
"@types/amqplib": "^0.8.1",
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/btoa": "^1.2.3",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/express": "^4.17.12",
|
||||
"@types/fs-extra": "^9.0.12",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/node": "^18.0.6",
|
||||
"ts-patch": "^2.0.1"
|
||||
"@types/node": "^18.0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.36.1",
|
||||
"@aws-sdk/node-http-handler": "^3.36.0",
|
||||
"@fosscord/util": "file:../util",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"btoa": "^1.2.1",
|
||||
"dotenv": "^16.0.1",
|
||||
"exif-be-gone": "^1.2.0",
|
||||
"express": "^4.17.1",
|
||||
"express-async-errors": "^3.1.1",
|
||||
"file-type": "^17.1.2",
|
||||
"form-data": "^4.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"image-size": "^1.0.0",
|
||||
"jest": "^28.1.3",
|
||||
"lambert-db": "^1.2.3",
|
||||
"lambert-server": "^1.2.12",
|
||||
"missing-native-js-functions": "^1.2.17",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"nanocolors": "^0.2.12",
|
||||
"node-fetch": "^2.6.7",
|
||||
"picocolors": "^1.0.0",
|
||||
"supertest": "^6.1.6",
|
||||
"typescript": "^4.1.2"
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router, Response, Request } from "express";
|
||||
import { Config, Snowflake } from "@fosscord/util";
|
||||
import { storage } from "../util/Storage";
|
||||
import FileType from "file-type";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { multer } from "../util/multer";
|
||||
import imageSize from "image-size";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router, Response, Request } from "express";
|
||||
import { Config, Snowflake } from "@fosscord/util";
|
||||
import { storage } from "../util/Storage";
|
||||
import FileType from "file-type";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import crypto from "crypto";
|
||||
import { multer } from "../util/multer";
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import fetch from "node-fetch";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { Snowflake } from "@fosscord/util";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import { Snowflake, Config } from "@fosscord/util";
|
||||
import { storage } from "../util/Storage";
|
||||
import FileType from "file-type";
|
||||
import { Config } from "@fosscord/util";
|
||||
|
||||
// TODO: somehow handle the deletion of images posted to the /external route
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Router, Response, Request } from "express";
|
||||
import { Config, Snowflake } from "@fosscord/util";
|
||||
import { storage } from "../util/Storage";
|
||||
import FileType from "file-type";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "@fosscord/util";
|
||||
import crypto from "crypto";
|
||||
import { multer } from "../util/multer";
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Storage } from "./Storage";
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
//import fse from "fs-extra";
|
||||
import { join, relative, dirname } from "path";
|
||||
import "missing-native-js-functions";
|
||||
import { Readable } from "stream";
|
||||
import ExifTransformer = require("exif-be-gone");
|
||||
|
||||
@@ -36,7 +35,8 @@ export class FileStorage implements Storage {
|
||||
|
||||
async set(path: string, value: any) {
|
||||
path = getPath(path);
|
||||
fse.ensureDirSync(dirname(path));
|
||||
//fse.ensureDirSync(dirname(path));
|
||||
fs.mkdirSync(dirname(path), {recursive: true});
|
||||
|
||||
value = Readable.from(value);
|
||||
const cleaned_file = fs.createWriteStream(path);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { FileStorage } from "./FileStorage";
|
||||
import path from "path";
|
||||
import fse from "fs-extra";
|
||||
//import fse from "fs-extra";
|
||||
import fs from "fs";
|
||||
import { bgCyan, black } from "picocolors";
|
||||
import { S3 } from "@aws-sdk/client-s3";
|
||||
import { S3Storage } from "./S3Storage";
|
||||
@@ -22,7 +23,8 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
|
||||
location = path.join(process.cwd(), "files");
|
||||
}
|
||||
console.log(`[CDN] storage location: ${bgCyan(`${black(location)}`)}`);
|
||||
fse.ensureDirSync(location);
|
||||
//fse.ensureDirSync(location);
|
||||
fs.mkdirSync(location, {recursive: true});
|
||||
process.env.STORAGE_LOCATION = location;
|
||||
|
||||
storage = new FileStorage();
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
"incremental": true /* Enable incremental compilation */,
|
||||
"incremental": false /* Enable incremental compilation */,
|
||||
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": [
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
"author": "Fosscord",
|
||||
"license": "AGPL-3.0-only",
|
||||
"devDependencies": {
|
||||
"@ovos-media/ts-transform-paths": "^1.7.18-1",
|
||||
"@types/amqplib": "^0.8.1",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/node": "^18.0.6",
|
||||
"@types/ws": "^8.5.3",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
@@ -28,10 +26,6 @@
|
||||
"@fosscord/util": "file:../util",
|
||||
"amqplib": "^0.10.0",
|
||||
"dotenv": "^16.0.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-server": "^1.2.11",
|
||||
"missing-native-js-functions": "^1.2.18",
|
||||
"proxy-agent": "^5.0.0",
|
||||
"typeorm": "^0.3.7",
|
||||
"ws": "^8.8.1"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import "missing-native-js-functions";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { CLOSECODES, OPCODES } from "../util/Constants";
|
||||
import { CLOSECODES } from "../util/Constants";
|
||||
import { WebSocket, Payload } from "@fosscord/gateway";
|
||||
let erlpack: any;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack");
|
||||
} catch (error) {}
|
||||
import OPCodeHandlers from "../opcodes";
|
||||
import { Tuple } from "lambert-server";
|
||||
import { check } from "../opcodes/instanceOf";
|
||||
import WS from "ws";
|
||||
|
||||
const PayloadSchema = {
|
||||
op: Number,
|
||||
$d: new Tuple(Object, Number), // or number for heartbeat sequence
|
||||
$d: Object || Number, // or number for heartbeat sequence
|
||||
$s: Number,
|
||||
$t: String,
|
||||
};
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
import { OPCODES } from "../util/Constants";
|
||||
import { Send } from "../util/Send";
|
||||
import { WebSocket } from "@fosscord/gateway";
|
||||
import "missing-native-js-functions";
|
||||
import { Channel as AMQChannel } from "amqplib";
|
||||
import { Recipient } from "@fosscord/util";
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ import { Send } from "../util/Send";
|
||||
import { OPCODES } from "../util/Constants";
|
||||
import { WebSocket, Payload, handlePresenceUpdate } from "@fosscord/gateway";
|
||||
import { check } from "./instanceOf";
|
||||
import "missing-native-js-functions";
|
||||
import { getRepository } from "typeorm";
|
||||
import "missing-native-js-functions";
|
||||
|
||||
// TODO: only show roles/members that have access to this channel
|
||||
// TODO: config: to list all members (even those who are offline) sorted by role, or just those who are online
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { instanceOf } from "lambert-server";
|
||||
import { instanceOf } from "@fosscord/util";
|
||||
import { WebSocket } from "@fosscord/gateway";
|
||||
import { CLOSECODES } from "../util/Constants";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
"incremental": true /* Enable incremental compilation */,
|
||||
"incremental": false /* Enable incremental compilation */,
|
||||
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": [
|
||||
|
||||
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
@@ -37,12 +37,14 @@
|
||||
"ts-node": "^10.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"amqplib": "^0.10.0",
|
||||
"form-data": "^4.0.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-server": "^1.2.12",
|
||||
"missing-native-js-functions": "^1.2.18",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"node-fetch": "^2.6.7",
|
||||
"picocolors": "^1.0.0",
|
||||
"proxy-agent": "^5.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import "reflect-metadata";
|
||||
import { BaseEntity, EntityMetadata, ObjectIdColumn, PrimaryColumn, FindOptionsWhere } from "typeorm";
|
||||
import { Snowflake } from "../util/Snowflake";
|
||||
import "missing-native-js-functions";
|
||||
|
||||
export class BaseClassWithoutId extends BaseEntity {
|
||||
constructor(props?: any) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "ty
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { PublicUserProjection, User } from "./User";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "..";
|
||||
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util";
|
||||
import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
|
||||
import { Recipient } from "./Recipient";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "ty
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { PublicUserProjection, User } from "./User";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "..";
|
||||
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util";
|
||||
import { BitField, BitFieldResolvable, BitFlag } from "../util/BitField";
|
||||
import { Recipient } from "./Recipient";
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
GuildMemberRemoveEvent,
|
||||
GuildMemberUpdateEvent,
|
||||
} from "../interfaces";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "..";
|
||||
import { Role } from "./Role";
|
||||
import { BaseClassWithoutId } from "./BaseClass";
|
||||
import { Ban, PublicGuildRelations } from ".";
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export default fetch;
|
||||
@@ -4,4 +4,3 @@ export * from "./util/index";
|
||||
export * from "./interfaces/index";
|
||||
export * from "./entities/index";
|
||||
export * from "./dtos/index";
|
||||
export * from "./fetch.js";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import "missing-native-js-functions";
|
||||
import fetch from "../fetch";
|
||||
import fetch from "node-fetch";
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import readline from "readline";
|
||||
import fs from "fs/promises";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import "missing-native-js-functions";
|
||||
import { ConfigValue, ConfigEntity, DefaultConfigOptions } from "../entities/Config";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
@@ -58,8 +58,8 @@ export async function listenEvent(event: string, callback: (event: EventOpts) =>
|
||||
process.setMaxListeners(process.getMaxListeners() - 1);
|
||||
};
|
||||
|
||||
const listener = (msg: ProcessEvent) => {
|
||||
msg.type === "event" && msg.id === event && callback({ ...msg.event, cancel });
|
||||
const listener = (message: any) => {
|
||||
message.type === "event" && message.id === event && callback({ ...message.event, cancel });
|
||||
};
|
||||
|
||||
process.addListener("message", listener);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import "missing-native-js-functions";
|
||||
|
||||
export function FieldErrors(fields: Record<string, { code?: string; message: string }>) {
|
||||
return new FieldError(
|
||||
50035,
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
// https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js
|
||||
// Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah
|
||||
import { Channel, ChannelPermissionOverwrite, Guild, Member, Role } from "../entities";
|
||||
import { BitField } from "./BitField";
|
||||
import "missing-native-js-functions";
|
||||
import { BitFieldResolvable, BitFlag } from "./BitField";
|
||||
|
||||
let HTTPError: any;
|
||||
|
||||
try {
|
||||
HTTPError = require("lambert-server").HTTPError;
|
||||
} catch (e) {
|
||||
HTTPError = Error;
|
||||
}
|
||||
import { BitField, BitFieldResolvable, BitFlag } from "./BitField";
|
||||
import { HTTPError } from "..";
|
||||
|
||||
export type PermissionResolvable = bigint | number | Permissions | PermissionResolvable[] | PermissionString;
|
||||
|
||||
|
||||
+2
-11
@@ -1,15 +1,6 @@
|
||||
import { BitField } from "./BitField";
|
||||
import "missing-native-js-functions";
|
||||
import { BitFieldResolvable, BitFlag } from "./BitField";
|
||||
import { BitField, BitFieldResolvable, BitFlag } from "./BitField";
|
||||
import { User } from "../entities";
|
||||
|
||||
let HTTPError: any;
|
||||
|
||||
try {
|
||||
HTTPError = require("lambert-server").HTTPError;
|
||||
} catch (e) {
|
||||
HTTPError = Error;
|
||||
}
|
||||
import { HTTPError } from "..";
|
||||
|
||||
export type RightResolvable = bigint | number | Rights | RightResolvable[] | RightString;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import FormData from "form-data";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { HTTPError } from "..";
|
||||
import { Config } from "./Config";
|
||||
import multer from "multer";
|
||||
import fetch from "../fetch"
|
||||
import fetch from "node-fetch"
|
||||
import { nodeModuleNameResolver } from "typescript";
|
||||
|
||||
export async function uploadFile(path: string, file?: Express.Multer.File) {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
//source: https://github.com/Flam3rboy/-server/blob/master/src/check.ts
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { HTTPError } from ".";
|
||||
|
||||
const OPTIONAL_PREFIX = "$";
|
||||
const EMAIL_REGEX =
|
||||
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
|
||||
export function check(schema: any) {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const result = instanceOf(schema, req.body, { path: "body" });
|
||||
if (result === true) return next();
|
||||
throw result;
|
||||
} catch (error) {
|
||||
next(new HTTPError((error as any).toString(), 400));
|
||||
}
|
||||
};
|
||||
}
|
||||
export class Tuple {
|
||||
public types: any[];
|
||||
constructor(...types: any[]) {
|
||||
this.types = types;
|
||||
}
|
||||
}
|
||||
|
||||
export class Email {
|
||||
constructor(public email: string) {}
|
||||
check() {
|
||||
return !!this.email.match(EMAIL_REGEX);
|
||||
}
|
||||
}
|
||||
export function instanceOf(
|
||||
type: any,
|
||||
value: any,
|
||||
{ path = "", optional = false }: { path?: string; optional?: boolean } = {}
|
||||
): boolean {
|
||||
if (!type) return true; // no type was specified
|
||||
|
||||
if (value == null) {
|
||||
if (optional) return true;
|
||||
throw `${path} is required`;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case String:
|
||||
if (typeof value === "string") return true;
|
||||
throw `${path} must be a string`;
|
||||
case Number:
|
||||
value = Number(value);
|
||||
if (typeof value === "number" && !isNaN(value)) return true;
|
||||
throw `${path} must be a number`;
|
||||
case BigInt:
|
||||
try {
|
||||
value = BigInt(value);
|
||||
if (typeof value === "bigint") return true;
|
||||
} catch (error) {}
|
||||
throw `${path} must be a bigint`;
|
||||
case Boolean:
|
||||
if (value == "true") value = true;
|
||||
if (value == "false") value = false;
|
||||
if (typeof value === "boolean") return true;
|
||||
throw `${path} must be a boolean`;
|
||||
case Object:
|
||||
if (typeof value === "object" && value !== null) return true;
|
||||
throw `${path} must be a object`;
|
||||
}
|
||||
|
||||
if (typeof type === "object") {
|
||||
if (Array.isArray(type)) {
|
||||
if (!Array.isArray(value)) throw `${path} must be an array`;
|
||||
if (!type.length) return true; // type array didn't specify any type
|
||||
|
||||
return value.every((val, i) => instanceOf(type[0], val, { path: `${path}[${i}]`, optional }));
|
||||
}
|
||||
if (type?.constructor?.name != "Object") {
|
||||
if (type instanceof Tuple) {
|
||||
if (
|
||||
(<Tuple>type).types.some((x) => {
|
||||
try {
|
||||
return instanceOf(x, value, { path, optional });
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
throw `${path} must be one of ${type.types}`;
|
||||
}
|
||||
if (type instanceof Email) {
|
||||
if ((<Email>type).check()) return true;
|
||||
throw `${path} is not a valid E-Mail`;
|
||||
}
|
||||
if (value instanceof type) return true;
|
||||
throw `${path} must be an instance of ${type}`;
|
||||
}
|
||||
if (typeof value !== "object") throw `${path} must be a object`;
|
||||
|
||||
const diff = Object.keys(value).missing(
|
||||
Object.keys(type).map((x) => (x.startsWith(OPTIONAL_PREFIX) ? x.slice(OPTIONAL_PREFIX.length) : x))
|
||||
);
|
||||
|
||||
if (diff.length) throw `Unkown key ${diff}`;
|
||||
|
||||
return Object.keys(type).every((key) => {
|
||||
let newKey = key;
|
||||
const OPTIONAL = key.startsWith(OPTIONAL_PREFIX);
|
||||
if (OPTIONAL) newKey = newKey.slice(OPTIONAL_PREFIX.length);
|
||||
|
||||
return instanceOf(type[key], value[newKey], {
|
||||
path: `${path}.${newKey}`,
|
||||
optional: OPTIONAL,
|
||||
});
|
||||
});
|
||||
} else if (typeof type === "number" || typeof type === "string" || typeof type === "boolean") {
|
||||
if (value === type) return true;
|
||||
throw `${path} must be ${value}`;
|
||||
} else if (typeof type === "bigint") {
|
||||
if (BigInt(value) === type) return true;
|
||||
throw `${path} must be ${value}`;
|
||||
}
|
||||
|
||||
return type == value;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export class HTTPError extends Error {
|
||||
constructor(message: string, public code: number = 400) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './Checks';
|
||||
export * from './HTTPError';
|
||||
@@ -19,4 +19,6 @@ export * from "./Snowflake";
|
||||
export * from "./String";
|
||||
export * from "./Array";
|
||||
export * from "./TraverseDirectory";
|
||||
export * from "./InvisibleCharacters";
|
||||
export * from "./InvisibleCharacters";
|
||||
|
||||
export * from "./imports/index"
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
"incremental": true /* Enable incremental compilation */,
|
||||
"incremental": false /* Enable incremental compilation */,
|
||||
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
|
||||
|
||||
Reference in New Issue
Block a user