Fixes
This commit is contained in:
4 files changed
+40
-11
No files matched your search
+7
-4
@@ -14,21 +14,24 @@ import { createHash, createPrivateKey, sign } from 'crypto'
|
|||||||
import { and, eq, sql } from 'drizzle-orm'
|
import { and, eq, sql } from 'drizzle-orm'
|
||||||
import { verifyCodes } from './tables'
|
import { verifyCodes } from './tables'
|
||||||
|
|
||||||
export const jsonResponse = (data: any, status = 200) => {
|
export const generateSignature = (body: string) => {
|
||||||
const body = JSON.stringify(data)
|
|
||||||
|
|
||||||
const key = Buffer.from(
|
const key = Buffer.from(
|
||||||
process.env.PRIVATE_SIGNING_KEY ?? '',
|
process.env.PRIVATE_SIGNING_KEY ?? '',
|
||||||
'base64'
|
'base64'
|
||||||
).toString('utf-8')
|
).toString('utf-8')
|
||||||
const privateKey = createPrivateKey(key)
|
const privateKey = createPrivateKey(key)
|
||||||
const signature = sign(null, Buffer.from(body), privateKey).toString('base64')
|
const signature = sign(null, Buffer.from(body), privateKey).toString('base64')
|
||||||
|
return signature
|
||||||
|
}
|
||||||
|
|
||||||
|
export const jsonResponse = (data: any, status = 200) => {
|
||||||
|
const body = JSON.stringify(data)
|
||||||
|
|
||||||
return new Response(body, {
|
return new Response(body, {
|
||||||
status,
|
status,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Signature': signature
|
'X-Signature': generateSignature(body)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
import {
|
||||||
|
generateSignature,
|
||||||
|
getDatabaseConnection,
|
||||||
|
jsonResponse
|
||||||
|
} from '../../../lib/util'
|
||||||
import { berryDashSplashTexts } from '../../../lib/tables'
|
import { berryDashSplashTexts } from '../../../lib/tables'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
import { Context } from 'elysia'
|
import { Context } from 'elysia'
|
||||||
@@ -40,9 +44,13 @@ export const handler = async (context: Context) => {
|
|||||||
})
|
})
|
||||||
.map(i => atob(i.content))
|
.map(i => atob(i.content))
|
||||||
|
|
||||||
return new Response(data.join('\n'), {
|
const body = data.join('\n')
|
||||||
|
return new Response(body, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: { 'Content-Type': 'text/plain' }
|
headers: {
|
||||||
|
'Content-Type': 'text/plain',
|
||||||
|
'X-Signature': generateSignature(body)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return jsonResponse(
|
return jsonResponse(
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { launcherUpdates } from '../../../lib/tables'
|
import { launcherUpdates } from '../../../lib/tables'
|
||||||
import { desc, eq } from 'drizzle-orm'
|
import { desc, eq } from 'drizzle-orm'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
import {
|
||||||
|
generateSignature,
|
||||||
|
getDatabaseConnection,
|
||||||
|
jsonResponse
|
||||||
|
} from '../../../lib/util'
|
||||||
|
|
||||||
export const handler = async () => {
|
export const handler = async () => {
|
||||||
const dbResult = getDatabaseConnection(0)
|
const dbResult = getDatabaseConnection(0)
|
||||||
@@ -19,5 +23,10 @@ export const handler = async () => {
|
|||||||
|
|
||||||
connection.end()
|
connection.end()
|
||||||
|
|
||||||
return version[0].id
|
return new Response(version[0].id, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Signature': generateSignature(version[0].id)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
import { loaderUpdates } from '../../../../lib/tables'
|
import { loaderUpdates } from '../../../../lib/tables'
|
||||||
import { desc, eq } from 'drizzle-orm'
|
import { desc, eq } from 'drizzle-orm'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../../../lib/util'
|
import {
|
||||||
|
generateSignature,
|
||||||
|
getDatabaseConnection,
|
||||||
|
jsonResponse
|
||||||
|
} from '../../../../lib/util'
|
||||||
|
|
||||||
export const handler = async () => {
|
export const handler = async () => {
|
||||||
const dbResult = getDatabaseConnection(0)
|
const dbResult = getDatabaseConnection(0)
|
||||||
@@ -19,5 +23,10 @@ export const handler = async () => {
|
|||||||
|
|
||||||
connection.end()
|
connection.end()
|
||||||
|
|
||||||
return version[0].id
|
return new Response(version[0].id, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Signature': generateSignature(version[0].id)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user