too many changes

This commit is contained in:
2026-10-09 02:07:18 +04:00
parent 9885e570b9
commit 833286debd
40 changed files with 1854 additions and 260 deletions
+30 -5
View File
@@ -15,6 +15,14 @@ async function request(method, path, body) {
})
if (!res.ok) {
const errCt = res.headers.get('content-type') ?? ''
if (errCt.includes('json')) {
const body = await res.json().catch(() => null)
const err = new Error(body?.detail ?? body?.title ?? `${res.status}`)
err.errorCode = body?.extensions?.errorCode ?? body?.errorCode ?? null
err.status = res.status
throw err
}
const text = await res.text()
throw new Error(`${res.status}: ${text}`)
}
@@ -27,23 +35,40 @@ export const api = {
// ── Auth ──────────────────────────────────────────────────────────────────
auth: (initData) => request('POST', '/auth/telegram', { initData }),
// ── Me ────────────────────────────────────────────────────────────────────
// GET /api/me → { telegramId, username, firstName, inboxCollectionId }
getMe: () => request('GET', '/me'),
// PATCH /api/me { inboxCollectionId } → 204
setInboxCollection: (collectionId) => request('PATCH', '/me', { inboxCollectionId: collectionId }),
// ── Media ─────────────────────────────────────────────────────────────────
getMedia: (q) => request('GET', `/media${q ? `?q=${encodeURIComponent(q)}` : ''}`),
createText: (caption, tags) => request('POST', '/media', { caption, tags }),
getMedia: (q, includeNsfw = false) => {
const params = new URLSearchParams({ includeNsfw })
if (q) params.set('q', q)
return request('GET', `/media?${params}`)
},
getDownloadUrl: (id) => request('GET', `/media/${id}/download-url`).then((r) => r?.url),
sendToChat: (id, queryId) => request('POST', `/media/${id}/send`, { queryId }),
updateMedia: (id, patch) => request('PATCH', `/media/${id}`, patch),
deleteMedia: (id) => request('DELETE', `/media/${id}`),
copyMedia: (id, targetCollectionId) => request('POST', `/media/${id}/copy`, { targetCollectionId }),
// ── Collections ───────────────────────────────────────────────────────────
getCollections: () => request('GET', '/collections'),
createCollection: (name, description) => request('POST', '/collections', { name, description }),
updateCollection: (id, name, description) => request('PATCH', `/collections/${id}`, { name, description }),
// patch: { name, description?, isNsfw?, visibility? } → { shareToken }
updateCollection: (id, patch) => request('PATCH', `/collections/${id}`, patch),
deleteCollection: (id) => request('DELETE', `/collections/${id}`),
setCollectionInbox: (id) => request('PUT', `/collections/${id}/inbox`),
getCollectionItems: (id) => request('GET', `/collections/${id}/items`),
cloneCollection: (id) => request('POST', `/collections/${id}/clone`),
joinCollection: (id) => request('POST', `/collections/${id}/join`),
regenerateShareLink: (id) => request('POST', `/collections/${id}/share-link/regenerate`),
// ── Invites ───────────────────────────────────────────────────────────────
getInvites: (collectionId) => request('GET', `/collections/${collectionId}/invites`),
createInvite: (collectionId, role) => request('POST', `/collections/${collectionId}/invites`, { role }),
revokeInvite: (collectionId, inviteId) => request('DELETE', `/collections/${collectionId}/invites/${inviteId}`),
createInvite: (collectionId, role, expiresAt) =>
request('POST', `/collections/${collectionId}/invites`, { role, expiresAt }),
revokeInvite: (collectionId, inviteId) =>
request('DELETE', `/collections/${collectionId}/invites/${inviteId}`),
}