Skip to content

Commit

Permalink
fix: remove keyv dependency and use redis instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Dec 3, 2024
1 parent 2a48968 commit b8234eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 100 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@dicebear/core": "^9.2.2",
"@floating-ui/dom": "^1.6.12",
"@iconify/svelte": "^4.0.2",
"@keyv/redis": "^3.0.1",
"@lezer/highlight": "^1.2.1",
"@rodrigodagostino/svelte-sortable-list": "^0.10.8",
"@skeletonlabs/skeleton": "^2.10.3",
Expand Down Expand Up @@ -52,7 +51,6 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.46.0",
"fast-xml-parser": "^4.5.0",
"keyv": "^5.2.1",
"leaf-proto": "workspace:*",
"linkedom": "^0.18.5",
"linktree-parser": "^1.5.0",
Expand Down
88 changes: 0 additions & 88 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src/lib/discord_bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import {
WebLinks
} from '$lib/leaf/profile';
import { getDiscordUserRauthyId } from '$lib/leaf/discord';
import Keyv from 'keyv';
import { leafClient } from '$lib/leaf';
import { Name } from 'leaf-proto/components';
import { redis } from '$lib/redis';
import { usernames } from '$lib/usernames';

// TODO: allow using Redis for key-value storage so that it can be clustered properly.
const discordLoginLinkIds = new Keyv({ namespace: 'discord-login-links' });
const REDIS_PREFIX = 'weird:discord-login-links:';

export const createDiscordLoginLinkId = async (discordId: string): Promise<string> => {
const linkid = crypto.randomUUID();
// Create a login link that is valid for 10 minutes
await discordLoginLinkIds.set(linkid, discordId, 10 * 60 * 1000);
await redis.set(REDIS_PREFIX + linkid, discordId, { EX: 10 * 60 * 1000 });
return linkid;
};

export const getDiscordIdForLoginLink = async (loginLink: string): Promise<string | undefined> => {
const discordId = await discordLoginLinkIds.get(loginLink);
if (discordId) await discordLoginLinkIds.delete(loginLink);
return discordId;
export const getDiscordIdForLoginLink = async (linkId: string): Promise<string | undefined> => {
const discordId = await redis.get(REDIS_PREFIX + linkId);
if (discordId) await redis.del(linkId);
return discordId || undefined;
};

const LOGIN_CMD = 'weird-login';
Expand Down Expand Up @@ -104,7 +104,7 @@ client.on('interactionCreate', async function (interaction) {
});
return;
}
const profileLink = getProfileLinkById(userId);
const profileLink = await getProfileLinkById(userId);
const profile = await getProfile(profileLink);
if (!profile) {
interaction.reply({
Expand All @@ -127,7 +127,7 @@ client.on('interactionCreate', async function (interaction) {
]);

interaction.reply({
content: `Links imported successfully (http://${PublicEnv.PUBLIC_DOMAIN}/${profile.username}/discord-links):\n${links.join('\n')}`,
content: `Links imported successfully (http://${PublicEnv.PUBLIC_DOMAIN}/${await usernames.getByRauthyId(userId)}/discord-links):\n${links.join('\n')}`,
ephemeral: true
});
}
Expand Down

0 comments on commit b8234eb

Please sign in to comment.