fix: Fix if vote is undefined

This commit is contained in:
Xyphyn committed 2023-07-13 19:09:55 -07:00
1 parent ff3246c0a6
commit 5f4c32fe2c
4 files changed
+25 -7

No files matched your search

+20 -3
View File
@@ -35,6 +35,19 @@
post_id: postRes.post.id,
})
}
function youtubeToPiped(url: string): string {
const youtubeDomainsRegex =
/^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\//i
if (youtubeDomainsRegex.test(url)) {
return url
.replace(youtubeDomainsRegex, '$1$2invidious.io.lol/')
.replace('www.', '')
}
return url
}
</script>
<Card class="bg-white flex flex-col overflow-hidden w-full relative p-5 gap-2">
@@ -87,14 +100,18 @@
src="{postRes.post.url}?thumbnail=1024&format=webp"
alt={postRes.post.name}
class="rounded-md max-h-[32rem] w-full max-w-full"
loading="lazy"
/>
</div>
{:else if postRes.post.embed_video_url}
<div class="self-start" class:blur-3xl={postRes.post.nsfw}>
<!-- svelte-ignore a11y-media-has-caption -->
<video class="rounded-md max-h-[32rem] w-full max-w-full" controls>
<source src={postRes.post.embed_video_url} />
</video>
{#if postRes.post.embed_video_url}
<embed
class="rounded-md max-h-[32rem] w-full max-w-full"
src={youtubeToPiped(postRes.post.embed_video_url)}
/>
{/if}
</div>
{:else if postRes.post.thumbnail_url}
<div class="self-start" class:blur-3xl={postRes.post.nsfw}>
+4
View File
@@ -12,6 +12,8 @@
async function upvote() {
if (!$authData) return
if (vote == undefined) vote = 0
const upvoted = vote == 1
if (vote == -1) {
@@ -36,6 +38,8 @@
async function downvote() {
if (!$authData) return
if (vote == undefined) vote = 0
const upvoted = vote == -1
if (vote == -1) {
-3
View File
@@ -77,11 +77,8 @@ authData.subscribe(async (data) => {
const site = await getClient().getSite({
auth: data.token,
})
if (!site?.my_user) throw Error('Missing user')
user.set({ ...site.my_user.local_user_view, unreads: 0 })
if (typeof localStorage != 'undefined') {
localStorage.setItem('user', JSON.stringify(data))
}
+1 -1
View File
@@ -15,7 +15,7 @@ const config = {
csp: {
directives: {
'script-src': ['self'],
'object-src': ['none'],
// 'object-src': ['none'],
'base-uri': ['none']
},
mode: 'nonce'