feat: support array target in transparency routes
This commit is contained in:
parent
c5fe9408cc
commit
ca16c361aa
|
|
@ -1,4 +1,5 @@
|
||||||
import { Elysia } from 'elysia';
|
import { Elysia } from 'elysia';
|
||||||
|
import { sql } from 'kysely'
|
||||||
|
|
||||||
import { db } from '@/utils/database'
|
import { db } from '@/utils/database'
|
||||||
import { m, eta, error } from '@/utils/html'
|
import { m, eta, error } from '@/utils/html'
|
||||||
|
|
@ -15,6 +16,10 @@ app.get('/transparency', async ({ set }) => {
|
||||||
|
|
||||||
const reports = await db.selectFrom('reports')
|
const reports = await db.selectFrom('reports')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
|
.where((eb) => eb.or([
|
||||||
|
eb('hidden', 'is', null),
|
||||||
|
eb('hidden', '=', false)
|
||||||
|
]))
|
||||||
.orderBy('date desc')
|
.orderBy('date desc')
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
|
|
@ -37,7 +42,7 @@ app.get('/transparency/:id', async ({ params: { id }, set, error }) => {
|
||||||
|
|
||||||
const json = await db.selectFrom('reports')
|
const json = await db.selectFrom('reports')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('target', '=', id)
|
.where(sql<boolean>`${id} = ANY(target)`)
|
||||||
.executeTakeFirst()
|
.executeTakeFirst()
|
||||||
if (!json) return error(404, 'Report not found.')
|
if (!json) return error(404, 'Report not found.')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Elysia } from 'elysia';
|
import { Elysia } from 'elysia';
|
||||||
|
import { sql } from 'kysely'
|
||||||
import DOMPurify from 'isomorphic-dompurify'
|
import DOMPurify from 'isomorphic-dompurify'
|
||||||
|
|
||||||
import { db } from '@/utils/database'
|
import { db } from '@/utils/database'
|
||||||
|
|
@ -91,7 +92,7 @@ app.get('/watch', async ({ query: { v }, set, redirect, error }) => {
|
||||||
if (json.hasBeenReported) {
|
if (json.hasBeenReported) {
|
||||||
transparency = await db.selectFrom('reports')
|
transparency = await db.selectFrom('reports')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('target', '=', json.id)
|
.where(sql<boolean>`${json.id} = ANY(target)`)
|
||||||
.execute()
|
.execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<% it.data.forEach(function(r){ %>
|
<% 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>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
<div class="reports">
|
<div class="reports">
|
||||||
<span class="reports-title">Somebody has complained about this video...</span> <br/>
|
<span class="reports-title">Somebody has complained about this video...</span> <br/>
|
||||||
<% it.transparency.forEach(function(t){ %>
|
<% it.transparency.forEach(function(t){ %>
|
||||||
<a href="/transparency/<%= t.target %>"><%= t.title %></a>
|
<a href="/transparency/<%= it.id %>"><%= t.title %></a>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,12 @@ export type UpdateVideo = Updateable<VideosTable>
|
||||||
|
|
||||||
export interface ReportsTable {
|
export interface ReportsTable {
|
||||||
uuid: Generated<string>
|
uuid: Generated<string>
|
||||||
target: string
|
target: string[]
|
||||||
title: string
|
title: string
|
||||||
details: string
|
details: string
|
||||||
date: Date
|
date: Date
|
||||||
pdf_url?: string | null
|
pdf_url?: string | null
|
||||||
|
hidden?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Report = Selectable<ReportsTable>
|
export type Report = Selectable<ReportsTable>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue