add dropzone for releases page

This commit is contained in:
2025-06-21 13:08:01 +02:00
parent c06f8cce04
commit 228cf6caa3
2 changed files with 11 additions and 12 deletions

View File

@@ -94,7 +94,6 @@ export function ReleasesClient() {
// Fetch branches from the database
const [branches] = api.branches.getBranches.useSuspenseQuery()
console.log(branches)
// Handle file upload
const [editIsUploading, setEditIsUploading] = useState(false)
@@ -104,6 +103,9 @@ export function ReleasesClient() {
if (files.length === 0) return
const file = files[0]
if (!file) {
return
}
if (!file.name.endsWith('.zip')) {
toast.error('Only zip files are allowed')
return
@@ -119,6 +121,9 @@ export function ReleasesClient() {
try {
const formData = new FormData()
if (!file) {
return
}
formData.append('file', file)
const response = await fetch('/api/upload', {
@@ -544,7 +549,7 @@ export function ReleasesClient() {
<DropzoneGroup className='gap-2'>
{editIsUploading ? (
<div className='flex items-center justify-center'>
<div className='h-6 w-6 animate-spin rounded-full border-primary border-b-2'></div>
<div className='h-6 w-6 animate-spin rounded-full border-primary border-b-2' />
</div>
) : (
<DropzoneUploadIcon />

View File

@@ -1,16 +1,13 @@
import { auth } from '@/server/auth'
import { uploadFile } from '@/server/minio'
import { NextRequest, NextResponse } from 'next/server'
import { type NextRequest, NextResponse } from 'next/server'
export async function POST(req: NextRequest) {
try {
// Check if user is authenticated and is an admin
const session = await auth()
if (!session || session.user.role !== 'admin') {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
)
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
// Parse the multipart form data
@@ -18,10 +15,7 @@ export async function POST(req: NextRequest) {
const file = formData.get('file') as File | null
if (!file) {
return NextResponse.json(
{ error: 'No file provided' },
{ status: 400 }
)
return NextResponse.json({ error: 'No file provided' }, { status: 400 })
}
// Check if the file is a zip file