73dd301dbb
Cluster A, milestone #97. Completes the frontend of the structured tag filter
(backend landed in 23fab98).
#6b store: gallery.filter gains tag_or (OR-groups) + tag_exclude; one model,
serialized via tag_or (repeated key) + tag_not across activeFilterParam/
filterToQuery/applyFilterFromQuery/cloneFilter/loadSimilar; _resolveLabels
resolves names for every referenced id. useApi now appends array param values
as a repeated key (tag_or=a&tag_or=b).
#6c light editor (GalleryFilterBar): autocomplete pick → include chip; click a
chip body to flip include↔exclude (exclude = red minus); ✕ removes. An
"N OR-groups" chip + an Advanced button open the builder.
#6d advanced editor (TagQueryBuilder.vue + common/TagPicker.vue): AND-of-OR
group builder + NOT list. Unifies includes+OR-groups into one groups view,
splits back to tag_ids/tag_or on Apply so the URL stays compact. Writes the
same model the light chips edit.
Store serialization round-trip tests added.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XCUHUGQLrBrkgyk1t49kpX
68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
// Thin fetch wrapper. Centralized so every call has consistent error handling
|
|
// and json parsing. Errors throw an ApiError with the response status + body.
|
|
|
|
export class ApiError extends Error {
|
|
constructor(message, status, body) {
|
|
super(message)
|
|
this.name = 'ApiError'
|
|
this.status = status
|
|
this.body = body
|
|
}
|
|
}
|
|
|
|
async function request(method, url, { body, params, signal } = {}) {
|
|
let fullUrl = url
|
|
if (params) {
|
|
const search = new URLSearchParams()
|
|
for (const [k, v] of Object.entries(params)) {
|
|
if (v === undefined || v === null) continue
|
|
// Array values serialize as a REPEATED key (k=a&k=b) — e.g. the
|
|
// gallery's tag_or OR-groups, read server-side via request.args.getlist.
|
|
if (Array.isArray(v)) {
|
|
for (const item of v) {
|
|
if (item !== undefined && item !== null) search.append(k, String(item))
|
|
}
|
|
} else {
|
|
search.set(k, String(v))
|
|
}
|
|
}
|
|
const qs = search.toString()
|
|
if (qs) fullUrl += (url.includes('?') ? '&' : '?') + qs
|
|
}
|
|
|
|
const headers = {}
|
|
const init = { method, headers, signal }
|
|
if (body !== undefined) {
|
|
if (body instanceof FormData) {
|
|
// Let the browser set Content-Type with the multipart boundary.
|
|
// JSON-stringifying FormData produces "{}" and the backend sees
|
|
// an empty multipart payload (this broke FC-5 IR/GS ingest from
|
|
// the UI for several releases).
|
|
init.body = body
|
|
} else {
|
|
headers['Content-Type'] = 'application/json'
|
|
init.body = JSON.stringify(body)
|
|
}
|
|
}
|
|
|
|
const r = await fetch(fullUrl, init)
|
|
const text = await r.text()
|
|
let parsed
|
|
try { parsed = text ? JSON.parse(text) : null } catch { parsed = text }
|
|
|
|
if (!r.ok) {
|
|
const msg = (parsed && parsed.error) || `${r.status} ${r.statusText}`
|
|
throw new ApiError(msg, r.status, parsed)
|
|
}
|
|
return parsed
|
|
}
|
|
|
|
export function useApi() {
|
|
return {
|
|
get: (url, opts) => request('GET', url, opts),
|
|
post: (url, opts) => request('POST', url, opts),
|
|
patch: (url, opts) => request('PATCH', url, opts),
|
|
delete: (url, opts) => request('DELETE', url, opts)
|
|
}
|
|
}
|