Merge pull request #223 from bipproduction/amalia/12-september-24

Amalia/12 september 24
This commit is contained in:
Amalia
2024-09-12 13:36:00 +08:00
committed by GitHub
45 changed files with 169 additions and 213 deletions

View File

@@ -91,7 +91,8 @@ export async function GET(request: Request, context: { params: { id: string } })
select: {
id: true,
name: true,
extension: true
extension: true,
idStorage: true
}
})

View File

@@ -1,4 +1,4 @@
import { prisma } from "@/module/_global";
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { NextResponse } from "next/server";
import fs from "fs";
@@ -36,8 +36,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
}
})
fs.unlink(`./public/file/project/${dataRelasi?.id}.${dataRelasi?.extension}`, (err) => { })
const delStorage = await funDeleteFile({ fileId: String(dataRelasi?.idStorage) })
const deleteRelasi = await prisma.projectFile.delete({
where: {
@@ -166,31 +165,27 @@ export async function POST(request: Request, context: { params: { id: string } }
if (cekFile) {
const root = path.join(process.cwd(), "./public/file/project/");
for (var pair of body.entries()) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
const upload = await funUploadFile({ file: file, dirId: DIR.project })
if (upload.success) {
const insertToTable = await prisma.projectFile.create({
data: {
idStorage: upload.data.id,
idProject: id,
name: fName,
extension: String(fExt),
const insertToTable = await prisma.projectFile.create({
data: {
idProject: id,
name: fName,
extension: String(fExt)
},
select: {
id: true
}
})
const nameFix = insertToTable.id + '.' + fExt
const filePath = path.join(root, nameFix)
// Konversi ArrayBuffer ke Buffer
const buffer = Buffer.from(await file.arrayBuffer());
// Tulis file ke sistem
fs.writeFileSync(filePath, buffer);
},
select: {
id: true
}
})
}
}
}
}

View File

@@ -1,4 +1,4 @@
import { prisma } from "@/module/_global";
import { DIR, funUploadFile, prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import _ from "lodash";
import moment from "moment";
@@ -169,31 +169,22 @@ export async function POST(request: Request) {
}
if (cekFile) {
const root = path.join(process.cwd(), "./public/file/project/");
for (var pair of body.entries()) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = file.name.replace("." + fExt, "")
const insertToTable = await prisma.projectFile.create({
data: {
idProject: data.id,
name: fName,
extension: String(fExt)
},
select: {
id: true
}
})
const nameFix = insertToTable.id + '.' + fExt
const filePath = path.join(root, nameFix)
// Konversi ArrayBuffer ke Buffer
const buffer = Buffer.from(await file.arrayBuffer());
// Tulis file ke sistem
fs.writeFileSync(filePath, buffer);
const upload = await funUploadFile({ file: file, dirId: DIR.project })
if (upload.success) {
await prisma.projectFile.create({
data: {
idStorage: upload.data.id,
idProject: data.id,
name: fName,
extension: String(fExt)
}
})
}
}
}
}

View File

@@ -1,7 +1,7 @@
import { prisma } from "@/module/_global";
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import _ from "lodash";
import _, { update } from "lodash";
import { NextResponse } from "next/server";
import path from "path";
import fs from "fs";
@@ -203,22 +203,17 @@ export async function PUT(request: Request, context: { params: { id: string } })
});
if (String(file) != "undefined" && String(file) != "null") {
fs.unlink(`./public/image/user/${updates.img}`, (err) => { })
const root = path.join(process.cwd(), "./public/image/user/");
const fExt = file.name.split(".").pop()
const fileName = id + '.' + fExt;
const filePath = path.join(root, fileName);
// Konversi ArrayBuffer ke Buffer
const buffer = Buffer.from(await file.arrayBuffer());
fs.writeFileSync(filePath, buffer);
const newFile = new File([file], fileName, { type: file.type });
await funDeleteFile({ fileId: String(updates.img) })
const upload = await funUploadFile({ file: newFile, dirId: DIR.user })
await prisma.user.update({
where: {
id: id
},
data: {
img: fileName
img: upload.data.id
}
})
}

View File

@@ -1,4 +1,4 @@
import { funDeleteFile, funUploadFile, prisma } from "@/module/_global";
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import _ from "lodash";
import { NextResponse } from "next/server";
@@ -119,34 +119,21 @@ export async function PUT(request: Request) {
if (String(file) != "undefined" && String(file) != "null") {
const fExt = file.name.split(".").pop()
// const fileName = user.id + '.' + fExt;
const fileName = 'COBAAYAA.' + fExt;
const fileName = user.id + '.' + fExt;
const newFile = new File([file], fileName, { type: file.type });
console.log(fileName, newFile.name)
await funDeleteFile({ name: fileName, dirId: "cm0x8dbwn0005bp5tgmfcthzw" })
await funUploadFile({ file: newFile, dirId: "cm0x8dbwn0005bp5tgmfcthzw" })
await funDeleteFile({ fileId: String(update.img) })
const upload = await funUploadFile({ file: newFile, dirId: DIR.user })
if (upload.success) {
await prisma.user.update({
where: {
id: user.id
},
data: {
img: upload.data.id
}
})
}
// fs.unlink(`./public/image/user/${update.img}`, (err) => { })
// const root = path.join(process.cwd(), "./public/image/user/");
// const fExt = file.name.split(".").pop()
// const fileName = user.id + '.' + fExt;
// const filePath = path.join(root, fileName);
// // Konversi ArrayBuffer ke Buffer
// const buffer = Buffer.from(await file.arrayBuffer());
// // Tulis file ke sistem
// fs.writeFileSync(filePath, buffer);
// await prisma.user.update({
// where: {
// id: user.id
// },
// data: {
// img: fileName
// }
// })
}
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data profile', table: 'user', data: user.id })

View File

@@ -1,4 +1,4 @@
import { funUploadFile, prisma } from "@/module/_global";
import { DIR, funUploadFile, prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import _ from "lodash";
@@ -141,27 +141,17 @@ export async function POST(request: Request) {
const fExt = file.name.split(".").pop()
const fileName = user.id + '.' + fExt;
const newFile = new File([file], fileName, { type: file.type });
await funUploadFile({ file: newFile, dirId: "cm0x8dbwn0005bp5tgmfcthzw" })
// const root = path.join(process.cwd(), "./public/image/user/");
// const fExt = file.name.split(".").pop()
// const fileName = users.id + '.' + fExt;
// const filePath = path.join(root, fileName);
// // Konversi ArrayBuffer ke Buffer
// const buffer = Buffer.from(await file.arrayBuffer());
// // Tulis file ke sistem
// fs.writeFileSync(filePath, buffer);
// await prisma.user.update({
// where: {
// id: users.id
// },
// data: {
// img: fileName
// }
// })
const upload = await funUploadFile({ file: newFile, dirId: DIR.user })
if (upload.success) {
await prisma.user.update({
where: {
id: users.id
},
data: {
img: upload.data.id
}
})
}
}
// create log user