upd: api create pengaduan dg image #21
@@ -100,8 +100,8 @@ const PengaduanRoute = new Elysia({
|
|||||||
|
|
||||||
// --- PENGADUAN ---
|
// --- PENGADUAN ---
|
||||||
.post("/create", async ({ body }) => {
|
.post("/create", async ({ body }) => {
|
||||||
const { title, detail, location, imageData, imageMime, idCategory, idWarga, phone } = body
|
const { title, detail, location, imageName, idCategory, idWarga, phone } = body
|
||||||
let imageFix = null
|
let imageFix = imageName
|
||||||
const noPengaduan = await generateNoPengaduan()
|
const noPengaduan = await generateNoPengaduan()
|
||||||
let idCategoryFix = idCategory
|
let idCategoryFix = idCategory
|
||||||
let idWargaFix = idWarga
|
let idWargaFix = idWarga
|
||||||
@@ -111,11 +111,11 @@ const PengaduanRoute = new Elysia({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!imageData && !imageMime) {
|
// if (!imageData && !imageMime) {
|
||||||
const ext = mimeToExtension(imageMime)
|
// const ext = mimeToExtension(imageMime)
|
||||||
imageFix = `${uuidv4()}.${ext}`
|
// imageFix = `${uuidv4()}.${ext}`
|
||||||
await uploadFileToFolder(defaultConfigSF, { name: imageFix, data: imageData }, "pengaduan")
|
// await uploadFileToFolder(defaultConfigSF, { name: imageFix, data: imageData }, "pengaduan")
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!category) {
|
if (!category) {
|
||||||
const cariCategory = await prisma.categoryPengaduan.findFirst({
|
const cariCategory = await prisma.categoryPengaduan.findFirst({
|
||||||
@@ -195,8 +195,7 @@ const PengaduanRoute = new Elysia({
|
|||||||
title: t.String({ minLength: 1, error: "title harus diisi" }),
|
title: t.String({ minLength: 1, error: "title harus diisi" }),
|
||||||
detail: t.String({ minLength: 1, error: "detail harus diisi" }),
|
detail: t.String({ minLength: 1, error: "detail harus diisi" }),
|
||||||
location: t.String({ minLength: 1, error: "location harus diisi" }),
|
location: t.String({ minLength: 1, error: "location harus diisi" }),
|
||||||
imageData: t.String({ optional: true, description: "base64 encoded image data" }),
|
imageName: t.String({ optional: true, description: "nama file gambar yg telah diupload" }),
|
||||||
imageMime: t.String({ optional: true, description: "mime type of image" }),
|
|
||||||
idCategory: t.String({ minLength: 1, error: "idCategory harus diisi" }),
|
idCategory: t.String({ minLength: 1, error: "idCategory harus diisi" }),
|
||||||
idWarga: t.String({ minLength: 1, error: "idWarga harus diisi" }),
|
idWarga: t.String({ minLength: 1, error: "idWarga harus diisi" }),
|
||||||
phone: t.String({ minLength: 1, error: "phone harus diisi" }),
|
phone: t.String({ minLength: 1, error: "phone harus diisi" }),
|
||||||
@@ -458,7 +457,7 @@ const PengaduanRoute = new Elysia({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.post("/upload-base64", async ({ body }) => {
|
.post("/upload-base64", async ({ body }) => {
|
||||||
const { data, mimetype } = body;
|
const { data, mimetype, folder } = body;
|
||||||
const ext = mimeToExtension(mimetype)
|
const ext = mimeToExtension(mimetype)
|
||||||
const name = `${uuidv4()}.${ext}`
|
const name = `${uuidv4()}.${ext}`
|
||||||
|
|
||||||
@@ -472,7 +471,8 @@ const PengaduanRoute = new Elysia({
|
|||||||
// const base64String = Buffer.from(buffer).toString("base64");
|
// const base64String = Buffer.from(buffer).toString("base64");
|
||||||
|
|
||||||
// (Opsional) jika perlu dikirim ke Seafile sebagai base64
|
// (Opsional) jika perlu dikirim ke Seafile sebagai base64
|
||||||
const result = await uploadFileBase64(defaultConfigSF, { name: name, data: data });
|
// const result = await uploadFileBase64(defaultConfigSF, { name: name, data: data });
|
||||||
|
const result = await uploadFileToFolder(defaultConfigSF, { name: name, data: data }, folder);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -486,7 +486,11 @@ const PengaduanRoute = new Elysia({
|
|||||||
}, {
|
}, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
data: t.String(),
|
data: t.String(),
|
||||||
mimetype: t.String()
|
mimetype: t.String(),
|
||||||
|
folder: t.Enum({
|
||||||
|
pengaduan: "pengaduan",
|
||||||
|
syarat_dokumen: "syarat-dokumen",
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
detail: {
|
detail: {
|
||||||
summary: "Upload File (Base64)",
|
summary: "Upload File (Base64)",
|
||||||
|
|||||||
Reference in New Issue
Block a user