upd: test api
This commit is contained in:
@@ -8,7 +8,7 @@ import { generateNoPengaduan } from "../lib/no-pengaduan"
|
|||||||
import { isValidPhone, normalizePhoneNumber } from "../lib/normalizePhone"
|
import { isValidPhone, normalizePhoneNumber } from "../lib/normalizePhone"
|
||||||
import { prisma } from "../lib/prisma"
|
import { prisma } from "../lib/prisma"
|
||||||
import { renameFile } from "../lib/rename-file"
|
import { renameFile } from "../lib/rename-file"
|
||||||
import { catFile, defaultConfigSF, removeFile, uploadFile, uploadFileBase64 } from "../lib/seafile"
|
import { catFile, defaultConfigSF, removeFile, uploadFile, uploadFileToFolder } from "../lib/seafile"
|
||||||
|
|
||||||
const PengaduanRoute = new Elysia({
|
const PengaduanRoute = new Elysia({
|
||||||
prefix: "pengaduan",
|
prefix: "pengaduan",
|
||||||
@@ -538,7 +538,7 @@ const PengaduanRoute = new Elysia({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
file : JSON.stringify(file),
|
file: JSON.stringify(file),
|
||||||
fileInfo: {
|
fileInfo: {
|
||||||
name: file.name || 'kosong',
|
name: file.name || 'kosong',
|
||||||
size: file.size || 0,
|
size: file.size || 0,
|
||||||
@@ -562,9 +562,10 @@ const PengaduanRoute = new Elysia({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.post("/upload-base64", async ({ body }) => {
|
.post("/upload-base64", async ({ body }) => {
|
||||||
const { data, mimetype } = body;
|
const { data, mimetype, kategori } = body;
|
||||||
const ext = mimeToExtension(mimetype)
|
const ext = mimeToExtension(mimetype)
|
||||||
const name = `${uuidv4()}.${ext}`
|
const name = `${uuidv4()}.${ext}`
|
||||||
|
const kategoriFix = kategori === 'pengaduan' ? 'pengaduan' : 'syarat-dokumen';
|
||||||
|
|
||||||
// Validasi file
|
// Validasi file
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -576,7 +577,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 }, kategoriFix);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -585,12 +587,14 @@ const PengaduanRoute = new Elysia({
|
|||||||
name,
|
name,
|
||||||
mimetype,
|
mimetype,
|
||||||
ext,
|
ext,
|
||||||
|
kategori,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, {
|
}, {
|
||||||
body: t.Object({
|
body: t.Object({
|
||||||
data: t.String(),
|
data: t.String(),
|
||||||
mimetype: t.String()
|
mimetype: t.String(),
|
||||||
|
kategori: t.String()
|
||||||
}),
|
}),
|
||||||
detail: {
|
detail: {
|
||||||
summary: "Upload File (Base64)",
|
summary: "Upload File (Base64)",
|
||||||
|
|||||||
Reference in New Issue
Block a user