Add bbox coordinates to object_pictures for chip highlight feature
- Add bbox_x/y/w/h FLOAT columns to object_pictures (0–1 percentage range)
- Include type ('word'|'object') and bbox in feed placeholder response
- Fix picture query to use DISTINCT ON instead of LIMIT 1
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -94,7 +94,9 @@ router.get('/', requireJwt, async (req, res, next) => {
|
||||
`SELECT id, titel_de AS de, titel_en AS en, titel_sv AS sv FROM words WHERE id = ANY($1)`,
|
||||
[uuidArr]
|
||||
);
|
||||
wordRes.rows.forEach(w => { placeholderMap[w.id] = { de: w.de, en: w.en, sv: w.sv }; });
|
||||
wordRes.rows.forEach(w => {
|
||||
placeholderMap[w.id] = { de: w.de, en: w.en, sv: w.sv, type: 'word', bbox: null };
|
||||
});
|
||||
|
||||
// Object lookup → get first linked word as label
|
||||
const objUuids = uuidArr.filter(u => !placeholderMap[u]);
|
||||
@@ -109,7 +111,10 @@ router.get('/', requireJwt, async (req, res, next) => {
|
||||
// First word per object
|
||||
const seen = new Set();
|
||||
objRes.rows.forEach(r => {
|
||||
if (!seen.has(r.id)) { placeholderMap[r.id] = { de: r.de, en: r.en, sv: r.sv }; seen.add(r.id); }
|
||||
if (!seen.has(r.id)) {
|
||||
placeholderMap[r.id] = { de: r.de, en: r.en, sv: r.sv, type: 'object', bbox: null };
|
||||
seen.add(r.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -156,14 +161,24 @@ router.get('/', requireJwt, async (req, res, next) => {
|
||||
const pictureMap = {}; // objectId → { url, blurhash }
|
||||
if (resolvedObjectIds.size) {
|
||||
const picRes = await query(
|
||||
`SELECT op.object_id, p.picture_link AS url, p.blurhash
|
||||
`SELECT DISTINCT ON (op.object_id)
|
||||
op.object_id, p.picture_link AS url, p.blurhash,
|
||||
op.bbox_x, op.bbox_y, op.bbox_w, op.bbox_h
|
||||
FROM object_pictures op
|
||||
JOIN pictures p ON p.id = op.picture_id
|
||||
WHERE op.object_id = ANY($1)
|
||||
LIMIT 1`,
|
||||
ORDER BY op.object_id, p.created_at`,
|
||||
[[...resolvedObjectIds]]
|
||||
);
|
||||
picRes.rows.forEach(r => { pictureMap[r.object_id] = { url: r.url, blurhash: r.blurhash }; });
|
||||
picRes.rows.forEach(r => {
|
||||
pictureMap[r.object_id] = { url: r.url, blurhash: r.blurhash };
|
||||
// Attach bbox to placeholder if all four values are present
|
||||
if (placeholderMap[r.object_id] && r.bbox_x != null) {
|
||||
placeholderMap[r.object_id].bbox = {
|
||||
x: r.bbox_x, y: r.bbox_y, w: r.bbox_w, h: r.bbox_h,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Pick first available picture across all placeholders in the pair
|
||||
|
||||
Reference in New Issue
Block a user