mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 12:42:44 +01:00
prettier formatted /api
This commit is contained in:
parent
53949bd737
commit
2ce3fbc652
8
api/.vscode/api-snippets.code-snippets
vendored
8
api/.vscode/api-snippets.code-snippets
vendored
@ -19,11 +19,7 @@
|
|||||||
"Route": {
|
"Route": {
|
||||||
"scope": "typescript",
|
"scope": "typescript",
|
||||||
"prefix": "route",
|
"prefix": "route",
|
||||||
"body": [
|
"body": ["router.get(\"$1\", route({}), (req: Request, res: Response) => {", "\t$2", "});"],
|
||||||
"router.get(\"$1\", route({}), (req: Request, res: Response) => {",
|
|
||||||
"\t$2",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"description": "An API endpoint"
|
"description": "An API endpoint"
|
||||||
},
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -10,10 +10,7 @@ router.post("/", route({ permission: "MANAGE_MESSAGES" }), (req: Request, res: R
|
|||||||
type: 0,
|
type: 0,
|
||||||
content: "",
|
content: "",
|
||||||
channel_id: "",
|
channel_id: "",
|
||||||
author: {id: "",
|
author: { id: "", username: "", avatar: "", discriminator: "", public_flags: 64 },
|
||||||
username: "",
|
|
||||||
avatar: "",
|
|
||||||
discriminator: "", public_flags: 64},
|
|
||||||
attachments: [],
|
attachments: [],
|
||||||
embeds: [],
|
embeds: [],
|
||||||
mentions: [],
|
mentions: [],
|
||||||
@ -23,8 +20,9 @@ router.post("/", route({ permission: "MANAGE_MESSAGES" }), (req: Request, res: R
|
|||||||
tts: false,
|
tts: false,
|
||||||
timestamp: "",
|
timestamp: "",
|
||||||
edited_timestamp: null,
|
edited_timestamp: null,
|
||||||
flags: 1, components: []}).status(200);
|
flags: 1,
|
||||||
|
components: []
|
||||||
|
}).status(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Channel, ChannelRecipientAddEvent, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util";
|
import {
|
||||||
import { route } from "@fosscord/api"
|
Channel,
|
||||||
|
ChannelRecipientAddEvent,
|
||||||
|
ChannelType,
|
||||||
|
DiscordApiErrors,
|
||||||
|
DmChannelDTO,
|
||||||
|
emitEvent,
|
||||||
|
PublicUserProjection,
|
||||||
|
Recipient,
|
||||||
|
User
|
||||||
|
} from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -9,20 +19,17 @@ router.put("/:user_id", route({}), async (req: Request, res: Response) => {
|
|||||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
||||||
|
|
||||||
if (channel.type !== ChannelType.GROUP_DM) {
|
if (channel.type !== ChannelType.GROUP_DM) {
|
||||||
const recipients = [
|
const recipients = [...channel.recipients!.map((r) => r.user_id), user_id].unique();
|
||||||
...channel.recipients!.map(r => r.user_id),
|
|
||||||
user_id
|
|
||||||
].unique()
|
|
||||||
|
|
||||||
const new_channel = await Channel.createDMChannel(recipients, req.user_id)
|
const new_channel = await Channel.createDMChannel(recipients, req.user_id);
|
||||||
return res.status(201).json(new_channel);
|
return res.status(201).json(new_channel);
|
||||||
} else {
|
} else {
|
||||||
if (channel.recipients!.map(r => r.user_id).includes(user_id)) {
|
if (channel.recipients!.map((r) => r.user_id).includes(user_id)) {
|
||||||
throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error?
|
throw DiscordApiErrors.INVALID_RECIPIENT; //TODO is this the right error?
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.recipients!.push(new Recipient({ channel_id: channel_id, user_id: user_id }));
|
channel.recipients!.push(new Recipient({ channel_id: channel_id, user_id: user_id }));
|
||||||
await channel.save()
|
await channel.save();
|
||||||
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "CHANNEL_CREATE",
|
event: "CHANNEL_CREATE",
|
||||||
@ -31,10 +38,12 @@ router.put("/:user_id", route({}), async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "CHANNEL_RECIPIENT_ADD", data: {
|
event: "CHANNEL_RECIPIENT_ADD",
|
||||||
|
data: {
|
||||||
channel_id: channel_id,
|
channel_id: channel_id,
|
||||||
user: await User.findOneOrFail({ where: { id: user_id }, select: PublicUserProjection })
|
user: await User.findOneOrFail({ where: { id: user_id }, select: PublicUserProjection })
|
||||||
}, channel_id: channel_id
|
},
|
||||||
|
channel_id: channel_id
|
||||||
} as ChannelRecipientAddEvent);
|
} as ChannelRecipientAddEvent);
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
}
|
}
|
||||||
@ -44,13 +53,13 @@ router.delete("/:user_id", route({}), async (req: Request, res: Response) => {
|
|||||||
const { channel_id, user_id } = req.params;
|
const { channel_id, user_id } = req.params;
|
||||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
||||||
if (!(channel.type === ChannelType.GROUP_DM && (channel.owner_id === req.user_id || user_id === req.user_id)))
|
if (!(channel.type === ChannelType.GROUP_DM && (channel.owner_id === req.user_id || user_id === req.user_id)))
|
||||||
throw DiscordApiErrors.MISSING_PERMISSIONS
|
throw DiscordApiErrors.MISSING_PERMISSIONS;
|
||||||
|
|
||||||
if (!channel.recipients!.map(r => r.user_id).includes(user_id)) {
|
if (!channel.recipients!.map((r) => r.user_id).includes(user_id)) {
|
||||||
throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error?
|
throw DiscordApiErrors.INVALID_RECIPIENT; //TODO is this the right error?
|
||||||
}
|
}
|
||||||
|
|
||||||
await Channel.removeRecipientFromChannel(channel, user_id)
|
await Channel.removeRecipientFromChannel(channel, user_id);
|
||||||
|
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,6 @@ import { Guild, Config } from "@fosscord/util";
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
@ -12,7 +11,9 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
// ! this only works using SQL querys
|
// ! this only works using SQL querys
|
||||||
// TODO: implement this with default typeorm query
|
// TODO: implement this with default typeorm query
|
||||||
// const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) });
|
// const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) });
|
||||||
const guilds = showAllGuilds ? await Guild.find({take: Math.abs(Number(limit || 20))}) : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 20)) });
|
const guilds = showAllGuilds
|
||||||
|
? await Guild.find({ take: Math.abs(Number(limit || 20)) })
|
||||||
|
: await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 20)) });
|
||||||
res.send({ guilds: guilds });
|
res.send({ guilds: guilds });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export interface GatewayBotResponse {
|
|||||||
remaining: number;
|
remaining: number;
|
||||||
reset_after: number;
|
reset_after: number;
|
||||||
max_concurrency: number;
|
max_concurrency: number;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: RouteOptions = {
|
const options: RouteOptions = {
|
||||||
|
@ -18,7 +18,8 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
currency: "eur",
|
currency: "eur",
|
||||||
price: 4199,
|
price: 4199,
|
||||||
price_tier: null
|
price_tier: null
|
||||||
}]).status(200);
|
}
|
||||||
|
]).status(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -4,10 +4,127 @@ import { route } from "@fosscord/api";
|
|||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
const skus = new Map([
|
const skus = new Map([
|
||||||
["521842865731534868", [{"id": "511651856145973248", "name": "Premium Monthly (Legacy)", "interval": 1, "interval_count": 1, "tax_inclusive": true, "sku_id": "521842865731534868", "currency": "usd", "price": 0, "price_tier": null}, {"id": "511651860671627264", "name": "Premium Yearly (Legacy)", "interval": 2, "interval_count": 1, "tax_inclusive": true, "sku_id": "521842865731534868", "currency": "usd", "price": 0, "price_tier": null}]],
|
[
|
||||||
["521846918637420545", [{"id": "511651871736201216", "name": "Premium Classic Monthly", "interval": 1, "interval_count": 1, "tax_inclusive": true, "sku_id": "521846918637420545", "currency": "usd", "price": 0, "price_tier": null}, {"id": "511651876987469824", "name": "Premium Classic Yearly", "interval": 2, "interval_count": 1, "tax_inclusive": true, "sku_id": "521846918637420545", "currency": "usd", "price": 0, "price_tier": null}]],
|
"521842865731534868",
|
||||||
["521847234246082599", [{"id": "642251038925127690", "name": "Premium Quarterly", "interval": 1, "interval_count": 3, "tax_inclusive": true, "sku_id": "521847234246082599", "currency": "usd", "price": 0, "price_tier": null}, {"id": "511651880837840896", "name": "Premium Monthly", "interval": 1, "interval_count": 1, "tax_inclusive": true, "sku_id": "521847234246082599", "currency": "usd", "price": 0, "price_tier": null}, {"id": "511651885459963904", "name": "Premium Yearly", "interval": 2, "interval_count": 1, "tax_inclusive": true, "sku_id": "521847234246082599", "currency": "usd", "price": 0, "price_tier": null}]],
|
[
|
||||||
["590663762298667008", [{"id": "590665532894740483", "name": "Server Boost Monthly", "interval": 1, "interval_count": 1, "tax_inclusive": true, "sku_id": "590663762298667008", "discount_price": 0, "currency": "usd", "price": 0, "price_tier": null}, {"id": "590665538238152709", "name": "Server Boost Yearly", "interval": 2, "interval_count": 1, "tax_inclusive": true, "sku_id": "590663762298667008", "discount_price": 0, "currency": "usd", "price": 0, "price_tier": null}]],
|
{
|
||||||
|
id: "511651856145973248",
|
||||||
|
name: "Premium Monthly (Legacy)",
|
||||||
|
interval: 1,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521842865731534868",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "511651860671627264",
|
||||||
|
name: "Premium Yearly (Legacy)",
|
||||||
|
interval: 2,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521842865731534868",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"521846918637420545",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "511651871736201216",
|
||||||
|
name: "Premium Classic Monthly",
|
||||||
|
interval: 1,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521846918637420545",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "511651876987469824",
|
||||||
|
name: "Premium Classic Yearly",
|
||||||
|
interval: 2,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521846918637420545",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"521847234246082599",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "642251038925127690",
|
||||||
|
name: "Premium Quarterly",
|
||||||
|
interval: 1,
|
||||||
|
interval_count: 3,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521847234246082599",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "511651880837840896",
|
||||||
|
name: "Premium Monthly",
|
||||||
|
interval: 1,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521847234246082599",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "511651885459963904",
|
||||||
|
name: "Premium Yearly",
|
||||||
|
interval: 2,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "521847234246082599",
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"590663762298667008",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "590665532894740483",
|
||||||
|
name: "Server Boost Monthly",
|
||||||
|
interval: 1,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "590663762298667008",
|
||||||
|
discount_price: 0,
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "590665538238152709",
|
||||||
|
name: "Server Boost Yearly",
|
||||||
|
interval: 2,
|
||||||
|
interval_count: 1,
|
||||||
|
tax_inclusive: true,
|
||||||
|
sku_id: "590663762298667008",
|
||||||
|
discount_price: 0,
|
||||||
|
currency: "usd",
|
||||||
|
price: 0,
|
||||||
|
price_tier: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
@ -5,7 +5,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.get("/", route({}), (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.json([]).status(200)
|
res.json([]).status(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -5,7 +5,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.get("/", route({}), (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.json([]).status(200)
|
res.json([]).status(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -5,8 +5,11 @@ import { route } from "@fosscord/api";
|
|||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const recipients = await Recipient.find({ where: { user_id: req.user_id, closed: false }, relations: ["channel", "channel.recipients"] });
|
const recipients = await Recipient.find({
|
||||||
res.json(await Promise.all(recipients.map(r => DmChannelDTO.from(r.channel, [req.user_id]))));
|
where: { user_id: req.user_id, closed: false },
|
||||||
|
relations: ["channel", "channel.recipients"]
|
||||||
|
});
|
||||||
|
res.json(await Promise.all(recipients.map((r) => DmChannelDTO.from(r.channel, [req.user_id]))));
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface DmChannelCreateSchema {
|
export interface DmChannelCreateSchema {
|
||||||
|
@ -11,7 +11,8 @@ router.get("/", route({}), (req: Request, res: Response) => {
|
|||||||
communication: true,
|
communication: true,
|
||||||
tips: false,
|
tips: false,
|
||||||
updates_and_announcements: false,
|
updates_and_announcements: false,
|
||||||
recommendations_and_events: false },
|
recommendations_and_events: false
|
||||||
|
},
|
||||||
initialized: false
|
initialized: false
|
||||||
}).status(200);
|
}).status(200);
|
||||||
});
|
});
|
||||||
|
@ -81,7 +81,6 @@ export function getIpAdress(req: Request): string {
|
|||||||
return req.headers[Config.get().security.forwadedFor] || req.socket.remoteAddress;
|
return req.headers[Config.get().security.forwadedFor] || req.socket.remoteAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function distanceBetweenLocations(loc1: any, loc2: any): number {
|
export function distanceBetweenLocations(loc1: any, loc2: any): number {
|
||||||
return distanceBetweenCoords(loc1.latitude, loc1.longitude, loc2.latitude, loc2.longitude);
|
return distanceBetweenCoords(loc1.latitude, loc1.longitude, loc2.latitude, loc2.longitude);
|
||||||
}
|
}
|
||||||
@ -90,9 +89,7 @@ export function distanceBetweenLocations(loc1: any, loc2: any): number {
|
|||||||
function distanceBetweenCoords(lat1: number, lon1: number, lat2: number, lon2: number) {
|
function distanceBetweenCoords(lat1: number, lon1: number, lat2: number, lon2: number) {
|
||||||
const p = 0.017453292519943295; // Math.PI / 180
|
const p = 0.017453292519943295; // Math.PI / 180
|
||||||
const c = Math.cos;
|
const c = Math.cos;
|
||||||
const a = 0.5 - c((lat2 - lat1) * p) / 2 +
|
const a = 0.5 - c((lat2 - lat1) * p) / 2 + (c(lat1 * p) * c(lat2 * p) * (1 - c((lon2 - lon1) * p))) / 2;
|
||||||
c(lat1 * p) * c(lat2 * p) *
|
|
||||||
(1 - c((lon2 - lon1) * p)) / 2;
|
|
||||||
|
|
||||||
return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
|
return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user