feat(project) cleanup, removed dependencies, updated structure

This commit is contained in:
Benjamin Wegener
2023-12-08 02:05:23 +00:00
parent 8aeea132a5
commit 07fa57f178
18 changed files with 853 additions and 173 deletions

5
src/Utils/Logger.js Normal file
View File

@@ -0,0 +1,5 @@
export class Logger {
static info() {
const [message, data] = arguments;
}
}

View File

@@ -0,0 +1,46 @@
export async function parseFormData(req, multipart = false) {
const data = await req.formData();
// console.log(tempFile, new Response(tempFile).headers.get('Content-Type'));
// console.log(upload.type, upload.type == tempFile.type);
for (const key of data.keys()) {
const value = data.get(key);
if (value.constructor.name == 'Blob' && multipart) {
// const ext = value.name.toString().split('.').pop().toLowerCase();
const tempFilePath = `/tmp/${Date.now().toString(36)}`;
await Bun.write(tempFilePath, value);
let tempFile = Bun.file(tempFilePath, { type: value.type });
console.log(
tempFile,
new Response(tempFile).headers.get('Content-Type')
);
console.log(value.type, value.type == tempFile.type);
// data.set(key, await Bun.write())
}
}
return data;
}
export default async function RequestParser(req) {
try {
const contentType = req.headers.get('Content-Type')?.toLowerCase();
let val = await req.text();
console.log(val);
return {};
if (!contentType) return await req.text();
if (contentType.startsWith('multipart/form-data'))
return await parseFormData(req, true);
if (contentType == 'application/x-www-form-urlencoded')
return await parseFormData(req);
if (contentType == 'application/json') return await req.json();
return await req.text();
} catch (err) {
console.log(err, typeof req, req.constructor.name);
}
}