Merge branch 'master' of https://github.com/discord-open-source/discord-api
This commit is contained in:
commit
91f2e73da0
69
package-lock.json
generated
69
package-lock.json
generated
@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-api",
|
"name": "fosscord-api",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord-api",
|
"name": "fosscord-api",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^5.0.0",
|
"bcrypt": "^5.0.0",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"discord-server-util": "github:discord-open-source/discord-server-util",
|
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-validator": "^6.9.2",
|
"express-validator": "^6.9.2",
|
||||||
|
"fosscord-server-util": "git+https://github.com/fosscord/fosscord-server-util.git",
|
||||||
"i18next": "^19.8.5",
|
"i18next": "^19.8.5",
|
||||||
"i18next-http-middleware": "^3.1.0",
|
"i18next-http-middleware": "^3.1.0",
|
||||||
"i18next-node-fs-backend": "^2.1.3",
|
"i18next-node-fs-backend": "^2.1.3",
|
||||||
@ -562,16 +562,6 @@
|
|||||||
"node": ">=0.3.1"
|
"node": ">=0.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/discord-server-util": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "git+ssh://git@github.com/discord-open-source/discord-server-util.git#6ab626fc0dcb4ce62345c9ee967ba300474728e2",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"jsonwebtoken": "^8.5.1",
|
|
||||||
"lambert-db": "^1.1.4",
|
|
||||||
"missing-native-js-functions": "^1.2.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/ecdsa-sig-formatter": {
|
"node_modules/ecdsa-sig-formatter": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||||
@ -786,6 +776,26 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fosscord-server-util": {
|
||||||
|
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#def655c738c5968af1722e5d32c5e8ec83327527",
|
||||||
|
"dependencies": {
|
||||||
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
"lambert-db": "^1.1.7",
|
||||||
|
"missing-native-js-functions": "^1.2.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/fosscord-server-util/node_modules/lambert-db": {
|
||||||
|
"version": "1.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.7.tgz",
|
||||||
|
"integrity": "sha512-OJzXySr/eISttGbkB3uE4ybJW8H/eO1lKWzCt0R38OBuMKnVBfCDO3yOQCXiIzjk9kXOggL4vsKy3OujLDXoDg==",
|
||||||
|
"dependencies": {
|
||||||
|
"missing-native-js-functions": "^1.1.8",
|
||||||
|
"mongodb": "^3.6.2",
|
||||||
|
"mongodb-memory-server": "^6.9.2",
|
||||||
|
"mongoose": "^5.11.8",
|
||||||
|
"rethinkdb-ts": "^2.4.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fresh": {
|
"node_modules/fresh": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||||
@ -1341,6 +1351,7 @@
|
|||||||
"version": "6.9.3",
|
"version": "6.9.3",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-6.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-6.9.3.tgz",
|
||||||
"integrity": "sha512-VU2ey+fknmZflHltPCznZr9fja8T6K7DTG5m7wSxmQC/Qf/kkKmRGqIPcZoEU5znRR/8m/EaOe+hFWkjmh1W5A==",
|
"integrity": "sha512-VU2ey+fknmZflHltPCznZr9fja8T6K7DTG5m7wSxmQC/Qf/kkKmRGqIPcZoEU5znRR/8m/EaOe+hFWkjmh1W5A==",
|
||||||
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mongodb-memory-server-core": "6.9.3"
|
"mongodb-memory-server-core": "6.9.3"
|
||||||
}
|
}
|
||||||
@ -2801,15 +2812,6 @@
|
|||||||
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"discord-server-util": {
|
|
||||||
"version": "git+ssh://git@github.com/discord-open-source/discord-server-util.git#6ab626fc0dcb4ce62345c9ee967ba300474728e2",
|
|
||||||
"from": "discord-server-util@github:discord-open-source/discord-server-util",
|
|
||||||
"requires": {
|
|
||||||
"jsonwebtoken": "^8.5.1",
|
|
||||||
"lambert-db": "^1.1.4",
|
|
||||||
"missing-native-js-functions": "^1.2.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ecdsa-sig-formatter": {
|
"ecdsa-sig-formatter": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||||
@ -2994,6 +2996,29 @@
|
|||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
|
||||||
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
||||||
},
|
},
|
||||||
|
"fosscord-server-util": {
|
||||||
|
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#def655c738c5968af1722e5d32c5e8ec83327527",
|
||||||
|
"from": "fosscord-server-util@git+https://github.com/fosscord/fosscord-server-util.git",
|
||||||
|
"requires": {
|
||||||
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
"lambert-db": "^1.1.7",
|
||||||
|
"missing-native-js-functions": "^1.2.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"lambert-db": {
|
||||||
|
"version": "1.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.7.tgz",
|
||||||
|
"integrity": "sha512-OJzXySr/eISttGbkB3uE4ybJW8H/eO1lKWzCt0R38OBuMKnVBfCDO3yOQCXiIzjk9kXOggL4vsKy3OujLDXoDg==",
|
||||||
|
"requires": {
|
||||||
|
"missing-native-js-functions": "^1.1.8",
|
||||||
|
"mongodb": "^3.6.2",
|
||||||
|
"mongodb-memory-server": "^6.9.2",
|
||||||
|
"mongoose": "^5.11.8",
|
||||||
|
"rethinkdb-ts": "^2.4.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"fresh": {
|
"fresh": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||||
|
10
package.json
10
package.json
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-api",
|
"name": "fosscord-api",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "This repository contains the HTTP API Server",
|
"description": "This repository contains the HTTP API Server",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
@ -10,21 +10,21 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/discord-open-source/discord-api.git"
|
"url": "git+https://github.com/fosscord/fosscord-api.git"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/discord-open-source/discord-api/issues"
|
"url": "https://github.com/fosscord/fosscord-api/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/discord-open-source/discord-api#readme",
|
"homepage": "https://github.com/fosscord/fosscord-api#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^5.0.0",
|
"bcrypt": "^5.0.0",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"discord-server-util": "github:discord-open-source/discord-server-util",
|
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-validator": "^6.9.2",
|
"express-validator": "^6.9.2",
|
||||||
|
"fosscord-server-util": "git+https://github.com/fosscord/fosscord-server-util.git",
|
||||||
"i18next": "^19.8.5",
|
"i18next": "^19.8.5",
|
||||||
"i18next-http-middleware": "^3.1.0",
|
"i18next-http-middleware": "^3.1.0",
|
||||||
"i18next-node-fs-backend": "^2.1.3",
|
"i18next-node-fs-backend": "^2.1.3",
|
||||||
|
@ -3,7 +3,7 @@ import fs from "fs/promises";
|
|||||||
import { Server, ServerOptions } from "lambert-server";
|
import { Server, ServerOptions } from "lambert-server";
|
||||||
import { Authentication, GlobalRateLimit } from "./middlewares/";
|
import { Authentication, GlobalRateLimit } from "./middlewares/";
|
||||||
import Config from "./util/Config";
|
import Config from "./util/Config";
|
||||||
import { db } from "discord-server-util";
|
import { db } from "fosscord-server-util";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import i18nextMiddleware, { I18next } from "i18next-http-middleware";
|
import i18nextMiddleware, { I18next } from "i18next-http-middleware";
|
||||||
import i18nextBackend from "i18next-node-fs-backend";
|
import i18nextBackend from "i18next-node-fs-backend";
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { checkToken } from "discord-server-util";
|
import { checkToken } from "fosscord-server-util";
|
||||||
|
|
||||||
export const NO_AUTHORIZATION_ROUTES = ["/api/v8/auth/login", "/api/v8/auth/register"];
|
export const NO_AUTHORIZATION_ROUTES = ["/api/v8/auth/login", "/api/v8/auth/register"];
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import Config from "../util/Config";
|
import Config from "../util/Config";
|
||||||
import { db } from "discord-server-util";
|
import { db } from "fosscord-server-util";
|
||||||
|
|
||||||
// TODO: use mongodb ttl index
|
// TODO: use mongodb ttl index
|
||||||
// TODO: increment count on serverside
|
// TODO: increment count on serverside
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { db } from "discord-server-util";
|
import { db } from "fosscord-server-util";
|
||||||
|
|
||||||
import { getIpAdress } from "./GlobalRateLimit";
|
import { getIpAdress } from "./GlobalRateLimit";
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { Request, Response, Router } from "express";
|
|||||||
import { check, FieldErrors, Length } from "../../../../util/instanceOf";
|
import { check, FieldErrors, Length } from "../../../../util/instanceOf";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import { db, User } from "discord-server-util";
|
import { db, User } from "fosscord-server-util";
|
||||||
import Config from "../../../../util/Config";
|
import Config from "../../../../util/Config";
|
||||||
import { adjustEmail } from "./register";
|
import { adjustEmail } from "./register";
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import Config from "../../../../util/Config";
|
import Config from "../../../../util/Config";
|
||||||
import { db, trimSpecial, User, Snowflake } from "discord-server-util";
|
import { db, trimSpecial, User, Snowflake } from "fosscord-server-util";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import { check, Email, EMAIL_REGEX, FieldErrors, Length } from "../../../../util/instanceOf";
|
import { check, Email, EMAIL_REGEX, FieldErrors, Length } from "../../../../util/instanceOf";
|
||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
@ -177,6 +177,7 @@ router.post(
|
|||||||
email: adjusted_email,
|
email: adjusted_email,
|
||||||
flags: 0n, // TODO: generate default flags
|
flags: 0n, // TODO: generate default flags
|
||||||
hash: adjusted_password,
|
hash: adjusted_password,
|
||||||
|
guilds: [],
|
||||||
valid_tokens_since: Date.now(),
|
valid_tokens_since: Date.now(),
|
||||||
user_settings: {
|
user_settings: {
|
||||||
afk_timeout: 300,
|
afk_timeout: 300,
|
||||||
|
@ -1,4 +1,152 @@
|
|||||||
import { Router } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
|
import { db, GuildSchema, Guild, Snowflake } from "fosscord-server-util";
|
||||||
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { check } from "./../../../../util/instanceOf";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/:id", async (req: Request, res: Response) => {
|
||||||
|
const member = await db.data.guilds({ id: req.params.id }).members({ id: req.userid }).get({ id: true });
|
||||||
|
|
||||||
|
if (!member) {
|
||||||
|
throw new HTTPError("you arent a member of the guild you are trying to access", 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
const guild = await db.data.guilds({ id: req.params.id }).get({
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
icon: true,
|
||||||
|
// icon_hash: true,
|
||||||
|
splash: true,
|
||||||
|
discovery_splash: true,
|
||||||
|
owner: true,
|
||||||
|
owner_id: true,
|
||||||
|
permissions: true,
|
||||||
|
region: true,
|
||||||
|
afk_channel_id: true,
|
||||||
|
afk_timeout: true,
|
||||||
|
widget_enabled: true,
|
||||||
|
widget_channel_id: true,
|
||||||
|
verification_level: true,
|
||||||
|
default_message_notifications: true,
|
||||||
|
explicit_content_filter: true,
|
||||||
|
roles: true,
|
||||||
|
emojis: true,
|
||||||
|
features: true,
|
||||||
|
mfa_level: true,
|
||||||
|
application_id: true,
|
||||||
|
system_channel_id: true,
|
||||||
|
system_channel_flags: true,
|
||||||
|
rules_channel_id: true,
|
||||||
|
joined_at: true,
|
||||||
|
// large: true,
|
||||||
|
// unavailable: true,
|
||||||
|
member_count: true,
|
||||||
|
// voice_states: true,
|
||||||
|
// members: true,
|
||||||
|
// channels: true,
|
||||||
|
// presences: true,
|
||||||
|
max_presences: true,
|
||||||
|
max_members: true,
|
||||||
|
vanity_url_code: true,
|
||||||
|
description: true,
|
||||||
|
banner: true,
|
||||||
|
premium_tier: true,
|
||||||
|
premium_subscription_count: true,
|
||||||
|
preferred_locale: true,
|
||||||
|
public_updates_channel_id: true,
|
||||||
|
max_video_channel_users: true,
|
||||||
|
approximate_member_count: true,
|
||||||
|
approximate_presence_count: true,
|
||||||
|
// welcome_screen: true,
|
||||||
|
});
|
||||||
|
return res.json(guild);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: add addGuildSchema & createGuildSchema
|
||||||
|
// router.put("/:id", check(GuildSchema), async (req: Request, res: Response) => {});
|
||||||
|
|
||||||
|
// // TODO: finish POST route
|
||||||
|
router.post("/", check(GuildSchema), async (req: Request, res: Response) => {
|
||||||
|
const body = req.body as GuildSchema;
|
||||||
|
const guildID = Snowflake.generate();
|
||||||
|
const guild: Guild = {
|
||||||
|
...body, // ! contains name & icon values
|
||||||
|
afk_channel_id: undefined,
|
||||||
|
afk_timeout: undefined,
|
||||||
|
application_id: undefined,
|
||||||
|
approximate_member_count: undefined,
|
||||||
|
approximate_presence_count: undefined,
|
||||||
|
banner: undefined,
|
||||||
|
channels: [],
|
||||||
|
default_message_notifications: undefined,
|
||||||
|
description: undefined,
|
||||||
|
discovery_splash: undefined,
|
||||||
|
emojis: [],
|
||||||
|
explicit_content_filter: undefined,
|
||||||
|
features: [],
|
||||||
|
// icon: undefined,
|
||||||
|
id: guildID,
|
||||||
|
// joined_at: undefined,
|
||||||
|
large: undefined,
|
||||||
|
max_members: undefined,
|
||||||
|
max_presences: undefined,
|
||||||
|
max_video_channel_users: undefined,
|
||||||
|
member_count: undefined,
|
||||||
|
members: undefined,
|
||||||
|
mfa_level: undefined,
|
||||||
|
// name: undefined,
|
||||||
|
owner_id: req.userid, // ! important
|
||||||
|
// owner: undefined,
|
||||||
|
permissions: undefined,
|
||||||
|
preferred_locale: undefined,
|
||||||
|
premium_subscription_count: undefined,
|
||||||
|
premium_tier: undefined,
|
||||||
|
presences: [],
|
||||||
|
public_updates_channel_id: undefined,
|
||||||
|
region: undefined,
|
||||||
|
roles: [],
|
||||||
|
rules_channel_id: undefined,
|
||||||
|
splash: undefined,
|
||||||
|
system_channel_flags: undefined,
|
||||||
|
system_channel_id: undefined,
|
||||||
|
unavailable: undefined,
|
||||||
|
vanity_url_code: undefined,
|
||||||
|
verification_level: undefined,
|
||||||
|
voice_states: [],
|
||||||
|
welcome_screen: [],
|
||||||
|
widget_channel_id: undefined,
|
||||||
|
widget_enabled: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.data.guilds.push(guild);
|
||||||
|
} catch (error) {
|
||||||
|
throw new HTTPError("Couldnt create Guild", 500);
|
||||||
|
}
|
||||||
|
res.status(201).json({ id: guild.id });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete("/:id", async (req: Request, res: Response) => {
|
||||||
|
const { id: guildID } = req.params;
|
||||||
|
|
||||||
|
const guild = await db.data.guilds({ id: guildID }).get({ owner_id: true });
|
||||||
|
|
||||||
|
if (!guild) {
|
||||||
|
throw new HTTPError("This guild doesnt exist", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guild.owner_id !== req.userid) {
|
||||||
|
throw new HTTPError("You arent the owner of this guild", 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.data.guilds({ id: guildID }).delete();
|
||||||
|
} catch (error) {
|
||||||
|
throw new HTTPError(`Couldnt delete guild: ${error}`, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(204);
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { Long } from "mongodb";
|
import { Long } from "mongodb";
|
||||||
import { Snowflake } from "discord-server-util";
|
import { Snowflake } from "fosscord-server-util";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const conn = await mongoose.createConnection(
|
const conn = await mongoose.createConnection(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Config } from "discord-server-util";
|
import { Config } from "fosscord-server-util";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user