feat(tools): dynamic 5-archetype tool pages, masking editor, alternating features, and studio workflow
This commit is contained in:
@@ -7,13 +7,18 @@ export async function generateMockNeuralResult(
|
||||
toolId: string,
|
||||
variantId?: string
|
||||
): Promise<{ buffer: Buffer; contentType: string }> {
|
||||
// If the uploaded image is valid, we can return it with appropriate media type
|
||||
// In a Node environment, we can either return the original buffer with simulated delay,
|
||||
// or apply lightweight transforms.
|
||||
|
||||
// Simulate 350ms neural inference latency
|
||||
await new Promise((resolve) => setTimeout(resolve, 350));
|
||||
|
||||
// If buffer is a small text seed (e.g. text-to-image), create a valid synthetic image buffer
|
||||
if (imageBuffer.length < 500) {
|
||||
const syntheticPng = createSyntheticArtPng(512, 512, toolId);
|
||||
return {
|
||||
buffer: syntheticPng,
|
||||
contentType: 'image/png',
|
||||
};
|
||||
}
|
||||
|
||||
const isPng = imageBuffer.length > 8 && imageBuffer[0] === 0x89 && imageBuffer[1] === 0x50;
|
||||
const contentType = isPng ? 'image/png' : 'image/jpeg';
|
||||
|
||||
@@ -22,3 +27,63 @@ export async function generateMockNeuralResult(
|
||||
contentType,
|
||||
};
|
||||
}
|
||||
|
||||
function createSyntheticArtPng(width: number, height: number, seedText: string): Buffer {
|
||||
const zlib = require('zlib');
|
||||
const signature = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||||
|
||||
const ihdr = Buffer.alloc(13);
|
||||
ihdr.writeUInt32BE(width, 0);
|
||||
ihdr.writeUInt32BE(height, 4);
|
||||
ihdr.writeUInt8(8, 8);
|
||||
ihdr.writeUInt8(6, 9); // RGBA
|
||||
ihdr.writeUInt8(0, 10);
|
||||
ihdr.writeUInt8(0, 11);
|
||||
ihdr.writeUInt8(0, 12);
|
||||
|
||||
const ihdrChunk = makePngChunk('IHDR', ihdr);
|
||||
|
||||
const rawData = Buffer.alloc((width * 4 + 1) * height);
|
||||
let offset = 0;
|
||||
for (let y = 0; y < height; y++) {
|
||||
rawData[offset++] = 0;
|
||||
for (let x = 0; x < width; x++) {
|
||||
rawData[offset++] = Math.floor((x / width) * 200 + 40);
|
||||
rawData[offset++] = Math.floor((y / height) * 160 + 50);
|
||||
rawData[offset++] = 220;
|
||||
rawData[offset++] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
const compressed = zlib.deflateSync(rawData);
|
||||
const idatChunk = makePngChunk('IDAT', compressed);
|
||||
const iendChunk = makePngChunk('IEND', Buffer.alloc(0));
|
||||
|
||||
return Buffer.concat([signature, ihdrChunk, idatChunk, iendChunk]);
|
||||
}
|
||||
|
||||
function makePngChunk(type: string, data: Buffer): Buffer {
|
||||
const length = Buffer.alloc(4);
|
||||
length.writeUInt32BE(data.length, 0);
|
||||
const typeBuf = Buffer.from(type, 'ascii');
|
||||
const body = Buffer.concat([typeBuf, data]);
|
||||
const crc = Buffer.alloc(4);
|
||||
|
||||
let c = 0xffffffff;
|
||||
for (let n = 0; n < body.length; n++) {
|
||||
c = CRC_TABLE[(c ^ body[n]) & 0xff] ^ (c >>> 8);
|
||||
}
|
||||
crc.writeInt32BE((c ^ 0xffffffff) | 0, 0);
|
||||
|
||||
return Buffer.concat([length, body, crc]);
|
||||
}
|
||||
|
||||
const CRC_TABLE = new Uint32Array(256);
|
||||
for (let n = 0; n < 256; n++) {
|
||||
let c = n;
|
||||
for (let k = 0; k < 8; k++) {
|
||||
if (c & 1) c = 0xedb88320 ^ (c >>> 1);
|
||||
else c = c >>> 1;
|
||||
}
|
||||
CRC_TABLE[n] = c;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,24 @@ export function getAllTools(): ToolItem[] {
|
||||
if (mgmtTool.media?.after && mgmtTool.content?.examples?.[0]) {
|
||||
mgmtTool.content.examples[0].after = mgmtTool.media.after;
|
||||
}
|
||||
toolsCache.set(mgmtTool.slug, mgmtTool);
|
||||
const existing = toolsCache.get(mgmtTool.slug) || ({} as any);
|
||||
const merged: ToolItem = {
|
||||
...existing,
|
||||
...mgmtTool,
|
||||
content: {
|
||||
...(existing.content || {}),
|
||||
...(mgmtTool.content || {}),
|
||||
alternatingFeatures: mgmtTool.content?.alternatingFeatures || existing.content?.alternatingFeatures,
|
||||
},
|
||||
pageType: mgmtTool.pageType || existing.pageType,
|
||||
showThumbnailsSection: mgmtTool.showThumbnailsSection !== undefined ? mgmtTool.showThumbnailsSection : existing.showThumbnailsSection,
|
||||
thumbnailPlacement: mgmtTool.thumbnailPlacement || existing.thumbnailPlacement,
|
||||
thumbnails: mgmtTool.thumbnails || existing.thumbnails,
|
||||
maskingConfig: mgmtTool.maskingConfig || existing.maskingConfig,
|
||||
twoImagesConfig: mgmtTool.twoImagesConfig || existing.twoImagesConfig,
|
||||
textToImageConfig: mgmtTool.textToImageConfig || existing.textToImageConfig,
|
||||
};
|
||||
toolsCache.set(mgmtTool.slug, merged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user