Skip to content

Commit

Permalink
Reduce dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Yureien committed Jun 8, 2023
1 parent 5ffaef1 commit 2a5024c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"base64-js": "^1.5.1",
"prism-themes": "^1.9.0",
"prismjs": "^1.29.0",
"sanitize-html": "^2.10.0",
"svelte-prism-autoloader": "^0.0.3"
"sanitize-html": "^2.10.0"
}
}
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface PasteConfig {
language: string;
encrypted: boolean;
expiresAfter: string;
burn: boolean;
burnAfterRead: boolean;
}

export interface Paste {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
language: 'plaintext',
encrypted: true,
expiresAfter: 'never',
burn: false
burnAfterRead: false
};
let inputRef: HTMLTextAreaElement;
Expand Down Expand Up @@ -117,7 +117,7 @@

<div>
<label for="burn" class="py-1">Burn after read?</label>
<input id="burn" type="checkbox" bind:checked={config.burn} />
<input id="burn" type="checkbox" bind:checked={config.burnAfterRead} />
</div>

<div>
Expand Down
10 changes: 7 additions & 3 deletions src/routes/[key]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ import sanitize from 'sanitize-html';
export async function load({ params }) {
const { key } = params;

const data = await prisma.paste.findUnique({
let data = await prisma.paste.findUnique({
where: { key }
});

if (!data) throw error(404, 'Not found');

await prisma.paste.update({
data = await prisma.paste.update({
where: { key },
data: { readCount: { increment: 1 } }
});

let { content, language, encrypted, passwordProtected } = data;
let { content, language, encrypted, passwordProtected, expiresCount, readCount } = data;
if (expiresCount !== null && expiresCount < readCount) {
await prisma.paste.delete({ where: { key } });
throw error(404, 'Not found');
}

let contentHtml: string;

Expand Down
10 changes: 6 additions & 4 deletions src/routes/[key]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { AutoLoader } from 'svelte-prism-autoloader';
import type { PageData } from './$types';
let Prism: any;
Expand All @@ -15,10 +14,14 @@
let pwInputRef: HTMLInputElement;
let error: string;
$: if (isDecrypted && codeRef) {
$: if (isDecrypted && codeRef && language && language !== 'plaintext') {
(async () => {
const Prism = (await import('prismjs')).default;
Prism.highlightElement(codeRef);
const script = document.createElement('script');
script.async = true;
script.src = `https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-${language}.min.js`;
script.onload = () => Prism.highlightAll();
document.body.appendChild(script);
})();
}
Expand Down Expand Up @@ -147,7 +150,6 @@
{:else}
<div class="grow whitespace-pre bg-dark p-4 overflow-x-scroll">
<pre><code bind:this={codeRef} class="language-{language}">{content}</code></pre>
<AutoLoader languagesPath="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/" />
</div>
{/if}

Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/create/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export async function POST({ request }) {
content,
language: config.language,
encrypted: config.encrypted,
passwordProtected
passwordProtected,
expiresCount: config.burnAfterRead ? 1 : null
}
});

Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1907,11 +1907,6 @@ svelte-preprocess@^5.0.3:
sorcery "^0.11.0"
strip-indent "^3.0.0"

svelte-prism-autoloader@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/svelte-prism-autoloader/-/svelte-prism-autoloader-0.0.3.tgz#f524fdfe2424e255e0b6475cbee489ad6231d29f"
integrity sha512-hp0k3Rn39rCCjex4quQpSRX+JriSm3CyNkJjvMMFQ+NdzIENXMQA0NAX4IwyjeWdnvE3DbfGRUQlPMxlW76BEA==

svelte-select@^5.6.1:
version "5.6.1"
resolved "https://registry.yarnpkg.com/svelte-select/-/svelte-select-5.6.1.tgz#2626748c92ff3983c75f273d87afba59ffef3b29"
Expand Down

0 comments on commit 2a5024c

Please sign in to comment.