diff options
author | developomp <developomp@gmail.com> | 2021-10-20 09:13:22 +0900 |
---|---|---|
committer | developomp <developomp@gmail.com> | 2021-10-20 09:13:22 +0900 |
commit | 2ce3fbc6525cd8c1ddd060c54f833c5b6a2623c7 (patch) | |
tree | 717ad10f33462c0298733407d8773c595828c32f /api/src | |
parent | prettier formatted /bundle (diff) | |
download | server-2ce3fbc6525cd8c1ddd060c54f833c5b6a2623c7.tar.xz |
prettier formatted /api
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/global.d.ts | 14 | ||||
-rw-r--r-- | api/src/routes/-/healthz.ts | 2 | ||||
-rw-r--r-- | api/src/routes/-/readyz.ts | 2 | ||||
-rw-r--r-- | api/src/routes/applications/#id/entitlements.ts | 2 | ||||
-rw-r--r-- | api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts | 36 | ||||
-rw-r--r-- | api/src/routes/channels/#channel_id/recipients.ts | 41 | ||||
-rw-r--r-- | api/src/routes/discoverable-guilds.ts | 5 | ||||
-rw-r--r-- | api/src/routes/discovery.ts | 2 | ||||
-rw-r--r-- | api/src/routes/gateway/bot.ts | 2 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/prune.ts | 164 | ||||
-rw-r--r-- | api/src/routes/oauth2/tokens.ts | 4 | ||||
-rw-r--r-- | api/src/routes/store/published-listings/applications/#id/subscription-plans.ts | 27 | ||||
-rw-r--r-- | api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts | 129 | ||||
-rw-r--r-- | api/src/routes/users/@me/activities/statistics/applications.ts | 2 | ||||
-rw-r--r-- | api/src/routes/users/@me/billing/payment-sources.ts | 2 | ||||
-rw-r--r-- | api/src/routes/users/@me/channels.ts | 7 | ||||
-rw-r--r-- | api/src/routes/users/@me/email-settings.ts | 15 | ||||
-rw-r--r-- | api/src/util/ipAddress.ts | 9 |
18 files changed, 296 insertions, 169 deletions
diff --git a/api/src/global.d.ts b/api/src/global.d.ts index 3eb70f44..7751af8f 100644 --- a/api/src/global.d.ts +++ b/api/src/global.d.ts @@ -1,8 +1,8 @@ declare global { - namespace Express { - interface Request { - user_id: any; - token: any; - } - } -} \ No newline at end of file + namespace Express { + interface Request { + user_id: any; + token: any; + } + } +} diff --git a/api/src/routes/-/healthz.ts b/api/src/routes/-/healthz.ts index a42575f8..f7bcfebf 100644 --- a/api/src/routes/-/healthz.ts +++ b/api/src/routes/-/healthz.ts @@ -9,7 +9,7 @@ router.get("/", route({}), (req: Request, res: Response) => { // test that the database is alive & responding getConnection(); return res.sendStatus(200); - } catch(e) { + } catch (e) { res.sendStatus(503); } }); diff --git a/api/src/routes/-/readyz.ts b/api/src/routes/-/readyz.ts index a42575f8..f7bcfebf 100644 --- a/api/src/routes/-/readyz.ts +++ b/api/src/routes/-/readyz.ts @@ -9,7 +9,7 @@ router.get("/", route({}), (req: Request, res: Response) => { // test that the database is alive & responding getConnection(); return res.sendStatus(200); - } catch(e) { + } catch (e) { res.sendStatus(503); } }); diff --git a/api/src/routes/applications/#id/entitlements.ts b/api/src/routes/applications/#id/entitlements.ts index 1152e500..cfcfe40f 100644 --- a/api/src/routes/applications/#id/entitlements.ts +++ b/api/src/routes/applications/#id/entitlements.ts @@ -5,7 +5,7 @@ const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { // TODO: - //const { exclude_consumed } = req.query; + //const { exclude_consumed } = req.query; res.status(200).send([]); }); diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts b/api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts index de0c01f1..b2cb6763 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts @@ -6,25 +6,23 @@ const router = Router(); router.post("/", route({ permission: "MANAGE_MESSAGES" }), (req: Request, res: Response) => { // TODO: res.json({ - id: "", - type: 0, - content: "", - channel_id: "", - author: {id: "", - username: "", - avatar: "", - discriminator: "", public_flags: 64}, - attachments: [], - embeds: [], - mentions: [], - mention_roles: [], - pinned: false, - mention_everyone: false, - tts: false, - timestamp: "", - edited_timestamp: null, - flags: 1, components: []}).status(200); + id: "", + type: 0, + content: "", + channel_id: "", + author: { id: "", username: "", avatar: "", discriminator: "", public_flags: 64 }, + attachments: [], + embeds: [], + mentions: [], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "", + edited_timestamp: null, + flags: 1, + components: [] + }).status(200); }); export default router; - diff --git a/api/src/routes/channels/#channel_id/recipients.ts b/api/src/routes/channels/#channel_id/recipients.ts index 83b62049..e6466211 100644 --- a/api/src/routes/channels/#channel_id/recipients.ts +++ b/api/src/routes/channels/#channel_id/recipients.ts @@ -1,6 +1,16 @@ import { Request, Response, Router } from "express"; -import { Channel, ChannelRecipientAddEvent, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util"; -import { route } from "@fosscord/api" +import { + Channel, + ChannelRecipientAddEvent, + ChannelType, + DiscordApiErrors, + DmChannelDTO, + emitEvent, + PublicUserProjection, + Recipient, + User +} from "@fosscord/util"; +import { route } from "@fosscord/api"; 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"] }); if (channel.type !== ChannelType.GROUP_DM) { - const recipients = [ - ...channel.recipients!.map(r => r.user_id), - user_id - ].unique() + const recipients = [...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); } else { - if (channel.recipients!.map(r => r.user_id).includes(user_id)) { - throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error? + if (channel.recipients!.map((r) => r.user_id).includes(user_id)) { + throw DiscordApiErrors.INVALID_RECIPIENT; //TODO is this the right error? } channel.recipients!.push(new Recipient({ channel_id: channel_id, user_id: user_id })); - await channel.save() + await channel.save(); await emitEvent({ event: "CHANNEL_CREATE", @@ -31,10 +38,12 @@ router.put("/:user_id", route({}), async (req: Request, res: Response) => { }); await emitEvent({ - event: "CHANNEL_RECIPIENT_ADD", data: { + event: "CHANNEL_RECIPIENT_ADD", + data: { channel_id: channel_id, user: await User.findOneOrFail({ where: { id: user_id }, select: PublicUserProjection }) - }, channel_id: channel_id + }, + channel_id: channel_id } as ChannelRecipientAddEvent); 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 = 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))) - throw DiscordApiErrors.MISSING_PERMISSIONS + throw DiscordApiErrors.MISSING_PERMISSIONS; - if (!channel.recipients!.map(r => r.user_id).includes(user_id)) { - throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error? + if (!channel.recipients!.map((r) => r.user_id).includes(user_id)) { + 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); }); diff --git a/api/src/routes/discoverable-guilds.ts b/api/src/routes/discoverable-guilds.ts index b626b084..1cf56f84 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/api/src/routes/discoverable-guilds.ts @@ -3,7 +3,6 @@ import { Guild, Config } from "@fosscord/util"; import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; - const router = Router(); 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 // TODO: implement this with default typeorm query // 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 }); }); diff --git a/api/src/routes/discovery.ts b/api/src/routes/discovery.ts index 9e6e0164..bc495d42 100644 --- a/api/src/routes/discovery.ts +++ b/api/src/routes/discovery.ts @@ -5,7 +5,7 @@ const router = Router(); router.get("/categories", route({}), (req: Request, res: Response) => { // TODO: - //const { locale, primary_only } = req.query; + //const { locale, primary_only } = req.query; res.json([]).status(200); }); diff --git a/api/src/routes/gateway/bot.ts b/api/src/routes/gateway/bot.ts index 72313700..f1dbb9df 100644 --- a/api/src/routes/gateway/bot.ts +++ b/api/src/routes/gateway/bot.ts @@ -12,7 +12,7 @@ export interface GatewayBotResponse { remaining: number; reset_after: number; max_concurrency: number; - } + }; } const options: RouteOptions = { diff --git a/api/src/routes/guilds/#guild_id/prune.ts b/api/src/routes/guilds/#guild_id/prune.ts index 92809985..0dd4d610 100644 --- a/api/src/routes/guilds/#guild_id/prune.ts +++ b/api/src/routes/guilds/#guild_id/prune.ts @@ -1,82 +1,82 @@ -import { Router, Request, Response } from "express"; -import { Guild, Member, Snowflake } from "@fosscord/util"; -import { LessThan, IsNull } from "typeorm"; -import { route } from "@fosscord/api"; -const router = Router(); - -//Returns all inactive members, respecting role hierarchy -export const inactiveMembers = async (guild_id: string, user_id: string, days: number, roles: string[] = []) => { - var date = new Date(); - date.setDate(date.getDate() - days); - //Snowflake should have `generateFromTime` method? Or similar? - var minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22); - - var members = await Member.find({ - where: [ - { - guild_id, - last_message_id: LessThan(minId.toString()) - }, - { - last_message_id: IsNull() - } - ], - relations: ["roles"] - }); - console.log(members); - if (!members.length) return []; - - //I'm sure I can do this in the above db query ( and it would probably be better to do so ), but oh well. - if (roles.length && members.length) members = members.filter((user) => user.roles?.some((role) => roles.includes(role.id))); - - const me = await Member.findOneOrFail({ id: user_id, guild_id }, { relations: ["roles"] }); - const myHighestRole = Math.max(...(me.roles?.map((x) => x.position) || [])); - - const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); - - members = members.filter( - (member) => - member.id !== guild.owner_id && //can't kick owner - member.roles?.some( - (role) => - role.position < myHighestRole || //roles higher than me can't be kicked - me.id === guild.owner_id //owner can kick anyone - ) - ); - - return members; -}; - -router.get("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => { - const days = parseInt(req.query.days as string); - - var roles = req.query.include_roles; - if (typeof roles === "string") roles = [roles]; //express will return array otherwise - - const members = await inactiveMembers(req.params.guild_id, req.user_id, days, roles as string[]); - - res.send({ pruned: members.length }); -}); - -export interface PruneSchema { - /** - * @min 0 - */ - days: number; -} - -router.post("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => { - const days = parseInt(req.body.days); - - var roles = req.query.include_roles; - if (typeof roles === "string") roles = [roles]; - - const { guild_id } = req.params; - const members = await inactiveMembers(guild_id, req.user_id, days, roles as string[]); - - await Promise.all(members.map((x) => Member.removeFromGuild(x.id, guild_id))); - - res.send({ purged: members.length }); -}); - -export default router; +import { Router, Request, Response } from "express"; +import { Guild, Member, Snowflake } from "@fosscord/util"; +import { LessThan, IsNull } from "typeorm"; +import { route } from "@fosscord/api"; +const router = Router(); + +//Returns all inactive members, respecting role hierarchy +export const inactiveMembers = async (guild_id: string, user_id: string, days: number, roles: string[] = []) => { + var date = new Date(); + date.setDate(date.getDate() - days); + //Snowflake should have `generateFromTime` method? Or similar? + var minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22); + + var members = await Member.find({ + where: [ + { + guild_id, + last_message_id: LessThan(minId.toString()) + }, + { + last_message_id: IsNull() + } + ], + relations: ["roles"] + }); + console.log(members); + if (!members.length) return []; + + //I'm sure I can do this in the above db query ( and it would probably be better to do so ), but oh well. + if (roles.length && members.length) members = members.filter((user) => user.roles?.some((role) => roles.includes(role.id))); + + const me = await Member.findOneOrFail({ id: user_id, guild_id }, { relations: ["roles"] }); + const myHighestRole = Math.max(...(me.roles?.map((x) => x.position) || [])); + + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); + + members = members.filter( + (member) => + member.id !== guild.owner_id && //can't kick owner + member.roles?.some( + (role) => + role.position < myHighestRole || //roles higher than me can't be kicked + me.id === guild.owner_id //owner can kick anyone + ) + ); + + return members; +}; + +router.get("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => { + const days = parseInt(req.query.days as string); + + var roles = req.query.include_roles; + if (typeof roles === "string") roles = [roles]; //express will return array otherwise + + const members = await inactiveMembers(req.params.guild_id, req.user_id, days, roles as string[]); + + res.send({ pruned: members.length }); +}); + +export interface PruneSchema { + /** + * @min 0 + */ + days: number; +} + +router.post("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => { + const days = parseInt(req.body.days); + + var roles = req.query.include_roles; + if (typeof roles === "string") roles = [roles]; + + const { guild_id } = req.params; + const members = await inactiveMembers(guild_id, req.user_id, days, roles as string[]); + + await Promise.all(members.map((x) => Member.removeFromGuild(x.id, guild_id))); + + res.send({ purged: members.length }); +}); + +export default router; diff --git a/api/src/routes/oauth2/tokens.ts b/api/src/routes/oauth2/tokens.ts index 3657176d..bd284221 100644 --- a/api/src/routes/oauth2/tokens.ts +++ b/api/src/routes/oauth2/tokens.ts @@ -2,8 +2,8 @@ import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; const router = Router(); -router.get("/",route({}), async (req: Request, res: Response) => { - //TODO +router.get("/", route({}), async (req: Request, res: Response) => { + //TODO res.json([]); }); diff --git a/api/src/routes/store/published-listings/applications/#id/subscription-plans.ts b/api/src/routes/store/published-listings/applications/#id/subscription-plans.ts index 77f949d9..54151ae5 100644 --- a/api/src/routes/store/published-listings/applications/#id/subscription-plans.ts +++ b/api/src/routes/store/published-listings/applications/#id/subscription-plans.ts @@ -6,19 +6,20 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { //TODO res.json([ - { - id: "", - name: "", - interval: 1, - interval_count: 1, - tax_inclusive: true, - sku_id: "", - fallback_price: 499, - fallback_currency: "eur", - currency: "eur", - price: 4199, - price_tier: null - }]).status(200); + { + id: "", + name: "", + interval: 1, + interval_count: 1, + tax_inclusive: true, + sku_id: "", + fallback_price: 499, + fallback_currency: "eur", + currency: "eur", + price: 4199, + price_tier: null + } + ]).status(200); }); export default router; diff --git a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts b/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts index 54c01607..723a5160 100644 --- a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts +++ b/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts @@ -4,17 +4,134 @@ import { route } from "@fosscord/api"; const router: Router = Router(); 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}]], - ["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}]], + [ + "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 + } + ] + ], + [ + "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) => { // TODO: add the ability to add custom const { sku_id } = req.params; - - if(!skus.has(sku_id)) { + + if (!skus.has(sku_id)) { console.log(`Request for invalid SKU ${sku_id}! Please report this!`); res.sendStatus(404); } else { diff --git a/api/src/routes/users/@me/activities/statistics/applications.ts b/api/src/routes/users/@me/activities/statistics/applications.ts index 834be35c..014df8af 100644 --- a/api/src/routes/users/@me/activities/statistics/applications.ts +++ b/api/src/routes/users/@me/activities/statistics/applications.ts @@ -5,7 +5,7 @@ const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { // TODO: - res.json([]).status(200) + res.json([]).status(200); }); export default router; diff --git a/api/src/routes/users/@me/billing/payment-sources.ts b/api/src/routes/users/@me/billing/payment-sources.ts index 834be35c..014df8af 100644 --- a/api/src/routes/users/@me/billing/payment-sources.ts +++ b/api/src/routes/users/@me/billing/payment-sources.ts @@ -5,7 +5,7 @@ const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { // TODO: - res.json([]).status(200) + res.json([]).status(200); }); export default router; diff --git a/api/src/routes/users/@me/channels.ts b/api/src/routes/users/@me/channels.ts index b5782eca..78f531e1 100644 --- a/api/src/routes/users/@me/channels.ts +++ b/api/src/routes/users/@me/channels.ts @@ -5,8 +5,11 @@ import { route } from "@fosscord/api"; const router: Router = Router(); 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"] }); - res.json(await Promise.all(recipients.map(r => DmChannelDTO.from(r.channel, [req.user_id])))); + const recipients = await Recipient.find({ + 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 { diff --git a/api/src/routes/users/@me/email-settings.ts b/api/src/routes/users/@me/email-settings.ts index 2d961a0e..3114984e 100644 --- a/api/src/routes/users/@me/email-settings.ts +++ b/api/src/routes/users/@me/email-settings.ts @@ -4,14 +4,15 @@ import { route } from "@fosscord/api"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: + // TODO: res.json({ - categories: { - social: true, - communication: true, - tips: false, - updates_and_announcements: false, - recommendations_and_events: false }, + categories: { + social: true, + communication: true, + tips: false, + updates_and_announcements: false, + recommendations_and_events: false + }, initialized: false }).status(200); }); diff --git a/api/src/util/ipAddress.ts b/api/src/util/ipAddress.ts index c6239426..13cc9603 100644 --- a/api/src/util/ipAddress.ts +++ b/api/src/util/ipAddress.ts @@ -81,18 +81,15 @@ export function getIpAdress(req: Request): string { return req.headers[Config.get().security.forwadedFor] || req.socket.remoteAddress; } - export function distanceBetweenLocations(loc1: any, loc2: any): number { return distanceBetweenCoords(loc1.latitude, loc1.longitude, loc2.latitude, loc2.longitude); } //Haversine function 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 a = 0.5 - c((lat2 - lat1) * p) / 2 + - c(lat1 * p) * c(lat2 * p) * - (1 - c((lon2 - lon1) * p)) / 2; + const a = 0.5 - c((lat2 - lat1) * 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 -} \ No newline at end of file +} |