mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: allow staff members to see user's unlisted pastes; show dislikes in the paste lists
This commit is contained in:
@@ -12,7 +12,8 @@
|
|||||||
Lock,
|
Lock,
|
||||||
EyeOff,
|
EyeOff,
|
||||||
Globe,
|
Globe,
|
||||||
HatGlasses
|
HatGlasses,
|
||||||
|
ThumbsUp
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import { syntaxes } from '$lib/consts';
|
import { syntaxes } from '$lib/consts';
|
||||||
import type { Paste } from '$lib/types/paste';
|
import type { Paste } from '$lib/types/paste';
|
||||||
@@ -27,6 +28,8 @@
|
|||||||
let { paste, now, showUser = true, compact = false }: Props = $props();
|
let { paste, now, showUser = true, compact = false }: Props = $props();
|
||||||
|
|
||||||
let syntax = $derived(syntaxes[paste.syntax] ?? syntaxes['plaintext']);
|
let syntax = $derived(syntaxes[paste.syntax] ?? syntaxes['plaintext']);
|
||||||
|
let netLikes = $derived(paste.likes - paste.dislikes);
|
||||||
|
let netLikeText = $derived(`${formatNumber(netLikes)} Like${netLikes === 1 ? '' : 's'}`);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if compact}
|
{#if compact}
|
||||||
@@ -83,10 +86,18 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex flex-wrap items-center gap-x-3 gap-y-1">
|
||||||
|
<span class="flex items-center gap-2">
|
||||||
<Eye class="h-4 w-4" />
|
<Eye class="h-4 w-4" />
|
||||||
|
|
||||||
{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}
|
{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="flex items-center gap-2"
|
||||||
|
use:tooltip={`${formatNumber(paste.likes)} likes, ${formatNumber(paste.dislikes)} dislikes`}
|
||||||
|
>
|
||||||
|
<ThumbsUp class="h-4 w-4" />
|
||||||
|
{netLikeText}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -175,13 +186,20 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="grid grid-cols-[auto_auto] gap-x-4 gap-y-1 text-sm text-neutral-400">
|
||||||
<div class="flex items-center gap-2 text-sm text-neutral-400">
|
<div class="flex items-center gap-2">
|
||||||
<Eye class="h-4 w-4" />
|
<Eye class="h-4 w-4" />
|
||||||
<span>{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}</span>
|
<span>{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="mt-1 flex items-center gap-2 text-sm text-neutral-400"
|
class="flex items-center gap-2"
|
||||||
|
use:tooltip={`${formatNumber(paste.likes)} likes, ${formatNumber(paste.dislikes)} dislikes`}
|
||||||
|
>
|
||||||
|
<ThumbsUp class="h-4 w-4" />
|
||||||
|
<span>{netLikeText}</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="flex items-center gap-2"
|
||||||
use:tooltip={paste.isCompressed
|
use:tooltip={paste.isCompressed
|
||||||
? `Compressed Size: ${formatBytes(paste.storedSize)}`
|
? `Compressed Size: ${formatBytes(paste.storedSize)}`
|
||||||
: ''}
|
: ''}
|
||||||
@@ -189,7 +207,7 @@
|
|||||||
<FileBox class="h-4 w-4" />
|
<FileBox class="h-4 w-4" />
|
||||||
<span>{formatBytes(paste.originalSize)}</span>
|
<span>{formatBytes(paste.originalSize)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1 flex items-center gap-2 text-sm text-neutral-400">
|
<div class="flex items-center gap-2">
|
||||||
<Code class="h-4 w-4" />
|
<Code class="h-4 w-4" />
|
||||||
<span>{syntax.name}</span>
|
<span>{syntax.name}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -397,6 +397,8 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
Visibility = p.Visibility,
|
Visibility = p.Visibility,
|
||||||
ExpiresAt = p.ExpiresAt,
|
ExpiresAt = p.ExpiresAt,
|
||||||
EditedAt = p.EditedAt,
|
EditedAt = p.EditedAt,
|
||||||
|
Likes = p.PositiveInteractionCount,
|
||||||
|
Dislikes = p.NegativeInteractionCount,
|
||||||
Author =
|
Author =
|
||||||
p.User != null && p.User.Visibility == 0
|
p.User != null && p.User.Visibility == 0
|
||||||
? new UserSimpleDto
|
? new UserSimpleDto
|
||||||
|
|||||||
@@ -285,6 +285,11 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
{
|
{
|
||||||
if (user.Visibility == Visibility.Private && !requesterIsStaff)
|
if (user.Visibility == Visibility.Private && !requesterIsStaff)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
if (requesterIsStaff)
|
||||||
|
pasteQuery = pasteQuery.Where(p => p.Visibility != Visibility.Private);
|
||||||
|
else if (user.Visibility == Visibility.Unlisted)
|
||||||
|
pasteQuery = pasteQuery.Where(p => p.Visibility != Visibility.Private);
|
||||||
else if (user.Visibility != Visibility.Unlisted)
|
else if (user.Visibility != Visibility.Unlisted)
|
||||||
pasteQuery = pasteQuery.Where(p => p.Visibility == Visibility.Public);
|
pasteQuery = pasteQuery.Where(p => p.Visibility == Visibility.Public);
|
||||||
}
|
}
|
||||||
@@ -314,6 +319,8 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
Visibility = p.Visibility,
|
Visibility = p.Visibility,
|
||||||
EditedAt = p.EditedAt,
|
EditedAt = p.EditedAt,
|
||||||
ExpiresAt = p.ExpiresAt,
|
ExpiresAt = p.ExpiresAt,
|
||||||
|
Likes = p.Interactions.Count(i => i.Type == Interaction.Positive),
|
||||||
|
Dislikes = p.Interactions.Count(i => i.Type == Interaction.Negative),
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,32 @@ namespace SharpbinV3.Server.Services
|
|||||||
if (publicOnly)
|
if (publicOnly)
|
||||||
query = query.Where(p => p.Visibility == 0);
|
query = query.Where(p => p.Visibility == 0);
|
||||||
|
|
||||||
return await query.OrderByDescending(p => p.PID).Skip(offset).Take(count).Include(p => p.User).ToListAsync();
|
var pastes = await query.OrderByDescending(p => p.PID).Skip(offset).Take(count).Include(p => p.User).ToListAsync();
|
||||||
|
|
||||||
|
if (pastes.Count == 0)
|
||||||
|
return pastes;
|
||||||
|
|
||||||
|
var pasteIds = pastes.Select(p => p.PID).ToArray();
|
||||||
|
var interactionCounts = (
|
||||||
|
await _db
|
||||||
|
.PasteInteractions.Where(pi => pasteIds.Contains(pi.PasteID))
|
||||||
|
.GroupBy(pi => new { pi.PasteID, pi.Type })
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
g.Key.PasteID,
|
||||||
|
g.Key.Type,
|
||||||
|
Count = g.Count(),
|
||||||
|
})
|
||||||
|
.ToListAsync()
|
||||||
|
).ToDictionary(counts => (counts.PasteID, counts.Type), counts => counts.Count);
|
||||||
|
|
||||||
|
foreach (var paste in pastes)
|
||||||
|
{
|
||||||
|
paste.PositiveInteractionCount = interactionCounts.GetValueOrDefault((paste.PID, Interaction.Positive));
|
||||||
|
paste.NegativeInteractionCount = interactionCounts.GetValueOrDefault((paste.PID, Interaction.Negative));
|
||||||
|
}
|
||||||
|
|
||||||
|
return pastes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PasteInteraction?> GetUserInteraction(Paste paste, Guid userUUID)
|
public async Task<PasteInteraction?> GetUserInteraction(Paste paste, Guid userUUID)
|
||||||
|
|||||||
Reference in New Issue
Block a user