Skip to content

Commit

Permalink
Merge pull request #156 from Delemangi/fix/webhooks
Browse files Browse the repository at this point in the history
Fix webhook error
  • Loading branch information
Delemangi authored Jun 16, 2024
2 parents bcbaa16 + a4ee28c commit 5d57714
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
9 changes: 8 additions & 1 deletion frontend/src/lib/components/user/FileRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
'test'
);
export let allowWebhooks: boolean;
const useStyles = createStyles((theme: theme) => {
return {
root: {
Expand Down Expand Up @@ -243,7 +245,12 @@
</Text>
<Flex justify="center" gap="xs" css={{ flex: 1 }}>
<Tooltip openDelay={10} label="Send to Webhook">
<ActionIcon variant="filled" color="blue" on:click={sendToWebHooks}>
<ActionIcon
variant="filled"
color="blue"
on:click={sendToWebHooks}
disabled={!allowWebhooks}
>
<DoubleArrowRight size={20} />
</ActionIcon>
</Tooltip>
Expand Down
23 changes: 17 additions & 6 deletions frontend/src/routes/user/2fa/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
import { page } from '$app/stores';
import QR from '@svelte-put/qr/img/QR.svelte';
import { Button, Flex, Text, TextInput } from '@svelteuidev/core';
import { isAxiosError } from 'axios';
import { onMount } from 'svelte';
import { get2FAToken, remove2FAToken } from '../../../server/auth';
let code: string | null = null;
let username: string = '';
let username: string | null = null;
let password: string = '';
let option: string | null = 'enable';
const fetchCode = async () => {
try {
let accessToken = localStorage.getItem('accessToken');
if (!accessToken) {
if (!accessToken || !username) {
window.location.href = '/auth/login';
return;
}
Expand All @@ -27,27 +28,37 @@
return;
}
} catch (error) {
console.error('Failed to update 2FA token:', error);
if (!isAxiosError(error)) {
alert('An unknown error occurred.');
return;
}
if (error.response?.status === 401) {
alert('Invalid password.');
return;
}
alert('An error occurred while sharing the file.');
}
};
onMount(async () => {
option = $page.url.searchParams.get('option');
username = localStorage.getItem('username');
});
</script>

{#if code == null}
<div class="container">
<TextInput label="Username" bind:value={username} />
<TextInput label="Password" bind:value={password} type="password" />
<br />
<div class="button-container">
<Button on:click={fetchCode} disabled={!username.length || !password.length}>Login</Button>
<Button on:click={fetchCode} disabled={!password.length}>Login</Button>
</div>
<br />
</div>
<br />
<Text size="md" align="center">Please log in again to update the 2FA token.</Text>
<Text size="md" align="center">Please enter your password again to update the 2FA token.</Text>
{/if}

{#if code != null}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/routes/user/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { onMount } from 'svelte';
import { clearSession } from '../../../auth/session';
import { getFilesForSpecifiedUser, sendFileForSpecifiedUser } from '../../../server/files';
import { getWebhooksForSpecifiedUser } from '../../../server/webhooks';
let filesToUpload: FileList | null = null;
let privateFile = true;
Expand Down Expand Up @@ -77,7 +78,7 @@
$: ({ classes, getStyles } = useStyles());
let userFiles: FileMetadata[] = [];
let allowWebhooks = false;
let visible = false;
onMount(async () => {
Expand All @@ -90,6 +91,9 @@
try {
userFiles = await getFilesForSpecifiedUser(accessToken);
const webhooks = await getWebhooksForSpecifiedUser(accessToken);
allowWebhooks = webhooks.length > 0;
} catch (error) {
if (!isAxiosError(error)) {
alert('An unknown error occurred.');
Expand Down Expand Up @@ -127,7 +131,7 @@

<TitleFileRow />
{#each userFiles as file}
<FileRow {file} />
<FileRow {file} {allowWebhooks} />
{/each}

{#if visible}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/server/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const uploadWebhook = async (accessToken: string, platform: string, url:

export const sendWebhook = async (webhookId: string, fileId: string) => {
const result = await axios.post(
`${BASE_URL}/webhooks/send?webhook_id=${webhookId}&file_id=${fileId}/`
`${BASE_URL}/webhooks/send?webhook_id=${webhookId}&file_id=${fileId}`
);

return result.data;
Expand Down

0 comments on commit 5d57714

Please sign in to comment.