mirror of
https://github.com/ershisan99/www.git
synced 2025-12-17 05:19:23 +00:00
add dropzone for releases page
This commit is contained in:
@@ -94,7 +94,6 @@ export function ReleasesClient() {
|
|||||||
|
|
||||||
// Fetch branches from the database
|
// Fetch branches from the database
|
||||||
const [branches] = api.branches.getBranches.useSuspenseQuery()
|
const [branches] = api.branches.getBranches.useSuspenseQuery()
|
||||||
console.log(branches)
|
|
||||||
|
|
||||||
// Handle file upload
|
// Handle file upload
|
||||||
const [editIsUploading, setEditIsUploading] = useState(false)
|
const [editIsUploading, setEditIsUploading] = useState(false)
|
||||||
@@ -104,6 +103,9 @@ export function ReleasesClient() {
|
|||||||
if (files.length === 0) return
|
if (files.length === 0) return
|
||||||
|
|
||||||
const file = files[0]
|
const file = files[0]
|
||||||
|
if (!file) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!file.name.endsWith('.zip')) {
|
if (!file.name.endsWith('.zip')) {
|
||||||
toast.error('Only zip files are allowed')
|
toast.error('Only zip files are allowed')
|
||||||
return
|
return
|
||||||
@@ -119,6 +121,9 @@ export function ReleasesClient() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
|
if (!file) {
|
||||||
|
return
|
||||||
|
}
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
|
|
||||||
const response = await fetch('/api/upload', {
|
const response = await fetch('/api/upload', {
|
||||||
@@ -544,7 +549,7 @@ export function ReleasesClient() {
|
|||||||
<DropzoneGroup className='gap-2'>
|
<DropzoneGroup className='gap-2'>
|
||||||
{editIsUploading ? (
|
{editIsUploading ? (
|
||||||
<div className='flex items-center justify-center'>
|
<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>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<DropzoneUploadIcon />
|
<DropzoneUploadIcon />
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
import { auth } from '@/server/auth'
|
import { auth } from '@/server/auth'
|
||||||
import { uploadFile } from '@/server/minio'
|
import { uploadFile } from '@/server/minio'
|
||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { type NextRequest, NextResponse } from 'next/server'
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
// Check if user is authenticated and is an admin
|
// Check if user is authenticated and is an admin
|
||||||
const session = await auth()
|
const session = await auth()
|
||||||
if (!session || session.user.role !== 'admin') {
|
if (!session || session.user.role !== 'admin') {
|
||||||
return NextResponse.json(
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
{ error: 'Unauthorized' },
|
|
||||||
{ status: 401 }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the multipart form data
|
// Parse the multipart form data
|
||||||
@@ -18,10 +15,7 @@ export async function POST(req: NextRequest) {
|
|||||||
const file = formData.get('file') as File | null
|
const file = formData.get('file') as File | null
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return NextResponse.json(
|
return NextResponse.json({ error: 'No file provided' }, { status: 400 })
|
||||||
{ error: 'No file provided' },
|
|
||||||
{ status: 400 }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the file is a zip file
|
// Check if the file is a zip file
|
||||||
@@ -47,4 +41,4 @@ export async function POST(req: NextRequest) {
|
|||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user