mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
* chore: added `rel="noopener noreferrer"` to external links for improved security on homepage * fix: reused variable name * feat: make the item table use a link instead of a click event * fix: pagination now shows correct page if loading page that isnt 1 * fix: make save button sticky again on item edit page * fix: adjust sticky header positioning based on whether legacy header is enabled * fix: navigate to homepage on unauthorized request in useUserApi function * fix: enhance link handling in DetailsSection * fix: improve markdown rendering, don't add big breaks between lines, make the gap smaller and dont have a trailing newline * fix: use secondary colour as switch secondary colour so its more visible against bg * fix: call refresh methods on location and label stores during component mount for better data consistency * fix: loading indicators * fix: convert detail.text to string for correct URL handling in DetailsSection component * fix: use replace instead of splice to remove newline at end of markdown * fix: use css vars for header height
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { PublicApi } from "~~/lib/api/public";
|
|
import { UserClient } from "~~/lib/api/user";
|
|
import { Requests } from "~~/lib/requests";
|
|
|
|
export type Observer = {
|
|
handler: (r: Response, req?: RequestInit) => void;
|
|
};
|
|
|
|
export type RemoveObserver = () => void;
|
|
|
|
const observers: Record<string, Observer> = {};
|
|
|
|
export function defineObserver(key: string, observer: Observer): RemoveObserver {
|
|
observers[key] = observer;
|
|
|
|
return () => {
|
|
delete observers[key];
|
|
};
|
|
}
|
|
|
|
function logger(r: Response) {
|
|
console.log(`${r.status} ${r.url} ${r.statusText}`);
|
|
}
|
|
|
|
export function usePublicApi(): PublicApi {
|
|
const requests = new Requests("", "", {});
|
|
return new PublicApi(requests);
|
|
}
|
|
|
|
export function useUserApi(): UserClient {
|
|
const authCtx = useAuthContext();
|
|
|
|
const requests = new Requests("", "", {});
|
|
requests.addResponseInterceptor(logger);
|
|
requests.addResponseInterceptor(r => {
|
|
if (r.status === 401) {
|
|
console.error("unauthorized request, invalidating session");
|
|
authCtx.invalidateSession();
|
|
navigateTo("/");
|
|
}
|
|
});
|
|
|
|
for (const [_, observer] of Object.entries(observers)) {
|
|
requests.addResponseInterceptor(observer.handler);
|
|
}
|
|
|
|
return new UserClient(requests, authCtx.attachmentToken || "");
|
|
}
|