core/steps/search.step.ts
core/steps/search.step.ts is a file in Bane's Lab Deploy. 32 lines of code and 4 definitions.
import type { Journal, PingPoster, SearchSitemaps } from "#types/deployment.types";
import { PINGING_SEARCH, PING_SKIPPED, pingAccepted, pingRefused } from "#configuration/strings/deployment.strings";
import { SEARCH_PING_ACCEPTED, SEARCH_PING_ENDPOINT } from "#configuration/constants/deployment.constants";
import { SEARCH_KEY_FILE } from "@banes-lab/build-scripts/configuration/constants/site.constants.ts";
import { changedLocations } from "#core/converters/search.converter";
import { postPing } from "#core/adapters/search.adapter";
const SLASH = "/";
export const pingSearch = async function pingSearch(
journal: Journal,
site: string,
key: string,
sitemaps: SearchSitemaps,
post: PingPoster = postPing,
): Promise<number> {
journal.log(PINGING_SEARCH);
const urlList = changedLocations(sitemaps.before, sitemaps.after);
if (urlList.length === 0) {
journal.mark(PING_SKIPPED);
return 0;
}
const status = await post(SEARCH_PING_ENDPOINT, {
host: new URL(site).host,
key,
keyLocation: site + SLASH + SEARCH_KEY_FILE,
urlList,
});
if (!SEARCH_PING_ACCEPTED.has(status)) {
throw new Error(pingRefused(status));
}
journal.mark(pingAccepted(urlList.length));
return urlList.length;
};