Removed shared folder
This commit is contained in:
parent
acc9be8bad
commit
0d33354b7f
|
@ -1,70 +0,0 @@
|
|||
import { contextCache } from "src/utils/payload";
|
||||
|
||||
const getUnlocalizedPathname = (pathname: string): string => {
|
||||
for (const locale of contextCache.locales) {
|
||||
if (pathname.startsWith(`/${locale}`)) {
|
||||
return pathname.substring(`/${locale}`.length) || "/";
|
||||
}
|
||||
}
|
||||
return pathname;
|
||||
};
|
||||
|
||||
type TrackRequestParams = {
|
||||
params: Record<string, string | undefined>;
|
||||
locals: App.Locals;
|
||||
clientAddress: string;
|
||||
};
|
||||
|
||||
export const trackRequest = (request: Request, { clientAddress, locals }: TrackRequestParams) => {
|
||||
const userAgent = request.headers.get("User-Agent");
|
||||
const acceptLanguage = request.headers.get("Accept-Language");
|
||||
const { method, url: stringUrl, referrer } = request;
|
||||
const url = new URL(stringUrl);
|
||||
|
||||
const body: AnalyticsBody = {
|
||||
type: "request",
|
||||
timestamp: Date.now(),
|
||||
payload: {
|
||||
user: {
|
||||
address: clientAddress,
|
||||
attributes: {
|
||||
locale: locals.currentLocale,
|
||||
},
|
||||
},
|
||||
request: {
|
||||
method,
|
||||
pathname: getUnlocalizedPathname(url.pathname),
|
||||
referrer,
|
||||
...(acceptLanguage ? { acceptLanguage } : {}),
|
||||
...(userAgent ? { userAgent } : {}),
|
||||
},
|
||||
response: {
|
||||
status: locals.notFound ? 404 : 200,
|
||||
},
|
||||
},
|
||||
};
|
||||
track(body);
|
||||
};
|
||||
|
||||
export const trackEvent = (eventName: string) => {
|
||||
const body: AnalyticsBody = { type: "event", timestamp: Date.now(), eventName };
|
||||
track(body);
|
||||
};
|
||||
|
||||
type AnalyticsBody = Record<string, unknown> & {
|
||||
type: "event" | "request";
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
const track = async (body: AnalyticsBody) => {
|
||||
if (!import.meta.env.ANALYTICS_URL) return;
|
||||
try {
|
||||
await fetch(import.meta.env.ANALYTICS_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("Couldn't send analytics", e);
|
||||
}
|
||||
};
|
|
@ -1,118 +0,0 @@
|
|||
import {
|
||||
Collections,
|
||||
type EndpointAudio,
|
||||
type EndpointChronologyEvent,
|
||||
type EndpointCollectible,
|
||||
type EndpointFile,
|
||||
type EndpointFolder,
|
||||
type EndpointImage,
|
||||
type EndpointPage,
|
||||
type EndpointRecorder,
|
||||
type EndpointVideo,
|
||||
} from "src/shared/payload/payload-sdk";
|
||||
|
||||
export enum Indexes {
|
||||
DOCUMENT = "DOCUMENT",
|
||||
}
|
||||
|
||||
export type MeiliDocument = {
|
||||
meilid: string;
|
||||
id: string;
|
||||
languages: string[];
|
||||
title?: string;
|
||||
content?: string;
|
||||
} & (
|
||||
| {
|
||||
type: Collections.Collectibles;
|
||||
data: EndpointCollectible;
|
||||
}
|
||||
| {
|
||||
type: Collections.Pages;
|
||||
data: EndpointPage;
|
||||
}
|
||||
| {
|
||||
type: Collections.Folders;
|
||||
data: EndpointFolder;
|
||||
}
|
||||
| {
|
||||
type: Collections.Videos;
|
||||
data: EndpointVideo;
|
||||
}
|
||||
| {
|
||||
type: Collections.Audios;
|
||||
data: EndpointAudio;
|
||||
}
|
||||
| {
|
||||
type: Collections.Images;
|
||||
data: EndpointImage;
|
||||
}
|
||||
| {
|
||||
type: Collections.Files;
|
||||
data: EndpointFile;
|
||||
}
|
||||
| {
|
||||
type: Collections.Recorders;
|
||||
data: EndpointRecorder;
|
||||
}
|
||||
| {
|
||||
type: Collections.ChronologyEvents;
|
||||
data: {
|
||||
date: EndpointChronologyEvent["date"];
|
||||
event: EndpointChronologyEvent["events"][number];
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
export type SearchResponse<T> = {
|
||||
hits: T[];
|
||||
query: string;
|
||||
processingTimeMs: number;
|
||||
hitsPerPage: number;
|
||||
page: number;
|
||||
totalPages: number;
|
||||
totalHits: number;
|
||||
facetDistribution: Record<"type" | "languages", Record<string, number>>;
|
||||
};
|
||||
|
||||
export type SearchRequest = {
|
||||
q: string;
|
||||
page: number;
|
||||
types?: string[] | string | undefined;
|
||||
};
|
||||
|
||||
export class Meilisearch {
|
||||
constructor(
|
||||
private readonly apiURL: string,
|
||||
private readonly bearer: string
|
||||
) {}
|
||||
|
||||
async search({ q, page, types }: SearchRequest): Promise<SearchResponse<MeiliDocument>> {
|
||||
const filter: string[] = [];
|
||||
|
||||
if (types) {
|
||||
if (typeof types === "string") {
|
||||
filter.push(`type = ${types}`);
|
||||
} else {
|
||||
filter.push(`type IN [${types.join(", ")}]`);
|
||||
}
|
||||
}
|
||||
|
||||
const body = {
|
||||
q,
|
||||
page,
|
||||
hitsPerPage: 25,
|
||||
filter,
|
||||
sort: ["updatedAt:desc"]
|
||||
};
|
||||
|
||||
const result = await fetch(`${this.apiURL}/indexes/DOCUMENT/search`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${this.bearer}`,
|
||||
},
|
||||
});
|
||||
return await result.json();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
|||
import currencies from "src/shared/openExchange/currencies.json";
|
||||
import { rates } from "src/shared/openExchange/rates.json";
|
||||
import currencies from "src/dist/openExchange/currencies.json";
|
||||
import { rates } from "src/dist/openExchange/rates.json";
|
||||
|
||||
type CurrencyCode = keyof typeof rates;
|
||||
|
||||
|
|
Loading…
Reference in New Issue