Adds API docs annotations & generator (#927)
* initial commit * fixes category api route * fixes follow api routes --------- Co-authored-by: Christian Beutel <>
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { User } from "$lib/models/user";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { users_search } from "$lib/stores/user_store";
|
||||
import { getFileURL } from "$lib/util/file_util";
|
||||
import Search, { type SearchItem } from "./base/search.svelte";
|
||||
import { _ } from "svelte-i18n";
|
||||
|
||||
interface Props {
|
||||
label?: string;
|
||||
value?: string;
|
||||
includeSelf?: boolean;
|
||||
clearAfterSelect?: boolean;
|
||||
onclear?: () => void
|
||||
onclick?: (item: SearchItem) => void
|
||||
}
|
||||
|
||||
let {
|
||||
label = "",
|
||||
value = $bindable(""),
|
||||
includeSelf = true,
|
||||
clearAfterSelect = true,
|
||||
onclear,
|
||||
onclick
|
||||
}: Props = $props();
|
||||
|
||||
let searchItems: SearchItem[] = $state([]);
|
||||
|
||||
async function updateUsers(q: string) {
|
||||
if (!q.length) {
|
||||
searchItems = [];
|
||||
onclear?.();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const users: User[] = await users_search(q, includeSelf);
|
||||
searchItems = users.map((u) => ({
|
||||
text: u.username!,
|
||||
value: u,
|
||||
icon: "user",
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
show_toast({
|
||||
type: "error",
|
||||
icon: "close",
|
||||
text: "Error during search",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onClick(item: SearchItem) {
|
||||
value = item.value.username ?? value;
|
||||
|
||||
onclick?.(item);
|
||||
searchItems = [];
|
||||
}
|
||||
</script>
|
||||
|
||||
<Search
|
||||
onupdate={(q) => updateUsers(q)}
|
||||
onclick={(item) => onClick(item)}
|
||||
placeholder={`${$_("username")}...`}
|
||||
items={searchItems}
|
||||
{clearAfterSelect}
|
||||
{label}
|
||||
bind:value
|
||||
>
|
||||
{#snippet prepend({ item })}
|
||||
<img
|
||||
|
||||
|
||||
class="rounded-full w-8 aspect-square mr-2"
|
||||
src={getFileURL(item.value, item.value.avatar) ||
|
||||
`https://api.dicebear.com/7.x/initials/svg?seed=${item.value.username}&backgroundType=gradientLinear`}
|
||||
alt="avatar"
|
||||
/>
|
||||
{/snippet}
|
||||
</Search>
|
||||
1224
web/src/lib/models/api/openapi_schemas.ts
Normal file
1224
web/src/lib/models/api/openapi_schemas.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -23,37 +23,6 @@ export async function users_create(user: User) {
|
||||
return createdUser;
|
||||
}
|
||||
|
||||
export async function users_search(q: string, includeSelf: boolean = true) {
|
||||
const user = get(currentUser)
|
||||
|
||||
let r = await fetch('/api/v1/user/anonymous?' + new URLSearchParams({
|
||||
"filter": `username~"${q}"${includeSelf ? '' : `&&id!="${user?.id}"`}`,
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
if (!r.ok) {
|
||||
const response = await r.json();
|
||||
throw new APIError(r.status, response.message, response.detail)
|
||||
}
|
||||
|
||||
const response = await r.json()
|
||||
return response.items;
|
||||
|
||||
}
|
||||
|
||||
export async function users_show(id: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
let r = await f(`/api/v1/user/anonymous/${id}`, {
|
||||
method: 'GET',
|
||||
})
|
||||
if (!r.ok) {
|
||||
const response = await r.json();
|
||||
throw new APIError(r.status, response.message, response.detail)
|
||||
}
|
||||
const response: UserAnonymous = await r.json()
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function users_auth_methods(f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch): Promise<AuthMethodsList> {
|
||||
const r = await f('/api/v1/auth/oauth', {
|
||||
method: 'GET',
|
||||
|
||||
Reference in New Issue
Block a user