Removed LZMA compression

This commit is contained in:
Simon Cambier 2023-11-24 19:37:08 +01:00
parent ad4b21daf1
commit b620536eb8
7 changed files with 29 additions and 79 deletions

View File

@ -2,14 +2,14 @@
> A no-database, no-backend pastebin-like service. All the data is stored in the url.
This is a rewrite of https://nopaste.boris.sh/, which was a rewrite of https://topaz.github.io/paste/. The biggest improvement of this version is that it uses brotli compression, while staying compatible with the original lzma compressed urls.
This is a rewrite of https://nopaste.boris.sh/, which is a rewrite of https://topaz.github.io/paste/
[More information on this self-hosted "about" page](https://paste.scambier.xyz/?l=mrwn#G14EICwPbMc0BJ69xNPoItLoErDRMwMj3+vxE5RxArxajeByk+b0b1Tm2h/5ugGgK6S83AqUCi09HeYmDs+vvzQc0QDZe7v7U2rHnFe6CTWSm2AArNua4tqtXVIEFVQuqG+is15etOm1OZOPPCH4xDX1iDNF2bQcN9ugum0Icnwj51n0nlvNacn/N3OOctSGrQbLoNzG8n5bSoJQXOx+PsxV+MeUl+rkKNPIAXT9c8LoOY/772FiFkLv/5w8rvtCBc38VEE5lzmGFcZ0QtqlzBhvWLV5WPhRkROqeoKoDCtH03/fQVI5Y8HfLkq2/Nuidd1GQTKgmPJQVWbZ4cAiqUdOJG6j6pvu48qWjqamYG3nFPHcdYLHYCRV877U2mBgSHTbLWv6eu/DEA88SE5XEIqiQFyDVS2HLN7jJSloLHQJ+jOE86zb9jrkQ9tXAwkAoovCcnlrW5T/EU4L7imRsDAkZdEySO/ri/NBuHPMpSFnqGItLlPd98/SZSmySbImOLfv4WGbdCxw9TYykGsk56aQaVSa/DB2t5HfD6x28lJVlMm3Hjnkwyx95PxNGH0teCAk6CqtbBYlC3LjhY0IEpJ0WWZWY6MlJB+jEW7lAN3DSJD0QFz2FZOOV/HwA9LbFBU=)
[More information on this self-hosted "about" page](https://paste.scambier.xyz/?l=md#G0oEIKySx5UfTkdu1XoEsNFTBka+1+MnKOMEeLUaweWLc/oYlbttJz93QOgIkhdODeUmDs/+u3T5RANkM7+ktGLRxbTN0WIKyb2AWJbsnIoNDvzMtbcgQpsQYPWXPwUeRkuMWOXIEYIfzvnjqY85WNtT9Rjq3Y4/qHB1+mjzCQsTvr9UIfLbq28+i4joe5i/F2SQCTO9G/SlgnojZOKr9BSbIq0EPVBnVgg9T8+zls2Ezgg67tZTjX8pVB70RIghiwfFeqn/ZMQv9VGcbEWDIHnUlL52CL4FeCQ6DMJ4OOtVWk9jWI3i1CRvzxbmHudPlk1iA4pD9wHgOOILFPKQUAntulosi6VRhJ9eeSmViKpbloonQX9cDQVUkg8rzdkoBllTTfnVcYwDRsMS3UjTv/I+befAQeNMiRc7ESFegwUd6yEFPyVJG8RCXcgvw1QfdBe93uXQ9qGBL6BhLpjlpqxjmf9fwkKHFYClXmn7yaZrc/HrW6YH5F6Ei9MGKMvY5be++/noh6TJ5MeGgDzeJgNr0rjvcltZrDRS8wumbWpseMjTY1bz/rp/fJVQxwy/Rd+kXjlGrMJLZsVVwED5b0Jr26wUAm85shUyLX50kklq6ZIRfnzNX4LWrnl72vWR1YaTr/3n+Cp+6IBEliYA)
## TODO
- [x] Use brotli
- [x] Stay compatible with original lzma-compressed urls
- [x] ~~Stay compatible with original lzma-compressed urls~~
- [x] Have a read-only view with nice colors for code blocks
- [ ] Use CodeMirror 6
- [ ] 100% self-contained, no dependance on jsdeliver

View File

@ -14,8 +14,6 @@ npm/codemirror@5.65.16/theme/nord.min.css"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
<script src="https://cdn.jsdelivr.net/combine/npm/lzma@2.3.2/src/lzma.min.js"></script>
</head>
<body data-sveltekit-preload-data="hover">
<div class="dark:text-gray-300 dark:bg-gray-800 min-h-screen">%sveltekit.body%</div>

View File

@ -5,7 +5,7 @@
<h1 class="text-xl">Paste</h1>
<span class="ml-8 text-xs">
<a
href="/?l=md#G14EICwPbMc0BJ69xNPoItLoErDRMwMj3+vxE5RxArxajeByk+b0b1Tm2h/5ugGgK6S83AqUCi09HeYmDs+vvzQc0QDZe7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be++/noh6TJ5MeGgDzeJgNr0rjvcltZrDRS8wumbWpseMjTY1bz/rp/fJVQxwy/Rd+kXjlGrMJLZsVVwED5b0Jr26wUAm85shUyLX50kklq6ZIRfnzNX4LWrnl72vWR1YaTr/3n+Cp+6IBEliYA"
target="_blank"
>
About

6
src/globals.d.ts vendored
View File

@ -1,7 +1 @@
declare class LZMA {
constructor(any): {}
compress: (value: string, level: number, callback: (result: number[]) => void) => void
decompress: (b: Uint8Array, callback: (result: string, err: any) => void) => void
}
declare const CodeMirror: any

View File

@ -1,33 +0,0 @@
// LZMA imported from <script> in index.html
const blob = new Blob([
'importScripts("https://cdn.jsdelivr.net/npm/lzma@2.3.2/src/lzma_worker.min.js");',
])
const lzma = new LZMA(window.URL.createObjectURL(blob))
async function compress(value: string): Promise<string> {
return new Promise((resolve, reject) => {
lzma.compress(value, 1, (numbers: number[]) => {
const bytes = new Uint8Array(numbers)
const b64 = btoa(String.fromCharCode(...bytes))
resolve(b64)
})
})
}
async function decompress(base64: string): Promise<string> {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest()
req.open('GET', 'data:application/octet;base64,' + base64)
req.responseType = 'arraybuffer'
req.onload = (e) => {
const bytes = new Uint8Array(req.response)
lzma.decompress(bytes, (result, err) => {
if (err) reject(err)
else resolve(result)
})
}
req.send()
})
}
export { compress, decompress }

