Fixed upload flow
This commit is contained in:
parent
0677b13902
commit
a200dc05e3
1 changed files with 8 additions and 2 deletions
|
|
@ -1,12 +1,18 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
import { writeFile } from 'node:fs/promises'
|
import { writeFile, readFile } from 'node:fs/promises'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import config from '@/config/config.json'
|
|
||||||
|
|
||||||
export const runtime = 'nodejs'
|
export const runtime = 'nodejs'
|
||||||
|
|
||||||
|
async function getConfig() {
|
||||||
|
const configPath = path.join(process.cwd(), 'src', 'config', 'config.json')
|
||||||
|
const content = await readFile(configPath, 'utf8')
|
||||||
|
return JSON.parse(content)
|
||||||
|
}
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
const password = req.headers.get('x-admin-password') || ''
|
const password = req.headers.get('x-admin-password') || ''
|
||||||
|
const config = await getConfig()
|
||||||
|
|
||||||
if (password !== config.adminPassword) {
|
if (password !== config.adminPassword) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue