From 4ce8f7ebff967265ac88098c7d48218771af40ad Mon Sep 17 00:00:00 2001 From: Christophe Bach Date: Mon, 8 May 2023 11:36:44 +0200 Subject: [PATCH 1/4] fix search results --- server/src/routes/posts.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/routes/posts.ts b/server/src/routes/posts.ts index 95546a2..c0b6025 100644 --- a/server/src/routes/posts.ts +++ b/server/src/routes/posts.ts @@ -13,6 +13,7 @@ import { UnauthorizedError } from "../errors/UnauthorizedError.js"; import { MarkdownConverterServer } from "../markdown-converter-server.js"; import { authMiddleware } from "../service/middleware/auth.js"; import { extractJsonBody, extractUploadFiles, multipleFilesUpload } from "../service/middleware/files-upload.js"; +import { In } from "typeorm"; const router: Router = express.Router(); @@ -35,7 +36,7 @@ router.get("/page/:page([0-9]+)/count/:count([0-9]+)/search/:search/operator/:op // TODO : add createdBy and tags to search results await AppDataSource.manager .createQueryBuilder(PostEntity, "post") - .select(["post.*", "ts_rank_cd(sp.post_tsv, to_tsquery(:searchTerm)) as rank", "count(*) over() as count"]) + .select(["post.id as post_id", "ts_rank_cd(sp.post_tsv, to_tsquery(:searchTerm)) as rank", "count(*) over() as count"]) .setParameter("searchTerm", searchTerm) .leftJoin("search_posts", "sp", "sp.post_id = id") .where("sp.post_tsv @@ to_tsquery(:searchTerm)", { searchTerm: searchTerm }) @@ -43,9 +44,14 @@ router.get("/page/:page([0-9]+)/count/:count([0-9]+)/search/:search/operator/:op .offset(skipEntries) .limit(itemsPerPage) .getRawMany() - .then((result) => { - const count = result?.map((r) => r.count) as number[]; - return res.status(200).json({ data: [result, count[0]] }); + .then(async (result) => { + const idArray = result?.map((r) => parseInt(r.post_id)) as number[]; + const count = result?.map((r) => parseInt(r.count)) as number[]; + + await AppDataSource.manager + .getRepository(PostEntity) + .findBy({ id: In(idArray) }) + .then((result) => res.status(200).json({ data: [result, count[0]] })); }) .catch((err) => next(err)); }); From 5a3b6183be4754353059d61c402fb93093c824b5 Mon Sep 17 00:00:00 2001 From: Christophe Bach Date: Mon, 8 May 2023 16:30:23 +0200 Subject: [PATCH 2/4] fix tags in edit mode --- server/src/routes/posts.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/routes/posts.ts b/server/src/routes/posts.ts index c0b6025..e603b52 100644 --- a/server/src/routes/posts.ts +++ b/server/src/routes/posts.ts @@ -255,10 +255,10 @@ router.post("/:id(\\d+$)", authMiddleware, multipleFilesUpload, async (req: Requ } else if (!permissionsForUser(account.user).canEditPost && (account.user.id === null || account.user.id !== post.createdBy?.id)) { return next(new ForbiddenError()); } - /* - const tagsToUseInPost: TagEntity[] = await getPersistedTagsForPost(body).catch((err) => { + + const tagsToUseInPost: TagEntity[] = await getPersistedTagsForPost(post, body).catch((err) => { throw new InternalServerError(true, "Error getting tags" + err); - });*/ + }); AppDataSource.manager .transaction(async (manager) => { @@ -288,7 +288,7 @@ router.post("/:id(\\d+$)", authMiddleware, multipleFilesUpload, async (req: Requ .getRepository(PostEntity) .findOneByOrFail({ id: postId }) .then((post) => { - post.tags = []; + post.tags = tagsToUseInPost; return post; }) .then((updatedPost) => manager.getRepository(PostEntity).save(updatedPost)) From 30474543974cd87917c19c04235f1edf6b684e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= Date: Tue, 9 May 2023 13:48:43 +0200 Subject: [PATCH 3/4] Update version number --- client/package.json | 2 +- common/package.json | 2 +- package.json | 2 +- portal/package.json | 2 +- server/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/package.json b/client/package.json index cba7c7f..cf7fdfc 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@fumix/fu-blog-client", - "version": "0.1.0", + "version": "0.2.1", "scripts": { "start": "vite --port 5010", "build": "run-p type-check build-only", diff --git a/common/package.json b/common/package.json index 9c966bc..aba944f 100644 --- a/common/package.json +++ b/common/package.json @@ -1,6 +1,6 @@ { "name": "@fumix/fu-blog-common", - "version": "0.1.0", + "version": "0.2.1", "author": "fumiX GmbH & Co KG", "license": "Apache-2.0", "scripts": { diff --git a/package.json b/package.json index 7bdfa53..41bc66b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "npm": ">=8.0.0 <10.0.0" }, "name": "@fumix/fu-blog", - "version": "0.1.0", + "version": "0.2.1", "workspaces": [ "common", "client", diff --git a/portal/package.json b/portal/package.json index 7289072..49eaae4 100644 --- a/portal/package.json +++ b/portal/package.json @@ -1,6 +1,6 @@ { "name": "@fumix/fu-blog-portal", - "version": "0.1.0", + "version": "0.2.1", "private": true, "main": "index.js", "type": "module", diff --git a/server/package.json b/server/package.json index a91741b..2672f0d 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@fumix/fu-blog-server", - "version": "0.1.0", + "version": "0.2.1", "description": "Backend Server for Blog in Node/Express", "main": "server.js", "scripts": { From ddeef801bd696de4e3398548a6ed2b393fd1ac21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= Date: Tue, 9 May 2023 14:16:15 +0200 Subject: [PATCH 4/4] Fix 0 byte sharepic --- server/src/routes/utility.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/routes/utility.ts b/server/src/routes/utility.ts index d320991..27e8d4b 100644 --- a/server/src/routes/utility.ts +++ b/server/src/routes/utility.ts @@ -14,7 +14,7 @@ const router: Router = express.Router(); let cachedSharepic: { url: string; bytes: Uint8Array } | undefined = undefined; router.get("/github-sharepic", async (req, res) => { - const timestamp = Math.floor(Date.now() / 3600000); + const timestamp = Math.floor(Date.now() / 3600000); // round down to the hour const url = `https://opengraph.githubassets.com/${timestamp}/${AppSettings.GITHUB_REPOSITORY_SLUG}`; if (cachedSharepic && cachedSharepic.url === url) { if (req.header("If-None-Match") === `${timestamp}`) { @@ -30,7 +30,7 @@ router.get("/github-sharepic", async (req, res) => { } } else { const sendCachedBytesOrNotFound = () => { - if (cachedSharepic) { + if (cachedSharepic && cachedSharepic.bytes.length > 0) { res .status(200) .header("ETag", `${timestamp}`)