diff options
author | kartofen <mladenovnasko0@gmail.com> | 2022-08-29 19:01:20 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2022-08-29 19:01:20 +0300 |
commit | 8e4163e3f08e29f38fe87c59d8cfb91e0fa98063 (patch) | |
tree | 2b117f4bafa0a4d10252eef95ca868a247a081a1 /src/lib | |
parent | 9d952483f250a97cbeab4061fa1c4e68341b330f (diff) |
everything works
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/api.ts | 2 | ||||
-rw-r--r-- | src/lib/image.ts | 4 | ||||
-rw-r--r-- | src/lib/thread.ts | 42 |
3 files changed, 30 insertions, 18 deletions
diff --git a/src/lib/api.ts b/src/lib/api.ts index 645fc23..e6ac0f1 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,7 +1,7 @@ const base = 'https://localhost:5001/api' export async function api(method: string, resource: string, data?: any) { - console.log("API USED", method, resource, data); + // console.log("API USED", method, resource, data); return await fetch(`${base}/${method}/${resource}`, { method, headers: { diff --git a/src/lib/image.ts b/src/lib/image.ts index c7d4d49..6ab20a5 100644 --- a/src/lib/image.ts +++ b/src/lib/image.ts @@ -20,8 +20,8 @@ export async function postImg(img: string) { let filename = `${uuidV4()}.${fileExt}`; //save file in this server - writeFileSync(`dist/client/images/${filename}`, img_b64, "base64"); - // writeFileSync(`public/images/${filename}`, img_b64, "base64"); + // writeFileSync(`dist/client/images/${filename}`, img_b64, "base64"); + writeFileSync(`public/images/${filename}`, img_b64, "base64"); let data = { 'name': filename, diff --git a/src/lib/thread.ts b/src/lib/thread.ts index e0f0aa4..2199318 100644 --- a/src/lib/thread.ts +++ b/src/lib/thread.ts @@ -8,8 +8,8 @@ export async function processThreadIn(board: string, thread: Thread, comments = if(!thread || !board) return; let imageId: string = thread.imageId; - if(existsSync(`dist/client/images/${imageId}`)) - // if(existsSync(`public/images/${imageId}`)) + // if(existsSync(`dist/client/images/${imageId}`)) + if(existsSync(`public/images/${imageId}`)) thread.imageId = `/images/${imageId}`; else thread.imageId = await getImg(imageId); @@ -21,8 +21,8 @@ export async function processThreadIn(board: string, thread: Thread, comments = for(let comment of thread.comments) { let cimageId = comment.imageId; - if(existsSync(`dist/client/images/${cimageId}`)) - // if(existsSync(`public/images/${cimageId}`)) + // if(existsSync(`dist/client/images/${cimageId}`)) + if(existsSync(`public/images/${cimageId}`)) comment.imageId = `/images/${cimageId}`; else comment.imageId = await getImg(cimageId); @@ -32,22 +32,34 @@ export async function processThreadIn(board: string, thread: Thread, comments = } export async function processThreadOut(form: any): Thread { - let img = form.get('image').toString(); - - let t: Thread = {}; - t.id = uuidV4(); - t.ThreadName = form.get('ThreadName').toString(); - t.ThreadCreator = uuidV5(form.get('iphash'), uuidNIL); - t.ThreadText = form.get('ThreadText').toString(); - t.Comments = []; - t.CreationDate = Date.now(); - t.ImageId = await postImg(img); - t.FileType = getImgType(img); + let img = form.get('image'); + + let t: Thread = { + id: uuidV4(), + threadName: form.get('ThreadName'), + threadCreator: uuidV5(form.get('iphash'), uuidNIL), + threadText: form.get('ThreadText'), + comments: [], + creationDate: Date.now(), + imageId: await postImg(img), + fileType: getImgType(img), + } return t; } export async function processCommentOut(form: any): Comment { + let img = form.get('image'); + + let c: Comment = {}; + c.id = uuidV4(); + c.commentCreator = uuidV5(form.get('iphash'), uuidNIL); + c.commentText = form.get('CommentText'); + c.creationDate = Date.now(); + c.imageId = await postImg(img); + c.fileType = getImgType(img); + + return c; } function replaceURLs(text: string, board: string, OPtid?: string): string { |