View File

@ -1,6 +1,5 @@
<script lang="ts">
import { onMount } from 'svelte'
import * as lzma from '$lib/lzma'
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
@ -25,12 +24,8 @@
const hash = window.location.hash.slice(1)
if (hash) {
// decompress the data
if (hash.startsWith('XQAAA')) {
decompressed = await lzma.decompress(hash)
} else {
const brotli = import('$lib/brotli')
decompressed = await (await brotli).decompress(hash)
}
const { decompress } = await import('$lib/brotli')
decompressed = await decompress(hash)
// Markdown
if (lang === 'md') {
@ -64,26 +59,28 @@
</script>
<div>
<TopBar>
<a
href={'/editor' + getUrlDataPart()}
class="p-1 hover:bg-gray-600/50"
title="Edit a copy of this note"
>
<Icon class="text-xl" icon="fluent:document-edit-16-regular" />
</a>
</TopBar>
<div class="prose dark:prose-invert lg:py-12 p-[0.5em] md:max-w-3xl md:mx-auto lg:max-w-4xl">
{#if isMarkdown}
{@html decompressed}
{:else if isPlainText}
<div class="whitespace-pre-line">
{decompressed}
</div>
{:else}
<pre><code>{@html decompressed}</code></pre>
{/if}
</div>
{#if decompressed}
<TopBar>
<a
href={'/editor' + getUrlDataPart()}
class="p-1 hover:bg-gray-600/50"
title="Edit a copy of this note"
>
<Icon class="text-xl" icon="fluent:document-edit-16-regular" />
</a>
</TopBar>
<div class="prose dark:prose-invert lg:py-12 p-[0.5em] md:max-w-3xl md:mx-auto lg:max-w-4xl">
{#if isMarkdown}
{@html decompressed}
{:else if isPlainText}
<div class="whitespace-pre-line">
{decompressed}
</div>
{:else}
<pre><code>{@html decompressed}</code></pre>
{/if}
</div>
{/if}
</div>
<style lang="scss">

View File

@ -2,7 +2,6 @@
import type { Editor } from 'codemirror'
import { debounce } from 'lodash-es'
import * as brotli from '$lib/brotli'
import * as lzma from '$lib/lzma'
import { byId } from '$lib/utils'
import TopBar from '../../components/TopBar.svelte'
import { selectedLang, shareUrl } from '../../store'
@ -58,12 +57,7 @@
const hash = window.location.hash.slice(1)
if (hash) {
// decompress the data
let decompressed: string
if (hash.startsWith('XQAAA')) {
decompressed = await lzma.decompress(hash)
} else {
decompressed = await brotli.decompress(hash)
}
const decompressed = await brotli.decompress(hash)
// set the editor value
if (editor) {
editor.setValue(decompressed)