🐛 Bug fixes of garfish api
This commit is contained in:
parent
cd12b6ce8d
commit
65ee99c213
@ -12,7 +12,7 @@ export default function NameCard(props: { accountId: string, onError: (messasge:
|
|||||||
|
|
||||||
async function readInfo() {
|
async function readInfo() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await fetch(`/api/users/${props.accountId}`);
|
const res = await request(`/api/users/${props.accountId}`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
props.onError(await res.text());
|
props.onError(await res.text());
|
||||||
} else {
|
} else {
|
||||||
@ -24,7 +24,7 @@ export default function NameCard(props: { accountId: string, onError: (messasge:
|
|||||||
|
|
||||||
async function readIsFollowing() {
|
async function readIsFollowing() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await fetch(`/api/users/${props.accountId}/follow`, {
|
const res = await request(`/api/users/${props.accountId}/follow`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: { Authorization: `Bearer ${getAtk()}` }
|
headers: { Authorization: `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
@ -37,7 +37,7 @@ export default function NameCard(props: { accountId: string, onError: (messasge:
|
|||||||
|
|
||||||
async function follow() {
|
async function follow() {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch(`/api/users/${props.accountId}/follow`, {
|
const res = await request(`/api/users/${props.accountId}/follow`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,7 @@ export default function PostEditActions(props: {
|
|||||||
const [attachmentMode, setAttachmentMode] = createSignal(0);
|
const [attachmentMode, setAttachmentMode] = createSignal(0);
|
||||||
|
|
||||||
async function readCategories() {
|
async function readCategories() {
|
||||||
const res = await fetch("/api/categories");
|
const res = await request("/api/categories");
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
setAvailableCategories(await res.json());
|
setAvailableCategories(await res.json());
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ export default function PostEditActions(props: {
|
|||||||
if (!data.get("attachment")) return;
|
if (!data.get("attachment")) return;
|
||||||
|
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
const res = await fetch("/api/attachments", {
|
const res = await request("/api/attachments", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { Authorization: `Bearer ${getAtk()}` },
|
headers: { Authorization: `Bearer ${getAtk()}` },
|
||||||
body: data,
|
body: data,
|
||||||
|
@ -54,7 +54,7 @@ export default function PostEditor(props: {
|
|||||||
}, [props.editing]);
|
}, [props.editing]);
|
||||||
|
|
||||||
async function listRealm() {
|
async function listRealm() {
|
||||||
const res = await fetch("/api/realms/me/available", {
|
const res = await request("/api/realms/me/available", {
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
@ -72,7 +72,7 @@ export default function PostEditor(props: {
|
|||||||
if (!editor()?.getValue()) return;
|
if (!editor()?.getValue()) return;
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch("/api/posts", {
|
const res = await request("/api/posts", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -107,7 +107,7 @@ export default function PostEditor(props: {
|
|||||||
if (!editor()?.getValue()) return;
|
if (!editor()?.getValue()) return;
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch(`/api/posts/${props.editing?.id}`, {
|
const res = await request(`/api/posts/${props.editing?.id}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -25,7 +25,7 @@ export default function PostItem(props: {
|
|||||||
|
|
||||||
async function reactPost(item: any, type: string) {
|
async function reactPost(item: any, type: string) {
|
||||||
setReacting(true);
|
setReacting(true);
|
||||||
const res = await fetch(`/api/posts/${item.id}/react/${type}`, {
|
const res = await request(`/api/posts/${item.id}/react/${type}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { Authorization: `Bearer ${getAtk()}` },
|
headers: { Authorization: `Bearer ${getAtk()}` },
|
||||||
});
|
});
|
||||||
|
@ -34,7 +34,7 @@ export default function PostList(props: {
|
|||||||
if (!confirm(`Are you sure to delete post#${item.id}?`)) return;
|
if (!confirm(`Are you sure to delete post#${item.id}?`)) return;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await fetch(`/api/posts/${item.id}`, {
|
const res = await request(`/api/posts/${item.id}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
|
@ -48,7 +48,7 @@ export default function PostPublish(props: {
|
|||||||
if (!data.content) return;
|
if (!data.content) return;
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch("/api/posts", {
|
const res = await request("/api/posts", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -85,7 +85,7 @@ export default function PostPublish(props: {
|
|||||||
if (!data.content) return;
|
if (!data.content) return;
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch(`/api/posts/${props.editing?.id}`, {
|
const res = await request(`/api/posts/${props.editing?.id}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -52,6 +52,7 @@ declare const __GARFISH_EXPORTS__: {
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
__GARFISH__: boolean;
|
__GARFISH__: boolean;
|
||||||
|
__LAUNCHPAD_TARGET__?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +72,7 @@ if (!window.__GARFISH__) {
|
|||||||
render(router, root!);
|
render(router, root!);
|
||||||
} else if (typeof __GARFISH_EXPORTS__ !== "undefined") {
|
} else if (typeof __GARFISH_EXPORTS__ !== "undefined") {
|
||||||
console.log("Running in launchpad container!")
|
console.log("Running in launchpad container!")
|
||||||
|
console.log("Launchpad target:", window.__LAUNCHPAD_TARGET__)
|
||||||
if (__GARFISH_EXPORTS__.registerProvider) {
|
if (__GARFISH_EXPORTS__.registerProvider) {
|
||||||
__GARFISH_EXPORTS__.registerProvider(provider);
|
__GARFISH_EXPORTS__.registerProvider(provider);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +23,7 @@ export default function AccountPage() {
|
|||||||
|
|
||||||
async function readPosts(pn?: number) {
|
async function readPosts(pn?: number) {
|
||||||
if (pn) setSearchParams({ page: pn });
|
if (pn) setSearchParams({ page: pn });
|
||||||
const res = await fetch(
|
const res = await request(
|
||||||
"/api/posts?" +
|
"/api/posts?" +
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
take: searchParams["take"] ? searchParams["take"] : (10).toString(),
|
take: searchParams["take"] ? searchParams["take"] : (10).toString(),
|
||||||
|
@ -10,7 +10,7 @@ export default function AuthCallback() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
async function callback() {
|
async function callback() {
|
||||||
const res = await fetch(`/api/auth/callback${location.search}`);
|
const res = await request(`/api/auth/callback${location.search}`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
setError(await res.text());
|
setError(await res.text());
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,7 +5,7 @@ export default function AuthCallout() {
|
|||||||
const [status, setStatus] = createSignal("Communicating with Goatpass...");
|
const [status, setStatus] = createSignal("Communicating with Goatpass...");
|
||||||
|
|
||||||
async function communicate() {
|
async function communicate() {
|
||||||
const res = await fetch(`/api/auth${location.search}`);
|
const res = await request(`/api/auth${location.search}`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
setError(await res.text());
|
setError(await res.text());
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,7 +11,7 @@ export default function PublishPost() {
|
|||||||
const [post, setPost] = createSignal<any>();
|
const [post, setPost] = createSignal<any>();
|
||||||
|
|
||||||
async function readPost() {
|
async function readPost() {
|
||||||
const res = await fetch(`/api/creators/posts/${params["postId"]}`, {
|
const res = await request(`/api/creators/posts/${params["postId"]}`, {
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
|
@ -17,7 +17,7 @@ export default function CreatorHub() {
|
|||||||
async function readPosts(pn?: number) {
|
async function readPosts(pn?: number) {
|
||||||
if (pn) setPage(pn);
|
if (pn) setPage(pn);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await fetch("/api/creators/posts?" + new URLSearchParams({
|
const res = await request("/api/creators/posts?" + new URLSearchParams({
|
||||||
take: (10).toString(),
|
take: (10).toString(),
|
||||||
offset: ((page() - 1) * 10).toString()
|
offset: ((page() - 1) * 10).toString()
|
||||||
}), { headers: { "Authorization": `Bearer ${getAtk()}` } });
|
}), { headers: { "Authorization": `Bearer ${getAtk()}` } });
|
||||||
|
@ -19,7 +19,7 @@ export default function DashboardPage() {
|
|||||||
|
|
||||||
async function readPosts(pn?: number) {
|
async function readPosts(pn?: number) {
|
||||||
if (pn) setSearchParams({ page: pn });
|
if (pn) setSearchParams({ page: pn });
|
||||||
const res = await fetch(
|
const res = await request(
|
||||||
"/api/posts?" +
|
"/api/posts?" +
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
take: searchParams["take"] ? searchParams["take"] : (10).toString(),
|
take: searchParams["take"] ? searchParams["take"] : (10).toString(),
|
||||||
|
@ -21,7 +21,7 @@ export default function PostPage() {
|
|||||||
|
|
||||||
async function readPost(pn?: number) {
|
async function readPost(pn?: number) {
|
||||||
if (pn) setPage(pn);
|
if (pn) setPage(pn);
|
||||||
const res = await fetch(`/api/posts/${params["postId"]}?` + new URLSearchParams({
|
const res = await request(`/api/posts/${params["postId"]}?` + new URLSearchParams({
|
||||||
take: (10).toString(),
|
take: (10).toString(),
|
||||||
offset: ((page() - 1) * 10).toString()
|
offset: ((page() - 1) * 10).toString()
|
||||||
}));
|
}));
|
||||||
@ -43,7 +43,7 @@ export default function PostPage() {
|
|||||||
async function deletePost(item: any) {
|
async function deletePost(item: any) {
|
||||||
if (!confirm(`Are you sure to delete post#${item.id}?`)) return;
|
if (!confirm(`Are you sure to delete post#${item.id}?`)) return;
|
||||||
|
|
||||||
const res = await fetch(`/api/posts/${item.id}`, {
|
const res = await request(`/api/posts/${item.id}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ export default function RealmDirectoryPage() {
|
|||||||
const [realms, setRealms] = createSignal<any>(null);
|
const [realms, setRealms] = createSignal<any>(null);
|
||||||
|
|
||||||
async function readRealms() {
|
async function readRealms() {
|
||||||
const res = await fetch(`/api/realms`);
|
const res = await request(`/api/realms`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
setError(await res.text());
|
setError(await res.text());
|
||||||
} else {
|
} else {
|
||||||
@ -26,7 +26,7 @@ export default function RealmDirectoryPage() {
|
|||||||
const data = Object.fromEntries(new FormData(form));
|
const data = Object.fromEntries(new FormData(form));
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch("/api/realms", {
|
const res = await request("/api/realms", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -23,7 +23,7 @@ export default function RealmPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
async function readRealm() {
|
async function readRealm() {
|
||||||
const res = await fetch(`/api/realms/${params["realmId"]}`);
|
const res = await request(`/api/realms/${params["realmId"]}`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
setError(await res.text());
|
setError(await res.text());
|
||||||
} else {
|
} else {
|
||||||
@ -35,7 +35,7 @@ export default function RealmPage() {
|
|||||||
|
|
||||||
async function readPosts(pn?: number) {
|
async function readPosts(pn?: number) {
|
||||||
if (pn) setPage(pn);
|
if (pn) setPage(pn);
|
||||||
const res = await fetch(`/api/posts?` + new URLSearchParams({
|
const res = await request(`/api/posts?` + new URLSearchParams({
|
||||||
take: (10).toString(),
|
take: (10).toString(),
|
||||||
offset: ((page() - 1) * 10).toString(),
|
offset: ((page() - 1) * 10).toString(),
|
||||||
realmId: params["realmId"]
|
realmId: params["realmId"]
|
||||||
@ -55,7 +55,7 @@ export default function RealmPage() {
|
|||||||
const data = Object.fromEntries(new FormData(form));
|
const data = Object.fromEntries(new FormData(form));
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch(`/api/realms/${params["realmId"]}`, {
|
const res = await request(`/api/realms/${params["realmId"]}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -81,7 +81,7 @@ export default function RealmPage() {
|
|||||||
const data = Object.fromEntries(new FormData(form));
|
const data = Object.fromEntries(new FormData(form));
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch(`/api/realms/${params["realmId"]}/invite`, {
|
const res = await request(`/api/realms/${params["realmId"]}/invite`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
@ -103,7 +103,7 @@ export default function RealmPage() {
|
|||||||
const data = Object.fromEntries(new FormData(form));
|
const data = Object.fromEntries(new FormData(form));
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const res = await fetch(`/api/realms/${params["realmId"]}/kick`, {
|
const res = await request(`/api/realms/${params["realmId"]}/kick`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
headers: { "Authorization": `Bearer ${getAtk()}`, "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
@ -121,7 +121,7 @@ export default function RealmPage() {
|
|||||||
async function breakRealm() {
|
async function breakRealm() {
|
||||||
if (!confirm("Are you sure about that? All posts in this realm will disappear forever.")) return;
|
if (!confirm("Are you sure about that? All posts in this realm will disappear forever.")) return;
|
||||||
|
|
||||||
const res = await fetch(`/api/realms/${params["realmId"]}`, {
|
const res = await request(`/api/realms/${params["realmId"]}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: { "Authorization": `Bearer ${getAtk()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@ export default function SearchPage() {
|
|||||||
|
|
||||||
async function readPosts(pn?: number) {
|
async function readPosts(pn?: number) {
|
||||||
if (pn) setPage(pn);
|
if (pn) setPage(pn);
|
||||||
const res = await fetch("/api/posts?" + new URLSearchParams({
|
const res = await request("/api/posts?" + new URLSearchParams({
|
||||||
take: (10).toString(),
|
take: (10).toString(),
|
||||||
offset: ((page() - 1) * 10).toString(),
|
offset: ((page() - 1) * 10).toString(),
|
||||||
...searchParams
|
...searchParams
|
||||||
|
4
pkg/view/src/scripts/request.ts
Normal file
4
pkg/view/src/scripts/request.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
async function request(input: string, init?: RequestInit) {
|
||||||
|
const prefix = window.__LAUNCHPAD_TARGET__ ?? "";
|
||||||
|
return await fetch(prefix + input, init)
|
||||||
|
}
|
@ -25,7 +25,7 @@ export function getAtk(): string {
|
|||||||
export async function refreshAtk() {
|
export async function refreshAtk() {
|
||||||
const rtk = new Cookie().get("refresh_token");
|
const rtk = new Cookie().get("refresh_token");
|
||||||
|
|
||||||
const res = await fetch("/api/auth/refresh", {
|
const res = await request("/api/auth/refresh", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -48,7 +48,7 @@ function checkLoggedIn(): boolean {
|
|||||||
export async function readProfiles(recovering = true) {
|
export async function readProfiles(recovering = true) {
|
||||||
if (!checkLoggedIn()) return;
|
if (!checkLoggedIn()) return;
|
||||||
|
|
||||||
const res = await fetch("/api/users/me", {
|
const res = await request("/api/users/me", {
|
||||||
headers: {"Authorization": `Bearer ${getAtk()}`}
|
headers: {"Authorization": `Bearer ${getAtk()}`}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ const WellKnownContext = createContext<any>();
|
|||||||
const [wellKnown, setWellKnown] = createStore<any>(null);
|
const [wellKnown, setWellKnown] = createStore<any>(null);
|
||||||
|
|
||||||
export async function readWellKnown() {
|
export async function readWellKnown() {
|
||||||
const res = await fetch("/.well-known")
|
const res = await request("/.well-known")
|
||||||
setWellKnown(await res.json())
|
setWellKnown(await res.json())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user