66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import {
|
|
generateSignature,
|
|
getDatabaseConnection,
|
|
jsonResponse
|
|
} from '../../../lib/util'
|
|
import { berryDashSplashTexts } from '../../../lib/tables'
|
|
import { eq } from 'drizzle-orm'
|
|
import { Context } from 'elysia'
|
|
|
|
export const handler = async (context: Context) => {
|
|
const dbInfo1 = getDatabaseConnection(1)
|
|
|
|
if (!dbInfo1)
|
|
return new Response('', {
|
|
status: 200,
|
|
headers: { 'Content-Type': 'text/plain' }
|
|
})
|
|
const { connection: connection1, db: db1 } = dbInfo1
|
|
|
|
const requester = context.headers.requester
|
|
const clientVersion = context.headers.clientversion
|
|
|
|
const result = await db1
|
|
.select({
|
|
content: berryDashSplashTexts.content,
|
|
attributes: berryDashSplashTexts.attributes
|
|
})
|
|
.from(berryDashSplashTexts)
|
|
.where(eq(berryDashSplashTexts.state, 1))
|
|
.execute()
|
|
|
|
connection1.end()
|
|
|
|
if (
|
|
!requester ||
|
|
!clientVersion ||
|
|
(requester == 'BerryDashClient' && clientVersion == '26.1')
|
|
) {
|
|
const data = result
|
|
.filter(v => {
|
|
if (clientVersion && clientVersion == '26.1' && v.attributes)
|
|
return false
|
|
return true
|
|
})
|
|
.map(i => atob(i.content))
|
|
|
|
const body = data.join('\n')
|
|
return new Response(body, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'text/plain',
|
|
'X-Signature': generateSignature(body)
|
|
}
|
|
})
|
|
} else {
|
|
return jsonResponse(
|
|
result.map(v => {
|
|
const data = v
|
|
v.content = atob(v.content)
|
|
v.attributes = v.attributes ? JSON.parse(v.attributes) : {}
|
|
return data
|
|
})
|
|
)
|
|
}
|
|
}
|