Skip to content

Commit

Permalink
feat: add pe debug
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinrais committed Jan 7, 2024
1 parent d2a5800 commit 3b0586b
Show file tree
Hide file tree
Showing 74 changed files with 680 additions and 306 deletions.
1 change: 1 addition & 0 deletions src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// and what to do when importing types
declare namespace App {
interface Error {
message?: string;
status?: number;
}

Expand Down
32 changes: 32 additions & 0 deletions src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,35 @@ a.link:not([href='']) {
.bytemd-fullscreen {
@apply z-50;
}

.table-border {
@apply w-full overflow-hidden rounded-xl border border-gray-200;

table {
@apply w-full;

th {
@apply font-bold;
}

td,
th {
@apply px-4 border;
}

th {
@apply border-t-0;
}

th:first-child,
td:first-child {
@apply border-l-0 border-t-0;
}

th:last-child,
td:last-child,
tr:last-child td {
@apply border-b-0 border-r-0;
}
}
}
12 changes: 9 additions & 3 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ export const handle: Handle = (async ({ event, resolve }) => {
'member_since',
'admin',
'email'
].reduce((obj: any, key) => ((obj[key] = (user as any)[key]), obj), {});
].reduce(
(finalUserData, key) => ({
...finalUserData,
[key]: user[key as keyof typeof user]
}),
{} as Record<string, any>
);
} catch (error) {
console.error('hooks error: ', error);
}

return await resolve(event);
return resolve(event);
}) satisfies Handle;

