mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
Only connect to Meili with valid config
This commit is contained in:
parent
66c4e8ed76
commit
b8bd07e3c4
1 changed files with 39 additions and 37 deletions
|
@ -9,55 +9,57 @@ import { Followings, Users } from "@/models/index.js";
|
||||||
|
|
||||||
const logger = dbLogger.createSubLogger("meilisearch", "gray", false);
|
const logger = dbLogger.createSubLogger("meilisearch", "gray", false);
|
||||||
|
|
||||||
logger.info("Connecting to MeiliSearch");
|
|
||||||
|
|
||||||
const hasConfig =
|
const hasConfig =
|
||||||
config.meilisearch &&
|
config.meilisearch &&
|
||||||
(config.meilisearch.host ||
|
(config.meilisearch.host ||
|
||||||
config.meilisearch.port ||
|
config.meilisearch.port ||
|
||||||
config.meilisearch.apiKey);
|
config.meilisearch.apiKey);
|
||||||
|
|
||||||
const host = hasConfig ? config.meilisearch.host ?? "localhost" : "";
|
if (hasConfig) {
|
||||||
const port = hasConfig ? config.meilisearch.port ?? 7700 : 0;
|
const host = hasConfig ? config.meilisearch.host ?? "localhost" : "";
|
||||||
const auth = hasConfig ? config.meilisearch.apiKey ?? "" : "";
|
const port = hasConfig ? config.meilisearch.port ?? 7700 : 0;
|
||||||
const ssl = hasConfig ? config.meilisearch.ssl ?? false : false;
|
const auth = hasConfig ? config.meilisearch.apiKey ?? "" : "";
|
||||||
|
const ssl = hasConfig ? config.meilisearch.ssl ?? false : false;
|
||||||
|
|
||||||
const client: MeiliSearch = new MeiliSearch({
|
logger.info("Connecting to MeiliSearch");
|
||||||
host: `${ssl ? "https" : "http"}://${host}:${port}`,
|
|
||||||
apiKey: auth,
|
|
||||||
});
|
|
||||||
|
|
||||||
const posts = client.index("posts");
|
const client: MeiliSearch = new MeiliSearch({
|
||||||
|
host: `${ssl ? "https" : "http"}://${host}:${port}`,
|
||||||
|
apiKey: auth,
|
||||||
|
});
|
||||||
|
|
||||||
posts
|
const posts = client.index("posts");
|
||||||
.updateSearchableAttributes(["text"])
|
|
||||||
.catch((e) =>
|
|
||||||
logger.error(`Setting searchable attr failed, searches won't work: ${e}`),
|
|
||||||
);
|
|
||||||
|
|
||||||
posts
|
posts
|
||||||
.updateFilterableAttributes([
|
.updateSearchableAttributes(["text"])
|
||||||
"userName",
|
.catch((e) =>
|
||||||
"userHost",
|
logger.error(`Setting searchable attr failed, searches won't work: ${e}`),
|
||||||
"mediaAttachment",
|
);
|
||||||
"createdAt",
|
|
||||||
"userId",
|
|
||||||
])
|
|
||||||
.catch((e) =>
|
|
||||||
logger.error(
|
|
||||||
`Setting filterable attr failed, advanced searches won't work: ${e}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
posts
|
posts
|
||||||
.updateSortableAttributes(["createdAt"])
|
.updateFilterableAttributes([
|
||||||
.catch((e) =>
|
"userName",
|
||||||
logger.error(
|
"userHost",
|
||||||
`Setting sortable attr failed, placeholder searches won't sort properly: ${e}`,
|
"mediaAttachment",
|
||||||
),
|
"createdAt",
|
||||||
);
|
"userId",
|
||||||
|
])
|
||||||
|
.catch((e) =>
|
||||||
|
logger.error(
|
||||||
|
`Setting filterable attr failed, advanced searches won't work: ${e}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
logger.info("Connected to MeiliSearch");
|
posts
|
||||||
|
.updateSortableAttributes(["createdAt"])
|
||||||
|
.catch((e) =>
|
||||||
|
logger.error(
|
||||||
|
`Setting sortable attr failed, placeholder searches won't sort properly: ${e}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.info("Connected to MeiliSearch");
|
||||||
|
}
|
||||||
|
|
||||||
export type MeilisearchNote = {
|
export type MeilisearchNote = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
Loading…
Reference in a new issue