Merge pull request 'Make Meilisearch optional and don't connect if unconfigured' (#10225) from PrivateGER/calckey:fix/meilisearch-optional into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10225
This commit is contained in:
Kainoa Kanter 2023-05-29 18:15:49 +00:00
commit 44e5006563

View file

@ -1,20 +1,24 @@
import { Health, MeiliSearch, Stats } from "meilisearch";
import { Health, Index, MeiliSearch, Stats } from "meilisearch";
import { dbLogger } from "./logger.js";
import config from "@/config/index.js";
import { Note } from "@/models/entities/note.js";
import * as url from "url";
import { ILocalUser, User } from "@/models/entities/user.js";
import { ILocalUser } from "@/models/entities/user.js";
import { Followings, Users } from "@/models/index.js";
const logger = dbLogger.createSubLogger("meilisearch", "gray", false);
let posts: Index;
let client: MeiliSearch;
const hasConfig =
config.meilisearch &&
(config.meilisearch.host ||
config.meilisearch.port ||
config.meilisearch.apiKey);
if (hasConfig) {
const host = hasConfig ? config.meilisearch.host ?? "localhost" : "";
const port = hasConfig ? config.meilisearch.port ?? 7700 : 0;
const auth = hasConfig ? config.meilisearch.apiKey ?? "" : "";
@ -22,12 +26,12 @@ const ssl = hasConfig ? config.meilisearch.ssl ?? false : false;
logger.info("Connecting to MeiliSearch");
const client: MeiliSearch = new MeiliSearch({
client = new MeiliSearch({
host: `${ssl ? "https" : "http"}://${host}:${port}`,
apiKey: auth,
});
const posts = client.index("posts");
posts = client.index("posts");
posts
.updateSearchableAttributes(["text"])
@ -58,6 +62,7 @@ posts
);
logger.info("Connected to MeiliSearch");
}
export type MeilisearchNote = {
id: string;