export const handleError = (async ({ error, event }: any) => {
Expand All @@ -45,7 +51,7 @@ export const handleError = (async ({ error, event }: any) => {
path: '/'
});

console.error(error);
console.error('handle error :', error);

return {
message: error?.message,
Expand Down
5 changes: 1 addition & 4 deletions src/lib/clients/saferwall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { env } from '$env/dynamic/public';
import { DEFAULT_PAGINATION_ITEMS } from '$lib/config';

import type {
ApiTraceBufferDto,
ChangePasswordDto,
Expand Down Expand Up @@ -41,9 +40,7 @@ export class SaferwallClient {
...args
};

this.setAuthHeaders(init);

const response: any = await fetch(url, init);
const response: any = await fetch(url, this.setAuthHeaders(init));

if (!response.ok) {
throw response;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/LoadMore.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let loading = false;
export let reachEnd = false;
const onLoadMoreMouseUp = () => {
const onMouseUpLoadMore = () => {
if (!loading) {
dispatch('load');
}
Expand All @@ -16,7 +16,7 @@

{#if !reachEnd}
<div
on:mouseup={onLoadMoreMouseUp}
on:mouseup={onMouseUpLoadMore}
class="w-full flex-center rounded cursor-pointer text-primary space-x-2 font-medium p-4"
>
<div class="flex-center space-x-1">
Expand Down
20 changes: 18 additions & 2 deletions src/lib/components/Multitoggle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createEventDispatcher } from 'svelte';
export let max = 1;
export let border = false;
export let name: string | undefined = undefined;
type MultitoggleItem = {
Expand Down Expand Up @@ -40,10 +41,17 @@
return true;
})
]);
items = [
...items.map((item) => {
item.checked = selected.has(item);
return item;
})
];
};
</script>

<ul class="multitoggle">
<ul class="multitoggle" class:with-border={border}>
{#each items as item}
<li class="item" class:active={selected.has(item)} on:mouseup={() => onToggleMouseUp(item)}>
<input type="checkbox" {name} bind:value={item.value} checked={selected.has(item)} />
Expand All @@ -54,7 +62,15 @@

<style lang="scss">
.multitoggle {
@apply flex items-center rounded-full space-x-1;
@apply inline-flex items-center rounded-full space-x-1;
&.with-border {
@apply border border-gray-100 p-1.5;
.item {
@apply py-1.5 px-4;
}
}
.item {
@apply py-2 px-4 rounded-full;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/TableKeyValue.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script lang="ts">
import { splitCamelCase, valueToHex } from '$lib/utils';
import type { A } from 'vitest/dist/types-71ccd11d';
export let lines = false;
export let header = true;
export let hexValue = true;
export let camelCase = true;
export let items: [string, any][] = [];
export let items: any[][] = [];
</script>

<table class="w-full">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/UploadBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

<div class="flex min-h-[300px] flex-col items-center justify-center space-y-6">
<div class="m-auto w-max h-max">
<ButtonBrowse href={loggedIn ? undefined : '/auth/login'} on:mouseup={selectFiles} />
<ButtonBrowse href={loggedIn ? undefined : '/auth/login'} on:click={selectFiles} />
</div>

<div class="flex flex-col w-full space-y-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{/each}
</table>
{#if activeExpanding}
<ButtonShowMore on:mouseup={onShowMoreMouseUp} {expanded} />
<ButtonShowMore on:click={onShowMoreMouseUp} {expanded} />
{/if}
</div>
</Card>
2 changes: 1 addition & 1 deletion src/lib/components/cards/summary/IndicatorsCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</table>
<CommingSoon />
{#if activeExpanding}
<ButtonShowMore on:mouseup={() => (expanded = !expanded)} {expanded} />
<ButtonShowMore on:click={() => (expanded = !expanded)} {expanded} />
{/if}
</div>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/cards/summary/SubmissionsCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</tbody>
</table>
{#if activeExpanding}
<ButtonShowMore on:mouseup={onShowMoreMouseUp} {expanded} />
<ButtonShowMore on:click={onShowMoreMouseUp} {expanded} />
{/if}
</div>
</Card>
4 changes: 2 additions & 2 deletions src/lib/components/form/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{#if href}
<a
on:mouseup
on:click
{...$$props}
{href}
{target}
Expand All @@ -31,7 +31,7 @@
</a>
{:else}
<button
on:mouseup
on:click
{...$$props}
{type}
disabled={loading || disabled}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/form/ButtonBrowse.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Button from './Button.svelte';
</script>

<Button {...$$props} theme="primary" size="lg" on:mouseup>
<Button {...$$props} theme="primary" size="lg" on:click>
<span>Browse files</span>
<svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8">
<use href="/images/icons.svg#icon-cloud" />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/form/ButtonShowMore.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export let mode: 'all' | 'more' = 'all';
</script>

<div class="button" on:mouseup>
<div class="button" on:click>
<span>
Show {#if expanded}less{:else}{mode}{/if}
</span>
Expand Down
24 changes: 13 additions & 11 deletions src/lib/components/partials/FileHeading.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<script lang="ts">
import type { Saferwall, Menus } from '$lib/types';
import { env } from '$env/dynamic/public';
import { SaferwallClient } from '$lib/clients/saferwall';
import Button from '$lib/components/form/Button.svelte';
import type { Menu, Saferwall } from '$lib/types';
import ButtonLike from '../form/ButtonLike.svelte';
import { SaferwallClient } from '$lib/clients/saferwall';
export let hash = '';
export let hash: string;
export let liked = false;
export let loggedIn = false;
export let activeMenu: Menus.File;
export let activeMenu: Menu.File;
export let session: Saferwall.Session;
$: downloadLink = `https://api.saferwall.com/v1/files/${hash}/download/`;
$: shareTwitterLink = `https://twitter.com/intent/tweet?text=https://saferwall.com/file/${hash}/${activeMenu.path}`;
$: downloadLink = `${env.PUBLIC_API_URL}files/${hash}/download/`;
$: shareTwitterLink = `https://twitter.com/intent/tweet?text=https://saferwall.com/files/${hash}/${activeMenu.path}`;
let rescaning = false;
const onRescanMouseUp = async () => {
const onRescanClick = async () => {
rescaning = true;
try {
await new SaferwallClient(session).rescanFile(hash);
window.location.reload();
} catch (error) {}
rescaning = false;
} catch (error) {
console.error('Rescab failed', error);
}
window.location.reload();
};
</script>

Expand All @@ -40,7 +42,7 @@
icon="rescan"
loading={rescaning}
disabled={rescaning}
on:mouseup={onRescanMouseUp}
on:click={onRescanClick}
>
<span class="hidden md:block pl-2">Rescan file</span>
</Button>
Expand Down
14 changes: 7 additions & 7 deletions src/lib/components/partials/FileNavbar.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts">
import type { Menus } from '$lib/types';
import type { Menu } from '$lib/types';
export let hash = '';
export let fileMenu: Menus.File[] = [];
export let activeFileMenu: Menu.File[] = [];
export let activeMenu: { name: string; path: string };
$: isActivePath = (path: string): boolean => path === activeMenu.path;
$: applyFilePath = (path: string): string => `/files/${hash}/${path}`;
$: isPathActive = (path: string): boolean => path === activeMenu.path;
$: generateFilePath = (path: string): string => `/files/${hash}/${path}`;
</script>

<section
Expand All @@ -23,12 +23,12 @@
<span>Browse file</span>
</a>
</li>
{#each fileMenu as menu}
{#each activeFileMenu as item}
<li class="fnavbar__item">
<a
class="fnavbar__link"
class:active={isActivePath(menu.path)}
href={applyFilePath(menu.path)}>{menu.name}</a
class:active={isPathActive(item.path)}
href={generateFilePath(item.path)}>{item.name}</a
>
</li>
{/each}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/partials/UserMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
$: username = user?.username;
const clickOutside = (node: Node, { enabled: initialEnabled, cb }: any) => {
const clickOutside = (
node: Node,
{ enabled: initialEnabled, cb }: { enabled: boolean; cb: Function }
) => {
const handleOutsideClick = ({ target }: any) => {
if (!node.contains(target)) {
cb();
Expand Down
6 changes: 3 additions & 3 deletions src/lib/data/menus.ts → src/lib/data/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Menus } from '$lib/types';
import type { Menu } from '$lib/types';

export const fileMenu: Menus.File[] = [
export const fileMenu: Menu.File[] = [
{ name: 'Summary', path: 'summary' },
{
name: 'PE',
Expand All @@ -15,7 +15,7 @@ export const fileMenu: Menus.File[] = [
{ name: 'Comments', path: 'comments' }
];

export const peMenu: Menus.PE[] = [
export const peMenu: Menu.PE[] = [
{ field: 'dos_header', path: 'dos-header', title: 'DOS Header' },
{ field: 'nt_header', path: 'nt-header', title: 'NT Header' },
{ field: 'rich_header', path: 'rich-header', title: 'Rich Header' },
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Error {
status: number;
}

export namespace Menus {
export namespace Menu {
export interface File {
name: string;
path: string;
Expand Down
Loading

0 comments on commit 3b0586b

Please sign in to comment.