vite-plugin-asset-manager 0.0.1 → 0.0.2

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.
@@ -18,8 +18,8 @@
18
18
  }
19
19
  })();
20
20
  </script>
21
- <script type="module" crossorigin src="/__asset_manager__/assets/index-BGQcqNrG.js"></script>
22
- <link rel="stylesheet" crossorigin href="/__asset_manager__/assets/index-u18B5UIt.css">
21
+ <script type="module" crossorigin src="/__asset_manager__/assets/index-DMq3biEu.js"></script>
22
+ <link rel="stylesheet" crossorigin href="/__asset_manager__/assets/index-BSP-y0L4.css">
23
23
  </head>
24
24
  <body class="bg-background text-foreground antialiased">
25
25
  <div id="root"></div>
package/dist/index.cjs CHANGED
@@ -248,12 +248,57 @@ async function handleGetGroupedAssets(res, scanner, query) {
248
248
  count: group.assets.filter((a) => (a.duplicatesCount ?? 0) > 0).length
249
249
  })).filter((group) => group.count > 0);
250
250
  }
251
+ const minSize = query.minSize ? parseInt(query.minSize, 10) : void 0;
252
+ const maxSize = query.maxSize ? parseInt(query.maxSize, 10) : void 0;
253
+ if (minSize !== void 0 || maxSize !== void 0) {
254
+ groups = groups.map((group) => ({
255
+ ...group,
256
+ assets: group.assets.filter((a) => {
257
+ if (minSize !== void 0 && a.size < minSize) return false;
258
+ if (maxSize !== void 0 && a.size > maxSize) return false;
259
+ return true;
260
+ })
261
+ })).map((g) => ({ ...g, count: g.assets.length })).filter((g) => g.count > 0);
262
+ }
263
+ const minDate = query.minDate ? parseInt(query.minDate, 10) : void 0;
264
+ const maxDate = query.maxDate ? parseInt(query.maxDate, 10) : void 0;
265
+ if (minDate !== void 0 || maxDate !== void 0) {
266
+ groups = groups.map((group) => ({
267
+ ...group,
268
+ assets: group.assets.filter((a) => {
269
+ if (minDate !== void 0 && a.mtime < minDate) return false;
270
+ if (maxDate !== void 0 && a.mtime > maxDate) return false;
271
+ return true;
272
+ })
273
+ })).map((g) => ({ ...g, count: g.assets.length })).filter((g) => g.count > 0);
274
+ }
275
+ const extensions = query.extensions;
276
+ if (extensions) {
277
+ const extList = extensions.split(",").map((e) => e.trim().toLowerCase());
278
+ groups = groups.map((group) => ({
279
+ ...group,
280
+ assets: group.assets.filter((a) => extList.includes(a.extension.toLowerCase()))
281
+ })).map((g) => ({ ...g, count: g.assets.length })).filter((g) => g.count > 0);
282
+ }
251
283
  const total = groups.reduce((sum, g) => sum + g.count, 0);
252
284
  sendJson(res, { groups, total });
253
285
  }
254
286
  async function handleSearch(res, scanner, query) {
255
287
  const q = query.q || "";
256
- const results = scanner.search(q);
288
+ let results = scanner.search(q);
289
+ const minSize = query.minSize ? parseInt(query.minSize, 10) : void 0;
290
+ const maxSize = query.maxSize ? parseInt(query.maxSize, 10) : void 0;
291
+ const minDate = query.minDate ? parseInt(query.minDate, 10) : void 0;
292
+ const maxDate = query.maxDate ? parseInt(query.maxDate, 10) : void 0;
293
+ const extensions = query.extensions;
294
+ if (minSize !== void 0) results = results.filter((a) => a.size >= minSize);
295
+ if (maxSize !== void 0) results = results.filter((a) => a.size <= maxSize);
296
+ if (minDate !== void 0) results = results.filter((a) => a.mtime >= minDate);
297
+ if (maxDate !== void 0) results = results.filter((a) => a.mtime <= maxDate);
298
+ if (extensions) {
299
+ const extList = extensions.split(",").map((e) => e.trim().toLowerCase());
300
+ results = results.filter((a) => extList.includes(a.extension.toLowerCase()));
301
+ }
257
302
  sendJson(res, { assets: results, total: results.length, query: q });
258
303
  }
259
304
  async function handleThumbnail(res, thumbnailService, root, query) {
@@ -314,6 +359,11 @@ async function handleServeFile(res, root, query) {
314
359
  async function handleGetStats(res, scanner, duplicateScanner) {
315
360
  const assets = scanner.getAssets();
316
361
  const dupStats = duplicateScanner.getStats();
362
+ const extensionCounts = /* @__PURE__ */ new Map();
363
+ for (const asset of assets) {
364
+ const ext = asset.extension.toLowerCase();
365
+ extensionCounts.set(ext, (extensionCounts.get(ext) || 0) + 1);
366
+ }
317
367
  const stats = {
318
368
  total: assets.length,
319
369
  byType: {
@@ -330,7 +380,8 @@ async function handleGetStats(res, scanner, duplicateScanner) {
330
380
  directories: [...new Set(assets.map((a) => a.directory))].length,
331
381
  unused: assets.filter((a) => a.importersCount === 0).length,
332
382
  duplicateGroups: dupStats.duplicateGroups,
333
- duplicateFiles: dupStats.duplicateFiles
383
+ duplicateFiles: dupStats.duplicateFiles,
384
+ extensionBreakdown: Object.fromEntries(extensionCounts)
334
385
  };
335
386
  sendJson(res, stats);
336
387
  }