tutu/src/masto/statuses.ts

33 lines
904 B
TypeScript
Raw Normal View History

import { CachedFetch } from "~platform/cache";
2025-01-01 21:08:26 +08:00
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) => {
2025-01-01 21:08:26 +08:00
try {
if (!response.ok) {
throw response;
}
return toSmallCamelCase(
await response.json(),
) as unknown as mastodon.v1.Status;
} catch (reason) {
throw wrapsError(reason);
}
},
);