@gallop.software/studio 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2214,74 +2214,105 @@ var FAVICON_CONFIGS = [
2214
2214
  { name: "apple-icon.png", size: 180 }
2215
2215
  ];
2216
2216
  async function handleGenerateFavicon(request) {
2217
+ const encoder = new TextEncoder();
2218
+ let imagePath;
2217
2219
  try {
2218
2220
  const body = await request.json();
2219
- const { imagePath } = body;
2221
+ imagePath = body.imagePath;
2220
2222
  if (!imagePath) {
2221
2223
  return _server.NextResponse.json({ error: "No image path provided" }, { status: 400 });
2222
2224
  }
2223
- const fileName = _path2.default.basename(imagePath).toLowerCase();
2224
- if (fileName !== "favicon.png" && fileName !== "favicon.jpg") {
2225
- return _server.NextResponse.json({
2226
- error: "Source file must be named favicon.png or favicon.jpg"
2227
- }, { status: 400 });
2228
- }
2229
- const sourcePath = _path2.default.join(process.cwd(), "public", imagePath.replace(/^\//, ""));
2230
- try {
2231
- await _promises2.default.access(sourcePath);
2232
- } catch (e45) {
2233
- return _server.NextResponse.json({ error: "Source file not found" }, { status: 404 });
2234
- }
2235
- let metadata;
2236
- try {
2237
- metadata = await _sharp2.default.call(void 0, sourcePath).metadata();
2238
- } catch (e46) {
2239
- return _server.NextResponse.json({ error: "Source file is not a valid image" }, { status: 400 });
2240
- }
2241
- const outputDir = _path2.default.join(process.cwd(), "src", "app");
2242
- try {
2243
- await _promises2.default.access(outputDir);
2244
- } catch (e47) {
2245
- return _server.NextResponse.json({
2246
- error: "Output directory src/app/ not found"
2247
- }, { status: 500 });
2248
- }
2249
- const results = [];
2250
- for (const config of FAVICON_CONFIGS) {
2225
+ } catch (e45) {
2226
+ return _server.NextResponse.json({ error: "Invalid request body" }, { status: 400 });
2227
+ }
2228
+ const fileName = _path2.default.basename(imagePath).toLowerCase();
2229
+ if (fileName !== "favicon.png" && fileName !== "favicon.jpg") {
2230
+ return _server.NextResponse.json({
2231
+ error: "Source file must be named favicon.png or favicon.jpg"
2232
+ }, { status: 400 });
2233
+ }
2234
+ const sourcePath = _path2.default.join(process.cwd(), "public", imagePath.replace(/^\//, ""));
2235
+ try {
2236
+ await _promises2.default.access(sourcePath);
2237
+ } catch (e46) {
2238
+ return _server.NextResponse.json({ error: "Source file not found" }, { status: 404 });
2239
+ }
2240
+ let metadata;
2241
+ try {
2242
+ metadata = await _sharp2.default.call(void 0, sourcePath).metadata();
2243
+ } catch (e47) {
2244
+ return _server.NextResponse.json({ error: "Source file is not a valid image" }, { status: 400 });
2245
+ }
2246
+ const outputDir = _path2.default.join(process.cwd(), "src", "app");
2247
+ try {
2248
+ await _promises2.default.access(outputDir);
2249
+ } catch (e48) {
2250
+ return _server.NextResponse.json({
2251
+ error: "Output directory src/app/ not found"
2252
+ }, { status: 500 });
2253
+ }
2254
+ const stream = new ReadableStream({
2255
+ async start(controller) {
2256
+ const sendEvent = (data) => {
2257
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
2258
+
2259
+ `));
2260
+ };
2251
2261
  try {
2252
- const outputPath = _path2.default.join(outputDir, config.name);
2253
- await _sharp2.default.call(void 0, sourcePath).resize(config.size, config.size, {
2254
- fit: "cover",
2255
- position: "center"
2256
- }).png({ quality: 100 }).toFile(outputPath);
2257
- results.push({
2258
- name: config.name,
2259
- size: config.size,
2260
- success: true
2262
+ const total = FAVICON_CONFIGS.length;
2263
+ const generated = [];
2264
+ const errors = [];
2265
+ sendEvent({
2266
+ type: "start",
2267
+ total,
2268
+ sourceSize: `${metadata.width}x${metadata.height}`
2261
2269
  });
2262
- } catch (error) {
2263
- results.push({
2264
- name: config.name,
2265
- size: config.size,
2266
- success: false,
2267
- error: error instanceof Error ? error.message : "Unknown error"
2270
+ for (let i = 0; i < FAVICON_CONFIGS.length; i++) {
2271
+ const config = FAVICON_CONFIGS[i];
2272
+ sendEvent({
2273
+ type: "progress",
2274
+ current: i + 1,
2275
+ total,
2276
+ percent: Math.round((i + 1) / total * 100),
2277
+ message: `Generating ${config.name} (${config.size}x${config.size})...`
2278
+ });
2279
+ try {
2280
+ const outputPath = _path2.default.join(outputDir, config.name);
2281
+ await _sharp2.default.call(void 0, sourcePath).resize(config.size, config.size, {
2282
+ fit: "cover",
2283
+ position: "center"
2284
+ }).png({ quality: 100 }).toFile(outputPath);
2285
+ generated.push(config.name);
2286
+ } catch (error) {
2287
+ console.error(`Failed to generate ${config.name}:`, error);
2288
+ errors.push(config.name);
2289
+ }
2290
+ }
2291
+ let message = `Generated ${generated.length} favicon${generated.length !== 1 ? "s" : ""} to src/app/.`;
2292
+ if (errors.length > 0) {
2293
+ message += ` ${errors.length} failed.`;
2294
+ }
2295
+ sendEvent({
2296
+ type: "complete",
2297
+ processed: generated.length,
2298
+ errors: errors.length,
2299
+ message
2268
2300
  });
2301
+ controller.close();
2302
+ } catch (error) {
2303
+ console.error("Favicon generation error:", error);
2304
+ sendEvent({ type: "error", message: "Failed to generate favicons" });
2305
+ controller.close();
2269
2306
  }
2270
2307
  }
2271
- const successCount = results.filter((r) => r.success).length;
2272
- const failCount = results.filter((r) => !r.success).length;
2273
- return _server.NextResponse.json({
2274
- success: failCount === 0,
2275
- message: `Generated ${successCount} favicon${successCount !== 1 ? "s" : ""}${failCount > 0 ? `, ${failCount} failed` : ""}.`,
2276
- sourceSize: `${metadata.width}x${metadata.height}`,
2277
- results
2278
- });
2279
- } catch (error) {
2280
- console.error("Favicon generation error:", error);
2281
- return _server.NextResponse.json({
2282
- error: "Failed to generate favicons"
2283
- }, { status: 500 });
2284
- }
2308
+ });
2309
+ return new Response(stream, {
2310
+ headers: {
2311
+ "Content-Type": "text/event-stream",
2312
+ "Cache-Control": "no-cache",
2313
+ Connection: "keep-alive"
2314
+ }
2315
+ });
2285
2316
  }
2286
2317
 
2287
2318
  // src/handlers/index.ts