feat(editor): Bild-Block skip wenn recipe.id === null
This commit is contained in:
@@ -134,14 +134,20 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="editor">
|
<div class="editor">
|
||||||
<section class="block">
|
{#if recipe.id !== null}
|
||||||
<h2>Bild</h2>
|
<section class="block">
|
||||||
<ImageUploadBox
|
<h2>Bild</h2>
|
||||||
recipeId={recipe.id!}
|
<ImageUploadBox
|
||||||
imagePath={recipe.image_path}
|
recipeId={recipe.id}
|
||||||
onchange={(p) => onimagechange?.(p)}
|
imagePath={recipe.image_path}
|
||||||
/>
|
onchange={(p) => onimagechange?.(p)}
|
||||||
</section>
|
/>
|
||||||
|
</section>
|
||||||
|
{:else}
|
||||||
|
<section class="block info">
|
||||||
|
<p class="hint">Bild kannst du nach dem Speichern hinzufügen.</p>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
<label class="field">
|
<label class="field">
|
||||||
@@ -271,6 +277,15 @@
|
|||||||
margin: 0 0 0.75rem;
|
margin: 0 0 0.75rem;
|
||||||
color: #2b6a3d;
|
color: #2b6a3d;
|
||||||
}
|
}
|
||||||
|
.block.info {
|
||||||
|
background: #f6faf7;
|
||||||
|
border: 1px dashed #cfd9d1;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
color: #666;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
.ing-list {
|
.ing-list {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe('POST /api/recipes/extract-from-photo', () => {
|
|||||||
it('happy path: 200 with recipe shape', async () => {
|
it('happy path: 200 with recipe shape', async () => {
|
||||||
mockExtract.mockResolvedValueOnce(validAiResponse);
|
mockExtract.mockResolvedValueOnce(validAiResponse);
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('photo', new Blob([await makeJpeg()], { type: 'image/jpeg' }), 'x.jpg');
|
fd.append('photo', new Blob([new Uint8Array(await makeJpeg())], { type: 'image/jpeg' }), 'x.jpg');
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const res = await POST(mkEvent(fd) as any);
|
const res = await POST(mkEvent(fd) as any);
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -73,7 +73,7 @@ describe('POST /api/recipes/extract-from-photo', () => {
|
|||||||
it('413 when file exceeds 8 MB', async () => {
|
it('413 when file exceeds 8 MB', async () => {
|
||||||
const big = Buffer.alloc(9 * 1024 * 1024);
|
const big = Buffer.alloc(9 * 1024 * 1024);
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('photo', new Blob([big], { type: 'image/jpeg' }));
|
fd.append('photo', new Blob([new Uint8Array(big)], { type: 'image/jpeg' }));
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const res = await POST(mkEvent(fd, '1.1.1.1') as any);
|
const res = await POST(mkEvent(fd, '1.1.1.1') as any);
|
||||||
expect(res.status).toBe(413);
|
expect(res.status).toBe(413);
|
||||||
@@ -82,7 +82,7 @@ describe('POST /api/recipes/extract-from-photo', () => {
|
|||||||
|
|
||||||
it('415 when content-type not in whitelist', async () => {
|
it('415 when content-type not in whitelist', async () => {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('photo', new Blob([Buffer.from('hi')], { type: 'text/plain' }));
|
fd.append('photo', new Blob([new Uint8Array(Buffer.from('hi'))], { type: 'text/plain' }));
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const res = await POST(mkEvent(fd, '2.2.2.2') as any);
|
const res = await POST(mkEvent(fd, '2.2.2.2') as any);
|
||||||
expect(res.status).toBe(415);
|
expect(res.status).toBe(415);
|
||||||
@@ -103,7 +103,7 @@ describe('POST /api/recipes/extract-from-photo', () => {
|
|||||||
steps: []
|
steps: []
|
||||||
});
|
});
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('photo', new Blob([await makeJpeg()], { type: 'image/jpeg' }));
|
fd.append('photo', new Blob([new Uint8Array(await makeJpeg())], { type: 'image/jpeg' }));
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const res = await POST(mkEvent(fd, '4.4.4.4') as any);
|
const res = await POST(mkEvent(fd, '4.4.4.4') as any);
|
||||||
expect(res.status).toBe(422);
|
expect(res.status).toBe(422);
|
||||||
@@ -115,7 +115,7 @@ describe('POST /api/recipes/extract-from-photo', () => {
|
|||||||
new GeminiError('AI_NOT_CONFIGURED', 'no key')
|
new GeminiError('AI_NOT_CONFIGURED', 'no key')
|
||||||
);
|
);
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('photo', new Blob([await makeJpeg()], { type: 'image/jpeg' }));
|
fd.append('photo', new Blob([new Uint8Array(await makeJpeg())], { type: 'image/jpeg' }));
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const res = await POST(mkEvent(fd, '5.5.5.5') as any);
|
const res = await POST(mkEvent(fd, '5.5.5.5') as any);
|
||||||
expect(res.status).toBe(503);
|
expect(res.status).toBe(503);
|
||||||
@@ -127,12 +127,12 @@ describe('POST /api/recipes/extract-from-photo', () => {
|
|||||||
const ip = '9.9.9.9';
|
const ip = '9.9.9.9';
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('photo', new Blob([await makeJpeg()], { type: 'image/jpeg' }));
|
fd.append('photo', new Blob([new Uint8Array(await makeJpeg())], { type: 'image/jpeg' }));
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
await POST(mkEvent(fd, ip) as any);
|
await POST(mkEvent(fd, ip) as any);
|
||||||
}
|
}
|
||||||
const last = new FormData();
|
const last = new FormData();
|
||||||
last.append('photo', new Blob([await makeJpeg()], { type: 'image/jpeg' }));
|
last.append('photo', new Blob([new Uint8Array(await makeJpeg())], { type: 'image/jpeg' }));
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const res = await POST(mkEvent(last, ip) as any);
|
const res = await POST(mkEvent(last, ip) as any);
|
||||||
expect(res.status).toBe(429);
|
expect(res.status).toBe(429);
|
||||||
|
|||||||
Reference in New Issue
Block a user