mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-07 10:31:26 +03:00
Merge branch 'feat-archives'
This commit is contained in:
@@ -9,7 +9,7 @@ module.exports.delete = fastify => ({
|
||||
const guild = client.guilds.cache.get(req.params.guild);
|
||||
const categoryId = Number(req.params.category);
|
||||
const original = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
|
||||
if (!original || original.guildId !== guild.id) return res.status(404).send(new Error('Not Found'));
|
||||
if (!original || original.guildId !== guild.id) return res.status(400).send(new Error('Bad Request'));
|
||||
const category = await client.prisma.category.delete({ where: { id: categoryId } });
|
||||
|
||||
await updateStaffRoles(guild);
|
||||
@@ -58,7 +58,7 @@ module.exports.get = fastify => ({
|
||||
where: { id: categoryId },
|
||||
});
|
||||
|
||||
if (!category || category.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
if (!category || category.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
|
||||
|
||||
return category;
|
||||
},
|
||||
@@ -118,7 +118,7 @@ module.exports.patch = fastify => ({
|
||||
where: { id: categoryId },
|
||||
});
|
||||
|
||||
if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
if (!original || original.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
|
||||
|
||||
if (data.hasOwnProperty('id')) delete data.id;
|
||||
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
||||
|
@@ -9,7 +9,7 @@ module.exports.delete = fastify => ({
|
||||
const questionId = req.params.question;
|
||||
const original = questionId && await client.prisma.question.findUnique({ where: { id: questionId } });
|
||||
const category = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
|
||||
if (original?.categoryId !== categoryId || category.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
if (original?.categoryId !== categoryId || category.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
|
||||
const question = await client.prisma.question.delete({ where: { id: questionId } });
|
||||
|
||||
logAdminEvent(client, {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
const { iconURL } = require('../../../../../lib/misc');
|
||||
const {
|
||||
getAvgResolutionTime,
|
||||
getAvgResponseTime,
|
||||
@@ -37,7 +38,7 @@ module.exports.get = fastify => ({
|
||||
cached = {
|
||||
createdAt: settings.createdAt,
|
||||
id: guild.id,
|
||||
logo: guild.iconURL(),
|
||||
logo: iconURL(guild),
|
||||
name: guild.name,
|
||||
stats: {
|
||||
avgResolutionTime: ms(getAvgResolutionTime(closedTickets)),
|
||||
|
@@ -8,7 +8,7 @@ module.exports.delete = fastify => ({
|
||||
const guildId = req.params.guild;
|
||||
const tagId = Number(req.params.tag);
|
||||
const original = tagId && await client.prisma.tag.findUnique({ where: { id: tagId } });
|
||||
if (original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
if (original.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
|
||||
const tag = await client.prisma.tag.delete({ where: { id: tagId } });
|
||||
|
||||
const cacheKey = `cache/guild-tags:${guildId}`;
|
||||
@@ -46,7 +46,7 @@ module.exports.get = fastify => ({
|
||||
const tagId = Number(req.params.tag);
|
||||
const tag = await client.prisma.tag.findUnique({ where: { id: tagId } });
|
||||
|
||||
if (!tag || tag.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
if (!tag || tag.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
|
||||
|
||||
return tag;
|
||||
},
|
||||
@@ -64,7 +64,7 @@ module.exports.patch = fastify => ({
|
||||
|
||||
const original = req.params.tag && await client.prisma.tag.findUnique({ where: { id: tagId } });
|
||||
|
||||
if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
if (!original || original.guildId !== guildId) return res.status(400).send(new Error('Bad Request'));
|
||||
|
||||
if (data.hasOwnProperty('id')) delete data.id;
|
||||
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
const { PermissionsBitField } = require('discord.js');
|
||||
const { iconURL } = require('../../../../lib/misc');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
@@ -10,7 +11,14 @@ module.exports.get = fastify => ({
|
||||
.map(guild => ({
|
||||
added: client.guilds.cache.has(guild.id),
|
||||
id: guild.id,
|
||||
logo: `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp`,
|
||||
logo: iconURL(
|
||||
client.guilds.cache.get(guild.id) ||
|
||||
{
|
||||
client,
|
||||
icon: guild.icon,
|
||||
id: guild.id,
|
||||
},
|
||||
),
|
||||
name: guild.name,
|
||||
})),
|
||||
);
|
||||
|
17
src/routes/api/guilds/[guild]/index.js
Normal file
17
src/routes/api/guilds/[guild]/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const { getPrivilegeLevel } = require('../../../../lib/users');
|
||||
const { iconURL } = require('../../../../lib/misc');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
const { client } = req.routeOptions.config;
|
||||
const guild = client.guilds.cache.get(req.params.guild);
|
||||
res.send({
|
||||
id: guild.id,
|
||||
logo: iconURL(guild),
|
||||
name: guild.name,
|
||||
privilegeLevel: await getPrivilegeLevel(await guild.members.fetch(req.user.id)),
|
||||
});
|
||||
},
|
||||
onRequest: [fastify.authenticate, fastify.isMember],
|
||||
});
|
||||
|
18
src/routes/api/guilds/[guild]/tickets/@me.js
Normal file
18
src/routes/api/guilds/[guild]/tickets/@me.js
Normal file
@@ -0,0 +1,18 @@
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
const { client } = req.routeOptions.config;
|
||||
/** @type {import("@prisma/client").PrismaClient} */
|
||||
const prisma = client.prisma;
|
||||
const guild = client.guilds.cache.get(req.params.guild);
|
||||
res.send(
|
||||
await prisma.ticket.findMany({
|
||||
where: {
|
||||
createdById: req.user.id,
|
||||
guildId: guild.id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
onRequest: [fastify.authenticate, fastify.isMember],
|
||||
});
|
||||
|
25
src/routes/api/guilds/index.js
Normal file
25
src/routes/api/guilds/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { getPrivilegeLevel } = require('../../../lib/users');
|
||||
const { iconURL } = require('../../../lib/misc');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
const { client } = req.routeOptions.config;
|
||||
const guilds = await (await fetch('https://discordapp.com/api/users/@me/guilds', { headers: { 'Authorization': `Bearer ${req.user.accessToken}` } })).json();
|
||||
res.send(
|
||||
await Promise.all(
|
||||
guilds
|
||||
.filter(partialGuild => client.guilds.cache.has(partialGuild.id))
|
||||
.map(async partialGuild => {
|
||||
const guild = client.guilds.cache.get(partialGuild.id);
|
||||
return {
|
||||
id: guild.id,
|
||||
logo: iconURL(guild),
|
||||
name: guild.name,
|
||||
privilegeLevel: await getPrivilegeLevel(await guild.members.fetch(req.user.id)),
|
||||
};
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
onRequest: [fastify.authenticate],
|
||||
});
|
@@ -19,7 +19,6 @@ module.exports.get = () => ({
|
||||
const token = this.jwt.sign({
|
||||
accessToken: data.access_token,
|
||||
avatar: user.avatar,
|
||||
discriminator: user.discriminator,
|
||||
expiresAt: Date.now() + (data.expires_in * 1000),
|
||||
id: user.id,
|
||||
locale: user.locale,
|
||||
@@ -30,9 +29,16 @@ module.exports.get = () => ({
|
||||
httpOnly: true,
|
||||
maxAge: data.expires_in,
|
||||
path: '/',
|
||||
sameSite: 'Lax',
|
||||
sameSite: 'Strict',
|
||||
secure: false,
|
||||
});
|
||||
return res.redirect(redirect, 303);
|
||||
res.header('Content-Type', 'text/html');
|
||||
return res.send(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta http-equiv="refresh" content="0; url='${redirect}'"></head>
|
||||
<body></body>
|
||||
</html>
|
||||
`);
|
||||
},
|
||||
});
|
||||
|
@@ -18,9 +18,17 @@ module.exports.get = fastify => ({
|
||||
domain,
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
sameSite: 'Lax',
|
||||
sameSite: 'Strict',
|
||||
secure: false,
|
||||
}).send('The token has been revoked.');
|
||||
});
|
||||
res.header('Content-Type', 'text/html');
|
||||
return res.send(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta http-equiv="refresh" content="0; url='/'"></head>
|
||||
<body></body>
|
||||
</html>
|
||||
`);
|
||||
},
|
||||
onRequest: [fastify.authenticate],
|
||||
});
|
||||
|
Reference in New Issue
Block a user