upd: api mobile
Deskripsi: - api create banner upload gambar No Issues
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { DIR, funUploadFile, funViewDir, prisma } from "@/module/_global";
|
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 { createLogUser } from "@/module/user";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -38,12 +38,16 @@ export async function GET(request: Request) {
|
|||||||
// CREATE BANNER
|
// CREATE BANNER
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
console.log('masuk')
|
console.log('masuklas')
|
||||||
|
console.log(request)
|
||||||
const body = await request.formData()
|
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");
|
const data = body.get("data");
|
||||||
|
|
||||||
console.log(data)
|
console.log(body, fileCoba)
|
||||||
|
|
||||||
const { title, user } = JSON.parse(data as string)
|
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 userLogin = await funGetUserById({ id: user })
|
||||||
|
|
||||||
|
|
||||||
const fExt = file.name.split(".").pop()
|
const fExt = fileCoba.name.split(".").pop()
|
||||||
const fName = file.name.replace("." + fExt, "")
|
const fName = fileCoba.name.replace("." + fExt, "")
|
||||||
const newFile = new File([file], file.name, { type: file.type });
|
const newFile = new File([fileCoba], fileCoba.name, { type: fileCoba.type });
|
||||||
|
|
||||||
const ini = funViewDir({ dirId: DIR.user })
|
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) {
|
if (upload.success) {
|
||||||
const create = await prisma.bannerImage.create({
|
const create = await prisma.bannerImage.create({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user