poad 2.63.0 → 2.65.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.
package/utils/storage.js CHANGED
@@ -172,7 +172,24 @@ function client({ base, key, apikey, renew, fetch: doFetch = fetch, timeout = TI
172
172
  return text ? JSON.parse(text) : null;
173
173
  }
174
174
 
175
+ /** Réponse fetch brute, quel que soit son code (envois en morceaux, utils/storage-tus.js) */
176
+ async function raw(method, route, { headers: extra = {}, body } = {}) {
177
+ await fresh();
178
+ const ctl = new AbortController();
179
+ const timer = setTimeout(() => ctl.abort(), timeout * 4);
180
+ try {
181
+ return await doFetch(`${base}/storage/v1${route}`, { method, headers: headers({ ...(body ? { 'content-length': String(body.length) } : {}), ...extra }), body, signal: ctl.signal });
182
+ } catch (err) {
183
+ const cause = (err && err.cause && err.cause.message) || (err && err.message) || String(err);
184
+ throw new CloudError(ctl.signal.aborted ? `The storage did not answer within ${(timeout * 4) / 1000} s (${base}).` : `The storage does not answer on ${base}: ${cause}`);
185
+ } finally {
186
+ clearTimeout(timer);
187
+ }
188
+ }
189
+
175
190
  return {
191
+ base,
192
+ raw,
176
193
  buckets: () => request('GET', '/bucket'),
177
194
  bucket: (id) => request('GET', `/bucket/${encodeURIComponent(id)}`),
178
195
  /** Tous les objets dont le nom commence par prefix (pages de 1000) */
@@ -354,13 +371,32 @@ async function cloudTarget(opts = {}) {
354
371
  const ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
355
372
  function engineEnv(config = {}) {
356
373
  const env = [];
374
+ // [storage] file_size_limit : taille maximale d'un fichier du projet, plafond des buckets (storage 0.6.0+)
375
+ const limit = fileSizeLimit(config);
376
+ if (limit.value) env.push(`POAD_STORAGE_FILE_SIZE_LIMIT=${limit.value}`);
357
377
  if (ID_RE.test(String(config.project_uuid || ''))) env.push(`POAD_PROJECT_UUID=${config.project_uuid}`);
358
378
  const linked = config.cloud && config.cloud.project;
359
379
  if (ID_RE.test(String(linked || ''))) env.push(`POAD_CLOUD_PROJECT=${linked}`);
360
380
  return env;
361
381
  }
362
382
 
383
+ /**
384
+ * [storage] file_size_limit de poad/config.toml → octets ({ value }), ou { warning } si la valeur est
385
+ * illisible (elle n'est alors pas transmise : la limite de l'engine, 50 MiB, reste). Octets ou texte :
386
+ * « 200MB », « 1GB » (décimal, comme Supabase), « 500MiB » (binaire). Pure.
387
+ */
388
+ function fileSizeLimit(config = {}) {
389
+ const raw = config.storage && config.storage.file_size_limit;
390
+ if (raw === undefined || raw === null || raw === '') return { value: null };
391
+ const units = { b: 1, kb: 1e3, mb: 1e6, gb: 1e9, tb: 1e12, kib: 1024, mib: 1024 ** 2, gib: 1024 ** 3, tib: 1024 ** 4 };
392
+ const m = typeof raw === 'number' ? [null, String(raw), 'b'] : /^(\d+(?:\.\d+)?)\s*([kmgt]i?b|b)?$/i.exec(String(raw).trim());
393
+ const n = m ? Math.round(Number(m[1]) * units[(m[2] || 'b').toLowerCase()]) : NaN;
394
+ if (!Number.isSafeInteger(n) || n <= 0)
395
+ return { value: null, warning: `[storage] file_size_limit = "${String(raw).slice(0, 32)}" in poad/config.toml is not a size (examples: "200MB", "1GB", 52428800): the engine default (50 MiB) is used.` };
396
+ return { value: n };
397
+ }
398
+
363
399
  /** Cible : poad.io avec --env/--project, sinon l'engine local */
364
400
  const target = (opts = {}, deps) => (opts.env || opts.project ? cloudTarget(opts) : localTarget(deps));
365
401
 
366
- module.exports = { EXIT, PARALLEL, MAX_PARALLEL, concurrency, reason, md5File, engineEnv, target, cloudTarget, when, parseRemote, isRemote, size, entries, viewEntries, joinKey, client, each, resolve, walk, mimeOf, show, localTarget };
402
+ module.exports = { fileSizeLimit, EXIT, PARALLEL, MAX_PARALLEL, concurrency, reason, md5File, engineEnv, target, cloudTarget, when, parseRemote, isRemote, size, entries, viewEntries, joinKey, client, each, resolve, walk, mimeOf, show, localTarget };