From 35b06b4fc851192916e000ad5e7e2f458846448c Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 28 Aug 2022 00:08:07 +0300 Subject: working on thread uploading --- package-lock.json | 16 ++++++++++++- package.json | 3 ++- run.sh | 6 ++--- src/components/Comment.svelte | 24 +++++++++---------- src/components/Thread.svelte | 16 ++++++------- src/layouts/Default.astro | 8 +++---- src/lib/thread.ts | 8 +++++-- src/pages/board/[board].astro | 1 - src/pages/create/[board].astro | 54 ++++++++++++++++++++++++++++++++++++++++++ src/pages/create/thread.ts | 28 ++++++++++++++++++++++ 10 files changed, 132 insertions(+), 32 deletions(-) create mode 100644 src/pages/create/[board].astro create mode 100644 src/pages/create/thread.ts diff --git a/package-lock.json b/package-lock.json index 072109d..f8fe288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "dependencies": { "@astrojs/deno": "^1.0.0", "@astrojs/node": "^1.0.0", - "express": "^4.18.1" + "express": "^4.18.1", + "uuid": "^8.3.2" }, "devDependencies": { "@astrojs/svelte": "^1.0.0", @@ -6298,6 +6299,14 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/uvu": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/uvu/-/uvu-0.5.6.tgz", @@ -11045,6 +11054,11 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "uvu": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/uvu/-/uvu-0.5.6.tgz", diff --git a/package.json b/package.json index 932d825..264a7ad 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "@astrojs/deno": "^1.0.0", "@astrojs/node": "^1.0.0", - "express": "^4.18.1" + "express": "^4.18.1", + "uuid": "^8.3.2" } } diff --git a/run.sh b/run.sh index a3c1bf5..dcb7dd5 100755 --- a/run.sh +++ b/run.sh @@ -2,10 +2,10 @@ set -xe -# NODE_TLS_REJECT_UNAUTHORIZED=0 npm run dev +NODE_TLS_REJECT_UNAUTHORIZED=0 npm run dev -npm run build +# npm run build -NODE_TLS_REJECT_UNAUTHORIZED=0 node server.mjs +# NODE_TLS_REJECT_UNAUTHORIZED=0 node server.mjs # deno run --allow-net --allow-read --allow-env --unsafely-ignore-certificate-errors=localhost ./dist/server/entry.mjs diff --git a/src/components/Comment.svelte b/src/components/Comment.svelte index 09469cc..bc53f4d 100644 --- a/src/components/Comment.svelte +++ b/src/components/Comment.svelte @@ -8,24 +8,24 @@
- {comment.id} + {comment.id} at {formatTime(comment.creationDate)}
- -> + -> {comment.commentCreator}
- {#if comment.imageId!= null && comment.imageId != undefined} - {#if comment.fileType == 'image'} - - {comment.imageId}
-
- {:else if comment.fileType == 'video'} - - {/if} + {#if comment.imageId!= null && comment.imageId != undefined} + {#if comment.fileType == 'image'} + + {comment.imageId}
+
+ {:else if comment.fileType == 'video'} + {/if} + {/if}

{@html comment.commentText}

diff --git a/src/components/Thread.svelte b/src/components/Thread.svelte index 8e07c9f..fee1a78 100644 --- a/src/components/Thread.svelte +++ b/src/components/Thread.svelte @@ -21,10 +21,10 @@ {#if thread.id != "rules"}
- {thread.id} + {thread.id} at {formatTime(thread.creationDate)}
- -> + -> {thread.threadCreator}
@@ -33,8 +33,8 @@ {#each replies as id} >>{id}  {/each} -

- {/if} +

+ {/if} @@ -60,15 +60,15 @@ {/if} diff --git a/src/layouts/Default.astro b/src/layouts/Default.astro index 85fd510..5a2a372 100644 --- a/src/layouts/Default.astro +++ b/src/layouts/Default.astro @@ -11,11 +11,11 @@ - + diff --git a/src/lib/thread.ts b/src/lib/thread.ts index d0a4fce..6bc54ce 100644 --- a/src/lib/thread.ts +++ b/src/lib/thread.ts @@ -2,7 +2,7 @@ import { writeFileSync, existsSync } from 'fs'; import { getImg } from './image'; import type Thread from '../models/Thread' -export async function processThreadIn(board: string, thread: Thread, procComments?: false) { +export async function processThreadIn(board: string, thread: Thread, comments? =false) { if(!thread || !board) return; let imageId: string = thread.imageId; @@ -13,7 +13,7 @@ export async function processThreadIn(board: string, thread: Thread, procComment thread.threadText = replaceURLs(thread.threadText, board, thread.id); - if(!procComments) return; + if(!comments) return; for(let comment of thread.comments) { @@ -27,6 +27,10 @@ export async function processThreadIn(board: string, thread: Thread, procComment } } +export async function processThreadOUT(board: string, thread: Thread, comments? = false) { + +} + function replaceURLs(text: string, board: string, OPtid?: string): string { if(!text) return; diff --git a/src/pages/board/[board].astro b/src/pages/board/[board].astro index 2624fed..23a5551 100644 --- a/src/pages/board/[board].astro +++ b/src/pages/board/[board].astro @@ -22,5 +22,4 @@ for(let thread of threads) {threads.map((thread) => ( ))} - diff --git a/src/pages/create/[board].astro b/src/pages/create/[board].astro new file mode 100644 index 0000000..45f8b0d --- /dev/null +++ b/src/pages/create/[board].astro @@ -0,0 +1,54 @@ +--- +import Default from '../../layouts/Default.astro' +const { board } = Astro.params; +--- + +

{board}

+ + +
+
+ +
+ + +
+ +
diff --git a/src/pages/create/thread.ts b/src/pages/create/thread.ts new file mode 100644 index 0000000..0af3471 --- /dev/null +++ b/src/pages/create/thread.ts @@ -0,0 +1,28 @@ +import type { APIRoute } from 'astro'; +import { v4 as uuidV4 } from 'uuid'; + +import type Thread from '../../models/Thread' +import { api } from '../../lib/api' + +export async function post({ params, request }): APIRoute { + const form = await request.formData(); + + let t: Thread = {}; + t.id = uuidV4().toString(); + t.ThreadName = form.get('ThreadName').toString(); + // data["ThreadCreator"] = locals.userid; + t.ThreadCreator = ''; + t.ThreadText = form.get('ThreadText').toString(); + t.Comments = []; + t.CreationDate = Date.now(); + // data["ImageId"] = await post_img(base64image, writeFileSync); + // data["FileType"] = get_img_type(base64image); + t.ImageId = form.get('image').toString(); + t.FileType = ''; + + // await api('post', `thread/${form.get('board')}`, JSON.stringify(data)); + + return new Response(null, { + status: 200 + }); +} -- cgit v1.2.3