32 lines
904 B
TypeScript
32 lines
904 B
TypeScript
import { CachedFetch } from "~platform/cache";
|
|
import { cacheBucket, toSmallCamelCase, wrapsError } from "./base";
|
|
import { isAccountKey, type RemoteServer } from "../accounts/stores";
|
|
import { type mastodon } from "masto";
|
|
|
|
export const fetchStatus = /* @__PURE__ */ new CachedFetch(
|
|
cacheBucket,
|
|
(session: RemoteServer, id: string) => {
|
|
const headers = new Headers({
|
|
Accept: "application/json",
|
|
});
|
|
if (isAccountKey(session)) {
|
|
headers.set("Authorization", `Bearer ${session.accessToken}`);
|
|
}
|
|
return {
|
|
url: new URL(`./api/v1/statuses/${id}`, session.site).toString(),
|
|
headers,
|
|
};
|
|
},
|
|
async (response) => {
|
|
try {
|
|
if (!response.ok) {
|
|
throw response;
|
|
}
|
|
return toSmallCamelCase(
|
|
await response.json(),
|
|
) as unknown as mastodon.v1.Status;
|
|
} catch (reason) {
|
|
throw wrapsError(reason);
|
|
}
|
|
},
|
|
);
|