commit 6700402830ee3f6378c973ab912a66ddad3278d9
parent 9125e3e9313219e2130a68e46a0612164da0d3c2
Author: MTRNord <mtrnord1@gmail.com>
Date: Thu, 20 Jun 2024 11:53:33 +0200
Allow changing the settings of meili via the config
Diffstat:
4 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
@@ -19,7 +19,7 @@ pnpm run build
## Usage
-To start the index you first have to fill the confix.yaml.
+To start the index you first have to fill the config.yaml.
Have a look at the config.example.yaml for an example.
When you are done you can start the bot using:
diff --git a/config.example.yaml b/config.example.yaml
@@ -1,2 +1,5 @@
homeserverUrl: "https://matrix.midnightthoughts.space"
-accessToken: ""
-\ No newline at end of file
+accessToken: ""
+meilisearch:
+ host: "http://localhost:7700"
+ masterKey: "masterKey"
+\ No newline at end of file
diff --git a/src/config.ts b/src/config.ts
@@ -7,6 +7,10 @@ import YAML from 'yaml';
const ConfigSchema = Type.Object({
homeserverUrl: Type.String(),
accessToken: Type.String(),
+ meilisearch: Type.Object({
+ host: Type.String(),
+ masterKey: Type.String()
+ })
});
export type ConfigSchema = Static<typeof ConfigSchema>;
@@ -56,6 +60,24 @@ export default class Config {
this.save();
}
+ public get meiliSearchHost(): string {
+ return this.config.meilisearch.host;
+ }
+
+ public set meiliSearchHost(value: string) {
+ this.config.meilisearch.host = value;
+ this.save();
+ }
+
+ public get meiliSearchKey(): string {
+ return this.config.meilisearch.masterKey;
+ }
+
+ public set meiliSearchKey(value: string) {
+ this.config.meilisearch.masterKey = value;
+ this.save();
+ }
+
public save() {
fs.writeFileSync('config.yaml', YAML.stringify(this.config));
}
diff --git a/src/indexer.ts b/src/indexer.ts
@@ -1,4 +1,7 @@
import { Hits, MeiliSearch } from 'meilisearch';
+import Config from './config.js';
+
+const config = new Config();
/* This is the indexer. It is a wrapper around orama.
*
@@ -9,8 +12,8 @@ import { Hits, MeiliSearch } from 'meilisearch';
*/
export default class Indexer {
private readonly client = new MeiliSearch({
- host: 'http://localhost:7700',
- apiKey: 'aSampleMasterKey'
+ host: config.meiliSearchHost,
+ apiKey: config.meiliSearchKey
});
private readonly textIndex = this.client.index('text');