@gallop.software/studio 1.4.6 → 1.5.0

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.
@@ -1450,7 +1450,6 @@ async function handleUnprocessStream(request) {
1450
1450
  percent: Math.round((i + 1) / total * 100),
1451
1451
  message: `Removing thumbnails for ${imageKey.slice(1)}...`
1452
1452
  });
1453
- await new Promise((resolve) => setTimeout(resolve, 1e3));
1454
1453
  try {
1455
1454
  const entry = getMetaEntry(meta, imageKey);
1456
1455
  if (!entry) {
@@ -2086,8 +2085,8 @@ async function handleDeleteOrphans(request) {
2086
2085
  function parseImageUrl(url) {
2087
2086
  const parsed = new URL(url);
2088
2087
  const base = `${parsed.protocol}//${parsed.host}`;
2089
- const path9 = parsed.pathname;
2090
- return { base, path: path9 };
2088
+ const path10 = parsed.pathname;
2089
+ return { base, path: path10 };
2091
2090
  }
2092
2091
  async function processRemoteImage(url) {
2093
2092
  const response = await fetch(url);
@@ -2136,20 +2135,20 @@ async function handleImportUrls(request) {
2136
2135
  currentFile: url
2137
2136
  });
2138
2137
  try {
2139
- const { base, path: path9 } = parseImageUrl(url);
2140
- const existingEntry = getMetaEntry(meta, path9);
2138
+ const { base, path: path10 } = parseImageUrl(url);
2139
+ const existingEntry = getMetaEntry(meta, path10);
2141
2140
  if (existingEntry) {
2142
- skipped.push(path9);
2141
+ skipped.push(path10);
2143
2142
  continue;
2144
2143
  }
2145
2144
  const cdnIndex = getOrAddCdnIndex(meta, base);
2146
2145
  const imageData = await processRemoteImage(url);
2147
- setMetaEntry(meta, path9, {
2146
+ setMetaEntry(meta, path10, {
2148
2147
  o: imageData.o,
2149
2148
  b: imageData.b,
2150
2149
  c: cdnIndex
2151
2150
  });
2152
- added.push(path9);
2151
+ added.push(path10);
2153
2152
  } catch (error) {
2154
2153
  console.error(`Failed to import ${url}:`, error);
2155
2154
  errors.push(url);
@@ -2204,6 +2203,87 @@ async function handleUpdateCdns(request) {
2204
2203
  }
2205
2204
  }
2206
2205
 
2206
+ // src/handlers/favicon.ts
2207
+
2208
+
2209
+
2210
+ var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
2211
+ var FAVICON_CONFIGS = [
2212
+ { name: "favicon.ico", size: 48 },
2213
+ { name: "icon.png", size: 32 },
2214
+ { name: "apple-icon.png", size: 180 }
2215
+ ];
2216
+ async function handleGenerateFavicon(request) {
2217
+ try {
2218
+ const body = await request.json();
2219
+ const { imagePath } = body;
2220
+ if (!imagePath) {
2221
+ return _server.NextResponse.json({ error: "No image path provided" }, { status: 400 });
2222
+ }
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) {
2251
+ 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
2261
+ });
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"
2268
+ });
2269
+ }
2270
+ }
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
+ }
2285
+ }
2286
+
2207
2287
  // src/handlers/index.ts
2208
2288
  async function GET(request) {
2209
2289
  if (process.env.NODE_ENV !== "development") {
@@ -2279,6 +2359,9 @@ async function POST(request) {
2279
2359
  if (route === "cdns") {
2280
2360
  return handleUpdateCdns(request);
2281
2361
  }
2362
+ if (route === "generate-favicon") {
2363
+ return handleGenerateFavicon(request);
2364
+ }
2282
2365
  return _server.NextResponse.json({ error: "Not found" }, { status: 404 });
2283
2366
  }
2284
2367
  async function DELETE(request) {