fixed issues
This commit is contained in:
parent
fa16e106ce
commit
9ec514dcf2
2 changed files with 27 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
import { writeFile, readFile } from 'node:fs/promises'
|
import { writeFile, readFile, mkdir } from 'node:fs/promises'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
|
||||||
export const runtime = 'nodejs'
|
export const runtime = 'nodejs'
|
||||||
|
|
@ -27,7 +27,9 @@ export async function POST(req: NextRequest) {
|
||||||
if (csvFile) {
|
if (csvFile) {
|
||||||
try {
|
try {
|
||||||
const buffer = await csvFile.arrayBuffer()
|
const buffer = await csvFile.arrayBuffer()
|
||||||
const csvPath = path.join(process.cwd(), 'src', 'data', csvFile.name)
|
const csvDir = path.join(process.cwd(), 'src', 'data')
|
||||||
|
await mkdir(csvDir, { recursive: true })
|
||||||
|
const csvPath = path.join(csvDir, csvFile.name)
|
||||||
await writeFile(csvPath, Buffer.from(buffer))
|
await writeFile(csvPath, Buffer.from(buffer))
|
||||||
results.csv = `✓ CSV uploaded: ${csvFile.name}`
|
results.csv = `✓ CSV uploaded: ${csvFile.name}`
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
@ -38,7 +40,9 @@ export async function POST(req: NextRequest) {
|
||||||
if (logoFile) {
|
if (logoFile) {
|
||||||
try {
|
try {
|
||||||
const buffer = await logoFile.arrayBuffer()
|
const buffer = await logoFile.arrayBuffer()
|
||||||
const logoPath = path.join(process.cwd(), 'public', 'branding', logoFile.name)
|
const logoDir = path.join(process.cwd(), 'public', 'branding')
|
||||||
|
await mkdir(logoDir, { recursive: true })
|
||||||
|
const logoPath = path.join(logoDir, logoFile.name)
|
||||||
await writeFile(logoPath, Buffer.from(buffer))
|
await writeFile(logoPath, Buffer.from(buffer))
|
||||||
results.logo = `✓ Logo uploaded: ${logoFile.name}`
|
results.logo = `✓ Logo uploaded: ${logoFile.name}`
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
@ -50,5 +54,9 @@ export async function POST(req: NextRequest) {
|
||||||
return NextResponse.json({ error: 'No files provided' }, { status: 400 })
|
return NextResponse.json({ error: 'No files provided' }, { status: 400 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (results.error) {
|
||||||
|
return NextResponse.json(results, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json(results)
|
return NextResponse.json(results)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,21 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { readFile } from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
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 GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
const auth = req.nextUrl.searchParams.get('auth') || ''
|
const config = await getConfig()
|
||||||
const redirectUrl = new URL('/', req.url)
|
const url = req.nextUrl.clone()
|
||||||
if (auth) {
|
url.pathname = '/'
|
||||||
redirectUrl.searchParams.set('auth', auth)
|
url.search = ''
|
||||||
|
if (config.authString) {
|
||||||
|
url.searchParams.set('auth', config.authString)
|
||||||
}
|
}
|
||||||
return NextResponse.redirect(redirectUrl)
|
|
||||||
|
return NextResponse.redirect(url)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue