From ca5be0042dddb13c193fad172abc4b678d7fd2a7 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:06:01 +0700 Subject: [PATCH] feat: tools to do some automate prepare --- Services/server/tools/prepare.ts | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Services/server/tools/prepare.ts diff --git a/Services/server/tools/prepare.ts b/Services/server/tools/prepare.ts new file mode 100644 index 0000000..d1394ef --- /dev/null +++ b/Services/server/tools/prepare.ts @@ -0,0 +1,44 @@ +import "dotenv/config"; +import esClient from "../src/elasticsearch"; +import minioClient from "../src/minio"; + +const DEFAULT_BUCKET = process.env.MINIO_BUCKET; +const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX; + +if (!DEFAULT_BUCKET) throw Error("Default MinIO bucket must be specified."); +if (!DEFAULT_INDEX) throw Error("Default ElasticSearch index must be specified."); + +esClient.ingest.putPipeline({ + id: "attachment", + body: { + description: "Extract attachment information", + processors: [ + { + attachment: { + field: "data", + }, + }, + { + remove: { + field: "data", + }, + }, + ], + }, +}); + +esClient.indices.putMapping({ + index: DEFAULT_INDEX, + body: { + properties: { + pathname: { + type: "keyword", + }, + }, + }, +}); + +minioClient.makeBucket(DEFAULT_BUCKET!, (e) => { + if (!e) console.log("Configuration needed for Bucket Notification to AMQP"); + console.error(e); +});