Removed LZMA compression
This commit is contained in:
parent
ad4b21daf1
commit
b620536eb8
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
> A no-database, no-backend pastebin-like service. All the data is stored in the url.
|
> 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
|
## TODO
|
||||||
|
|
||||||
- [x] Use brotli
|
- [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
|
- [x] Have a read-only view with nice colors for code blocks
|
||||||
- [ ] Use CodeMirror 6
|
- [ ] Use CodeMirror 6
|
||||||
- [ ] 100% self-contained, no dependance on jsdeliver
|
- [ ] 100% self-contained, no dependance on jsdeliver
|
||||||
|
|
|
@ -14,8 +14,6 @@ npm/codemirror@5.65.16/theme/nord.min.css"
|
||||||
/>
|
/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/combine/npm/lzma@2.3.2/src/lzma.min.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body data-sveltekit-preload-data="hover">
|
||||||
<div class="dark:text-gray-300 dark:bg-gray-800 min-h-screen">%sveltekit.body%</div>
|
<div class="dark:text-gray-300 dark:bg-gray-800 min-h-screen">%sveltekit.body%</div>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<h1 class="text-xl">Paste</h1>
|
<h1 class="text-xl">Paste</h1>
|
||||||
<span class="ml-8 text-xs">
|
<span class="ml-8 text-xs">
|
||||||
<a
|
<a
|
||||||
href="/?l=md#G14EICwPbMc0BJ69xNPoItLoErDRMwMj3+vxE5RxArxajeByk+b0b1Tm2h/5ugGgK6S83AqUCi09HeYmDs+vvzQc0QDZe7v7U2rHnFe6CTWSm2AArNua4tqtXVIEFVQuqG+is15etOm1OZOPPCH4xDX1iDNF2bQcN9ugum0Icnwj51n0nlvNacn/N3OOctSGrQbLoNzG8n5bSoJQXOx+PsxV+MeUl+rkKNPIAXT9c8LoOY/772FiFkLv/5w8rvtCBc38VEE5lzmGFcZ0QtqlzBhvWLV5WPhRkROqeoKoDCtH03/fQVI5Y8HfLkq2/Nuidd1GQTKgmPJQVWbZ4cAiqUdOJG6j6pvu48qWjqamYG3nFPHcdYLHYCRV877U2mBgSHTbLWv6eu/DEA88SE5XEIqiQFyDVS2HLN7jJSloLHQJ+jOE86zb9jrkQ9tXAwkAoovCcnlrW5T/EU4L7imRsDAkZdEySO/ri/NBuHPMpSFnqGItLlPd98/SZSmySbImOLfv4WGbdCxw9TYykGsk56aQaVSa/DB2t5HfD6x28lJVlMm3Hjnkwyx95PxNGH0teCAk6CqtbBYlC3LjhY0IEpJ0WWZWY6MlJB+jEW7lAN3DSJD0QFz2FZOOV/HwA9LbFBU="
|
href="?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"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
About
|
About
|
||||||
|
|
6
src/globals.d.ts
vendored
6
src/globals.d.ts
vendored
|
@ -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
|
declare const CodeMirror: any
|
||||||
|
|
|
@ -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 }
|
|
|
@ -1,6 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import * as lzma from '$lib/lzma'
|
|
||||||
import { unified } from 'unified'
|
import { unified } from 'unified'
|
||||||
import remarkParse from 'remark-parse'
|
import remarkParse from 'remark-parse'
|
||||||
import remarkRehype from 'remark-rehype'
|
import remarkRehype from 'remark-rehype'
|
||||||
|
@ -25,12 +24,8 @@
|
||||||
const hash = window.location.hash.slice(1)
|
const hash = window.location.hash.slice(1)
|
||||||
if (hash) {
|
if (hash) {
|
||||||
// decompress the data
|
// decompress the data
|
||||||
if (hash.startsWith('XQAAA')) {
|
const { decompress } = await import('$lib/brotli')
|
||||||
decompressed = await lzma.decompress(hash)
|
decompressed = await decompress(hash)
|
||||||
} else {
|
|
||||||
const brotli = import('$lib/brotli')
|
|
||||||
decompressed = await (await brotli).decompress(hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Markdown
|
// Markdown
|
||||||
if (lang === 'md') {
|
if (lang === 'md') {
|
||||||
|
@ -64,6 +59,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
{#if decompressed}
|
||||||
<TopBar>
|
<TopBar>
|
||||||
<a
|
<a
|
||||||
href={'/editor' + getUrlDataPart()}
|
href={'/editor' + getUrlDataPart()}
|
||||||
|
@ -84,6 +80,7 @@
|
||||||
<pre><code>{@html decompressed}</code></pre>
|
<pre><code>{@html decompressed}</code></pre>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import type { Editor } from 'codemirror'
|
import type { Editor } from 'codemirror'
|
||||||
import { debounce } from 'lodash-es'
|
import { debounce } from 'lodash-es'
|
||||||
import * as brotli from '$lib/brotli'
|
import * as brotli from '$lib/brotli'
|
||||||
import * as lzma from '$lib/lzma'
|
|
||||||
import { byId } from '$lib/utils'
|
import { byId } from '$lib/utils'
|
||||||
import TopBar from '../../components/TopBar.svelte'
|
import TopBar from '../../components/TopBar.svelte'
|
||||||
import { selectedLang, shareUrl } from '../../store'
|
import { selectedLang, shareUrl } from '../../store'
|
||||||
|
@ -58,12 +57,7 @@
|
||||||
const hash = window.location.hash.slice(1)
|
const hash = window.location.hash.slice(1)
|
||||||
if (hash) {
|
if (hash) {
|
||||||
// decompress the data
|
// decompress the data
|
||||||
let decompressed: string
|
const decompressed = await brotli.decompress(hash)
|
||||||
if (hash.startsWith('XQAAA')) {
|
|
||||||
decompressed = await lzma.decompress(hash)
|
|
||||||
} else {
|
|
||||||
decompressed = await brotli.decompress(hash)
|
|
||||||
}
|
|
||||||
// set the editor value
|
// set the editor value
|
||||||
if (editor) {
|
if (editor) {
|
||||||
editor.setValue(decompressed)
|
editor.setValue(decompressed)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user