From 9d952483f250a97cbeab4061fa1c4e68341b330f Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 28 Aug 2022 23:22:15 +0300 Subject: posting thread and image works --- src/lib/thread.ts | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/lib/thread.ts') diff --git a/src/lib/thread.ts b/src/lib/thread.ts index 6bc54ce..e0f0aa4 100644 --- a/src/lib/thread.ts +++ b/src/lib/thread.ts @@ -1,12 +1,15 @@ -import { writeFileSync, existsSync } from 'fs'; -import { getImg } from './image'; -import type Thread from '../models/Thread' +import { existsSync } from 'fs'; +import { v4 as uuidV4, v5 as uuidV5, NIL as uuidNIL } from 'uuid'; -export async function processThreadIn(board: string, thread: Thread, comments? =false) { +import { getImg, postImg, getImgType } from './image'; +import type { Thread, Comment } from '../models/Thread' + +export async function processThreadIn(board: string, thread: Thread, comments = false) { if(!thread || !board) return; let imageId: string = thread.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); @@ -18,7 +21,8 @@ export async function processThreadIn(board: string, thread: Thread, comments? = for(let comment of thread.comments) { let cimageId = comment.imageId; - 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); @@ -27,8 +31,23 @@ export async function processThreadIn(board: string, thread: Thread, comments? = } } -export async function processThreadOUT(board: string, thread: Thread, comments? = false) { +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); + + return t; +} +export async function processCommentOut(form: any): Comment { } function replaceURLs(text: string, board: string, OPtid?: string): string { -- cgit v1.2.3