tutu/src/masto/statuses.ts

31 lines
764 B
TypeScript
Raw Normal View History

import { CachedFetch } from "~platform/cache";
import { cacheBucket, toSmallCamelCase } 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) => {
return toSmallCamelCase(
await response.json(),
) as unknown as mastodon.v1.Status;
},
);