Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

944 B
Raw Blame
import { API_URL, apiFailure } from '@/lib/api/core/client';

// Uploads an avatar image to the API (stored in the S3 object store). The API writes the new URL
// to the user's image column itself and returns it, so the caller only has to read
// the session again. Multipart, so the browser sets the boundary itself — no
// Content-Type header.
export async function uploadAvatar(file: File): Promise<{ image: string }> {
  const form = new FormData();
  form.append('file', file);
  const res = await fetch(`${API_URL}/me/avatar`, {
    method: 'POST',
    credentials: 'include',
    body: form,
  });
  if (!res.ok) throw await apiFailure(res);
  return res.json();
}

// Removes the stored avatar object and clears the user's image column.
export async function removeAvatar(): Promise<void> {
  const res = await fetch(`${API_URL}/me/avatar`, { method: 'DELETE', credentials: 'include' });
  if (!res.ok) throw await apiFailure(res);
}