mirror of https://github.com/TZGyn/shortener
add public routes for viewing qr code + switched using qr-code-styling for qr code generation
parent
338839974e
commit
ee81c52172
Binary file not shown.
@ -1,6 +0,0 @@
|
||||
import type { PageServerLoad } from './$types'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export const load = (async () => {
|
||||
return redirect(300, '/')
|
||||
}) satisfies PageServerLoad
|
||||
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
import { goto } from '$app/navigation'
|
||||
import Button from '$lib/components/ui/button/button.svelte'
|
||||
</script>
|
||||
|
||||
<div class="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
|
||||
<div class="flex flex-col items-center gap-12">
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<div class="text-4xl font-bold">404</div>
|
||||
<div class="text-4xl font-bold">Invalid Url</div>
|
||||
</div>
|
||||
<Button on:click={() => goto('/')} class="w-fit">Return</Button>
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,79 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/ui/button'
|
||||
import { toast } from 'svelte-sonner'
|
||||
import { Badge } from '$lib/components/ui/badge'
|
||||
import QRCodeStyling from 'qr-code-styling'
|
||||
import { onMount } from 'svelte'
|
||||
import * as Card from '$lib/components/ui/card'
|
||||
|
||||
export let data
|
||||
|
||||
let image = ''
|
||||
|
||||
const copyImageToClipboard = async () => {
|
||||
if (!image) return
|
||||
|
||||
const imageData = await fetch(image)
|
||||
|
||||
const imageBlob = await imageData.blob()
|
||||
|
||||
try {
|
||||
navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
'image/png': imageBlob,
|
||||
}),
|
||||
])
|
||||
toast.success('Copied Image To Clipboard')
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
'Unable to copy item to clipboard. If you are using firefox, you can change the setting dom.events.asyncclipboard.clipboarditem in about:config to true',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async function generateQrCode() {
|
||||
const qrcodestyling = new QRCodeStyling({
|
||||
data: data.url + '/' + data.shortenerId,
|
||||
width: 300,
|
||||
height: 300,
|
||||
margin: 10,
|
||||
qrOptions: {
|
||||
errorCorrectionLevel: 'L',
|
||||
typeNumber: 0,
|
||||
},
|
||||
backgroundOptions: {
|
||||
color: data.colorSetting?.color.background || '#fff',
|
||||
},
|
||||
dotsOptions: {
|
||||
color: data.colorSetting?.color.foreground || '#000',
|
||||
},
|
||||
cornersSquareOptions: {
|
||||
type: 'square',
|
||||
},
|
||||
})
|
||||
const blob = await qrcodestyling.getRawData()
|
||||
if (!blob) return
|
||||
image = URL.createObjectURL(blob)
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
generateQrCode()
|
||||
})
|
||||
</script>
|
||||
|
||||
<Card.Root
|
||||
class="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
|
||||
<Card.Header class="flex-col items-center gap-4">
|
||||
<Badge variant="secondary" class="w-fit">
|
||||
{data.url + '/' + data.shortenerId}
|
||||
</Badge>
|
||||
<img
|
||||
src={image}
|
||||
alt={data.url + '/' + data.shortenerId}
|
||||
width={300}
|
||||
height={300} />
|
||||
<Button class="w-full" on:click={copyImageToClipboard}>
|
||||
Copy Image
|
||||
</Button>
|
||||
</Card.Header>
|
||||
</Card.Root>
|
||||
Loading…
Reference in New Issue