feat: support array target in transparency routes

This commit is contained in:
localhost 2026-08-31 12:54:18 +02:00
parent c5fe9408cc
commit ca16c361aa
5 changed files with 12 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import { Elysia } from 'elysia';
import { sql } from 'kysely'
import { db } from '@/utils/database'
import { m, eta, error } from '@/utils/html'
@ -15,6 +16,10 @@ app.get('/transparency', async ({ set }) => {
const reports = await db.selectFrom('reports')
.selectAll()
.where((eb) => eb.or([
eb('hidden', 'is', null),
eb('hidden', '=', false)
]))
.orderBy('date desc')
.execute()
@ -37,7 +42,7 @@ app.get('/transparency/:id', async ({ params: { id }, set, error }) => {
const json = await db.selectFrom('reports')
.selectAll()
.where('target', '=', id)
.where(sql<boolean>`${id} = ANY(target)`)
.executeTakeFirst()
if (!json) return error(404, 'Report not found.')

View File

@ -1,4 +1,5 @@
import { Elysia } from 'elysia';
import { sql } from 'kysely'
import DOMPurify from 'isomorphic-dompurify'
import { db } from '@/utils/database'
@ -91,7 +92,7 @@ app.get('/watch', async ({ query: { v }, set, redirect, error }) => {
if (json.hasBeenReported) {
transparency = await db.selectFrom('reports')
.selectAll()
.where('target', '=', json.id)
.where(sql<boolean>`${json.id} = ANY(target)`)
.execute()
}

View File

@ -2,7 +2,7 @@
<div class="grid">
<% it.data.forEach(function(r){ %>
<a class="title" href="/transparency/<%= r.target %>"><%= r.title %></a>
<a class="title" href="/transparency/<%= r.target[0] %>"><%= r.title %></a>
<% }) %>
</div>

View File

@ -62,7 +62,7 @@
<div class="reports">
<span class="reports-title">Somebody has complained about this video...</span> <br/>
<% it.transparency.forEach(function(t){ %>
<a href="/transparency/<%= t.target %>"><%= t.title %></a>
<a href="/transparency/<%= it.id %>"><%= t.title %></a>
<% }) %>
</div>
<% } %>

View File

@ -36,11 +36,12 @@ export type UpdateVideo = Updateable<VideosTable>
export interface ReportsTable {
uuid: Generated<string>
target: string
target: string[]
title: string
details: string
date: Date
pdf_url?: string | null
hidden?: boolean
}
export type Report = Selectable<ReportsTable>