Add tabbed sub-views to bins section, create-bin-from-source flow
Bins section now mirrors the grids section with two tabs: - Bins: gallery of processed bin records - Sources: source images tagged with uses=['bin'], with upload and '+ Bin' button to create a bin record from an existing source image Server: POST /api/bins/from-source accepts source_id, creates bin record and adds 'bin' to the source image's uses array. URL state: /bins → bins tab, /bins/sources → sources tab. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
34
server.mjs
34
server.mjs
@@ -662,6 +662,40 @@ app.get('/api/bins/:id', (req, res) => {
|
||||
ok(res, { bin });
|
||||
});
|
||||
|
||||
// Create a bin from an already-uploaded source image
|
||||
app.post('/api/bins/from-source', (req, res) => {
|
||||
const { source_id, name = '' } = req.body;
|
||||
if (!source_id) return fail(res, 'source_id is required');
|
||||
const src = get_source_image(source_id);
|
||||
if (!src) return fail(res, 'source image not found', 404);
|
||||
|
||||
// Add 'bin' to uses if not already there
|
||||
if (!src.uses?.includes('bin')) {
|
||||
add_source_image({ ...src, uses: [...(src.uses ?? []), 'bin'] });
|
||||
}
|
||||
|
||||
const mx = Math.round(src.width * 0.15);
|
||||
const my = Math.round(src.height * 0.15);
|
||||
const bin = {
|
||||
id: generate_id(),
|
||||
name: name.trim() || src.original_name?.replace(/\.[^.]+$/, '') || 'Bin',
|
||||
source_id,
|
||||
source_w: src.width,
|
||||
source_h: src.height,
|
||||
corners: [
|
||||
{ x: mx, y: my },
|
||||
{ x: src.width - mx, y: my },
|
||||
{ x: src.width - mx, y: src.height - my },
|
||||
{ x: mx, y: src.height - my },
|
||||
],
|
||||
image_filename: null,
|
||||
created_at: Date.now(),
|
||||
updated_at: Date.now(),
|
||||
};
|
||||
set_bin(bin);
|
||||
ok(res, { bin });
|
||||
});
|
||||
|
||||
// Upload a source image for a bin and create the bin record (no processing yet)
|
||||
app.post('/api/bins', upload.single('image'), async (req, res) => {
|
||||
if (!req.file) return fail(res, 'no image uploaded');
|
||||
|
||||
Reference in New Issue
Block a user