From 1721b2291e4f7f8d986aec7edbb682df774338c3 Mon Sep 17 00:00:00 2001 From: thamudi Date: Wed, 27 Nov 2024 17:03:51 +0300 Subject: [PATCH] patch: fix circular dependency issue with ts util files --- server/api/upload-comment.post.ts | 7 ++++--- server/api/upload-file.post.ts | 4 ++-- server/utils/file-parser.ts | 1 + server/utils/index.ts | 12 ------------ 4 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 server/utils/index.ts diff --git a/server/api/upload-comment.post.ts b/server/api/upload-comment.post.ts index 57a66dd..8311e5e 100644 --- a/server/api/upload-comment.post.ts +++ b/server/api/upload-comment.post.ts @@ -1,4 +1,5 @@ -import { predictCommentsResults } from '../utils' +import { predictCommentsResults } from '../utils/nuha-api-request' +import { reject } from '../utils/promise-handlers' export default defineEventHandler(async (event) => { const data = await readBody(event) @@ -33,14 +34,14 @@ async function verifyData(input: SingleComment): Promise { } const emailPattern = new RegExp( - /(?:[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+(?:\.[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?\.)+[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-zA-Z\d-]*[a-zA-Z\d]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/gm, + /(?:[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+(?:\.[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?\.)+[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-zA-Z\d-]*[a-zA-Z\d]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/gm ) if (input.comment.match(emailPattern)) { return reject('apiResponse.commentContainsEmail') } const urlPattern = new RegExp( - /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gm, + /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gm ) if (input.comment.match(urlPattern)) { return reject('apiResponse.commentContainsUrl') diff --git a/server/api/upload-file.post.ts b/server/api/upload-file.post.ts index 2ecd8e9..24bdff2 100644 --- a/server/api/upload-file.post.ts +++ b/server/api/upload-file.post.ts @@ -1,4 +1,4 @@ -import { FileParser, getFileParser, getFileType } from '../utils' +import { FileParser, getFileParser, getFileType } from '../utils/file-parser' export default defineEventHandler(async (event) => { const files = await readMultipartFormData(event) @@ -8,7 +8,7 @@ export default defineEventHandler(async (event) => { } const fileType = getFileType( - files[0].filename?.substring(files[0].filename?.lastIndexOf('.') + 1) ?? '', + files[0].filename?.substring(files[0].filename?.lastIndexOf('.') + 1) ?? '' ) let err: unknown const parser = await getFileParser(fileType).catch((_err) => { diff --git a/server/utils/file-parser.ts b/server/utils/file-parser.ts index 5ee2c86..b9b9d3e 100644 --- a/server/utils/file-parser.ts +++ b/server/utils/file-parser.ts @@ -1,4 +1,5 @@ import { parse } from 'csv-parse/sync' +import { resolve, reject } from './promise-handlers' import xlsx from 'node-xlsx' export interface FileParser { diff --git a/server/utils/index.ts b/server/utils/index.ts deleted file mode 100644 index 6c09f17..0000000 --- a/server/utils/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { resolve, reject } from './promise-handlers' -import { getFileParser, FileType, getFileType } from './file-parser' -import { predictCommentsResults } from './nuha-api-request' - -export { - resolve, - reject, - getFileParser, - FileType, - getFileType, - predictCommentsResults, -}