Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix updating vanity URL & widget.json #1194

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/api/routes/guilds/#guild_id/vanity-url.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -108,30 +108,23 @@ router.patch(
});

if (!guild.features.includes("ALIASABLE_NAMES")) {
await Invite.update(
{ guild_id },
{
code: code,
},
);

return res.json({ code });
await Invite.delete({ guild_id, vanity_url: true });
}

await Invite.create({
vanity_url: true,
code: code,
code,
temporary: false,
uses: 0,
max_uses: 0,
max_age: 0,
created_at: new Date(),
expires_at: new Date(),
guild_id: guild_id,
channel_id: id,
flags: 0,
}).save();

return res.json({ code: code });
return res.json({ code });
},
);

Expand Down
5 changes: 5 additions & 0 deletions src/api/routes/guilds/#guild_id/widget.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ router.get(
where: { id: guild_id },
select: {
channel_ordering: true,
widget_channel_id: true,
widget_enabled: true,
presence_count: true,
name: true,
},
});
if (!guild.widget_enabled) throw DiscordApiErrors.EMBED_DISABLED;
Expand All @@ -82,6 +86,7 @@ router.get(
created_at: new Date(),
guild_id,
channel_id: guild.widget_channel_id,
flags: 0,
}).save();
}

Expand Down
Loading