upd: api mobile

Deskripsi:
- api create banner upload gambar

No Issues
This commit is contained in:
amel
2025-05-14 17:37:43 +08:00
parent cda1bdd12e
commit 228b6f944f

View File

@@ -1,5 +1,5 @@
import { DIR, funUploadFile, funViewDir, prisma } from "@/module/_global";
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
import { funGetUserById } from "@/module/auth";
import { createLogUser } from "@/module/user";
import { NextResponse } from "next/server";
@@ -38,12 +38,16 @@ export async function GET(request: Request) {
// CREATE BANNER
export async function POST(request: Request) {
try {
console.log('masuk')
console.log('masuklas')
console.log(request)
const body = await request.formData()
const file = body.get("file") as File;
const fileAwal = body.get("file");
const file = JSON.parse(fileAwal as string)
const fileFix = file as File
const fileCoba = new File([fileFix], fileFix.name, { type: fileFix.type});
const data = body.get("data");
console.log(data)
console.log(body, fileCoba)
const { title, user } = JSON.parse(data as string)
@@ -54,12 +58,12 @@ export async function POST(request: Request) {
const userLogin = await funGetUserById({ id: user })
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
const newFile = new File([file], file.name, { type: file.type });
const fExt = fileCoba.name.split(".").pop()
const fName = fileCoba.name.replace("." + fExt, "")
const newFile = new File([fileCoba], fileCoba.name, { type: fileCoba.type });
const ini = funViewDir({ dirId: DIR.user })
const upload = await funUploadFile({ file: newFile, dirId: DIR.banner })
const upload = await funUploadFile({ file: fileCoba, dirId: DIR.banner })
if (upload.success) {
const create = await prisma.bannerImage.create({
data: {