mirror of
https://github.com/Sevichecc/raycast-akkoma-extension.git
synced 2025-04-30 14:49:29 +08:00
refactor: api types
This commit is contained in:
parent
fbfea648fe
commit
d64e191e5e
1 changed files with 6 additions and 7 deletions
13
src/api.ts
13
src/api.ts
|
@ -1,6 +1,6 @@
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { OAuth, getPreferenceValues } from "@raycast/api";
|
import { OAuth, getPreferenceValues } from "@raycast/api";
|
||||||
import { AppResponse, Preference, Status } from "./types";
|
import { Credentials, Preference, Status ,StatusResponse} from "./types";
|
||||||
import { authorize } from "./oauth";
|
import { authorize } from "./oauth";
|
||||||
|
|
||||||
export const fetchToken = async (params: URLSearchParams, errorMessage: string): Promise<OAuth.TokenResponse> => {
|
export const fetchToken = async (params: URLSearchParams, errorMessage: string): Promise<OAuth.TokenResponse> => {
|
||||||
|
@ -19,7 +19,7 @@ export const fetchToken = async (params: URLSearchParams, errorMessage: string):
|
||||||
return (await response.json()) as OAuth.TokenResponse;
|
return (await response.json()) as OAuth.TokenResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createApp = async (): Promise<AppResponse> => {
|
export const createApp = async (): Promise<Credentials> => {
|
||||||
const { instance } = getPreferenceValues<Preference>();
|
const { instance } = getPreferenceValues<Preference>();
|
||||||
|
|
||||||
const response = await fetch(`https://${instance}/api/v1/apps`, {
|
const response = await fetch(`https://${instance}/api/v1/apps`, {
|
||||||
|
@ -39,16 +39,16 @@ export const createApp = async (): Promise<AppResponse> => {
|
||||||
throw new Error("Failed to create Akkoma app");
|
throw new Error("Failed to create Akkoma app");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (await response.json()) as AppResponse;
|
return (await response.json()) as Credentials;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const postNewStatus = async <T>({
|
export const postNewStatus = async ({
|
||||||
status,
|
status,
|
||||||
visibility,
|
visibility,
|
||||||
spoiler_text,
|
spoiler_text,
|
||||||
sensitive,
|
sensitive,
|
||||||
scheduled_at,
|
scheduled_at,
|
||||||
}: Status): Promise<T> => {
|
}: Partial<Status>) : Promise<StatusResponse> => {
|
||||||
const { instance } = getPreferenceValues<Preference>();
|
const { instance } = getPreferenceValues<Preference>();
|
||||||
const token = await authorize();
|
const token = await authorize();
|
||||||
|
|
||||||
|
@ -66,10 +66,9 @@ export const postNewStatus = async <T>({
|
||||||
scheduled_at,
|
scheduled_at,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to pulish new status");
|
throw new Error("Failed to pulish new status");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (await response.json()) as T;
|
return (await response.json()) as StatusResponse;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue