@aphexcms/cms-core 9.9.0 → 10.0.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.
Files changed (324) hide show
  1. package/dist/api/assets.d.ts +62 -7
  2. package/dist/api/assets.d.ts.map +1 -1
  3. package/dist/api/assets.js +116 -9
  4. package/dist/api/client.d.ts +1 -1
  5. package/dist/api/client.d.ts.map +1 -1
  6. package/dist/api/client.js +39 -9
  7. package/dist/api/limits.d.ts +55 -0
  8. package/dist/api/limits.d.ts.map +1 -0
  9. package/dist/api/limits.js +58 -0
  10. package/dist/api/schemas/assets.d.ts +94 -4
  11. package/dist/api/schemas/assets.d.ts.map +1 -1
  12. package/dist/api/schemas/assets.js +82 -5
  13. package/dist/api/schemas/documents.d.ts +1 -0
  14. package/dist/api/schemas/documents.d.ts.map +1 -1
  15. package/dist/api/schemas/documents.js +1 -0
  16. package/dist/api/types.d.ts +25 -0
  17. package/dist/api/types.d.ts.map +1 -1
  18. package/dist/api/upload-timeout.d.ts +17 -0
  19. package/dist/api/upload-timeout.d.ts.map +1 -0
  20. package/dist/api/upload-timeout.js +35 -0
  21. package/dist/api/upload.d.ts +42 -0
  22. package/dist/api/upload.d.ts.map +1 -0
  23. package/dist/api/upload.js +144 -0
  24. package/dist/components/AdminApp.svelte +213 -32
  25. package/dist/components/AdminApp.svelte.d.ts.map +1 -1
  26. package/dist/components/admin/AssetBrowserModal.svelte +4 -3
  27. package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
  28. package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
  29. package/dist/components/admin/MediaBrowser.svelte +1859 -281
  30. package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
  31. package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
  32. package/dist/components/admin/fields/ArrayField.svelte +21 -10
  33. package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
  34. package/dist/components/admin/fields/FileField.svelte +9 -2
  35. package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
  36. package/dist/components/admin/fields/ImageField.svelte +47 -12
  37. package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +14 -0
  40. package/dist/db/interfaces/asset.d.ts +114 -5
  41. package/dist/db/interfaces/asset.d.ts.map +1 -1
  42. package/dist/db/interfaces/document.d.ts +107 -3
  43. package/dist/db/interfaces/document.d.ts.map +1 -1
  44. package/dist/hooks.d.ts.map +1 -1
  45. package/dist/hooks.js +2 -1
  46. package/dist/image/Image.svelte +72 -0
  47. package/dist/image/Image.svelte.d.ts +40 -0
  48. package/dist/image/Image.svelte.d.ts.map +1 -0
  49. package/dist/image/index.d.ts +3 -0
  50. package/dist/image/index.d.ts.map +1 -0
  51. package/dist/image/index.js +11 -0
  52. package/dist/image/types.d.ts +28 -0
  53. package/dist/image/types.d.ts.map +1 -0
  54. package/dist/image/types.js +1 -0
  55. package/dist/images/generate.d.ts +55 -0
  56. package/dist/images/generate.d.ts.map +1 -0
  57. package/dist/images/generate.js +243 -0
  58. package/dist/images/index.d.ts +2 -0
  59. package/dist/images/index.d.ts.map +1 -0
  60. package/dist/images/index.js +7 -0
  61. package/dist/images/variants.d.ts +82 -0
  62. package/dist/images/variants.d.ts.map +1 -0
  63. package/dist/images/variants.js +124 -0
  64. package/dist/jobs/asset-reference-jobs.d.ts +49 -0
  65. package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
  66. package/dist/jobs/asset-reference-jobs.js +74 -0
  67. package/dist/jobs/run-batch.d.ts.map +1 -1
  68. package/dist/jobs/run-batch.js +5 -0
  69. package/dist/lib/api/assets.d.ts +62 -7
  70. package/dist/lib/api/assets.d.ts.map +1 -1
  71. package/dist/lib/api/assets.js +116 -9
  72. package/dist/lib/api/assets.js.map +1 -1
  73. package/dist/lib/api/client.d.ts +1 -1
  74. package/dist/lib/api/client.d.ts.map +1 -1
  75. package/dist/lib/api/client.js +39 -9
  76. package/dist/lib/api/client.js.map +1 -1
  77. package/dist/lib/api/limits.d.ts +55 -0
  78. package/dist/lib/api/limits.d.ts.map +1 -0
  79. package/dist/lib/api/limits.js +59 -0
  80. package/dist/lib/api/limits.js.map +1 -0
  81. package/dist/lib/api/schemas/assets.d.ts +94 -4
  82. package/dist/lib/api/schemas/assets.d.ts.map +1 -1
  83. package/dist/lib/api/schemas/assets.js +82 -5
  84. package/dist/lib/api/schemas/assets.js.map +1 -1
  85. package/dist/lib/api/schemas/documents.d.ts +1 -0
  86. package/dist/lib/api/schemas/documents.d.ts.map +1 -1
  87. package/dist/lib/api/schemas/documents.js +1 -0
  88. package/dist/lib/api/schemas/documents.js.map +1 -1
  89. package/dist/lib/api/types.d.ts +25 -0
  90. package/dist/lib/api/types.d.ts.map +1 -1
  91. package/dist/lib/api/upload-timeout.d.ts +17 -0
  92. package/dist/lib/api/upload-timeout.d.ts.map +1 -0
  93. package/dist/lib/api/upload-timeout.js +36 -0
  94. package/dist/lib/api/upload-timeout.js.map +1 -0
  95. package/dist/lib/api/upload.d.ts +42 -0
  96. package/dist/lib/api/upload.d.ts.map +1 -0
  97. package/dist/lib/api/upload.js +145 -0
  98. package/dist/lib/api/upload.js.map +1 -0
  99. package/dist/lib/config.d.ts.map +1 -1
  100. package/dist/lib/config.js +14 -0
  101. package/dist/lib/config.js.map +1 -1
  102. package/dist/lib/db/interfaces/asset.d.ts +114 -5
  103. package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
  104. package/dist/lib/db/interfaces/document.d.ts +107 -3
  105. package/dist/lib/db/interfaces/document.d.ts.map +1 -1
  106. package/dist/lib/hooks.d.ts.map +1 -1
  107. package/dist/lib/hooks.js +2 -1
  108. package/dist/lib/hooks.js.map +1 -1
  109. package/dist/lib/image/index.d.ts +3 -0
  110. package/dist/lib/image/index.d.ts.map +1 -0
  111. package/dist/lib/image/index.js +12 -0
  112. package/dist/lib/image/index.js.map +1 -0
  113. package/dist/lib/image/types.d.ts +28 -0
  114. package/dist/lib/image/types.d.ts.map +1 -0
  115. package/dist/lib/image/types.js +2 -0
  116. package/dist/lib/image/types.js.map +1 -0
  117. package/dist/lib/images/generate.d.ts +55 -0
  118. package/dist/lib/images/generate.d.ts.map +1 -0
  119. package/dist/lib/images/generate.js +244 -0
  120. package/dist/lib/images/generate.js.map +1 -0
  121. package/dist/lib/images/index.d.ts +2 -0
  122. package/dist/lib/images/index.d.ts.map +1 -0
  123. package/dist/lib/images/index.js +8 -0
  124. package/dist/lib/images/index.js.map +1 -0
  125. package/dist/lib/images/variants.d.ts +82 -0
  126. package/dist/lib/images/variants.d.ts.map +1 -0
  127. package/dist/lib/images/variants.js +125 -0
  128. package/dist/lib/images/variants.js.map +1 -0
  129. package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
  130. package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
  131. package/dist/lib/jobs/asset-reference-jobs.js +75 -0
  132. package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
  133. package/dist/lib/jobs/run-batch.d.ts.map +1 -1
  134. package/dist/lib/jobs/run-batch.js +5 -0
  135. package/dist/lib/jobs/run-batch.js.map +1 -1
  136. package/dist/lib/local-api/collection-api.d.ts +25 -2
  137. package/dist/lib/local-api/collection-api.d.ts.map +1 -1
  138. package/dist/lib/local-api/collection-api.js +107 -20
  139. package/dist/lib/local-api/collection-api.js.map +1 -1
  140. package/dist/lib/preview/assets.d.ts +19 -0
  141. package/dist/lib/preview/assets.d.ts.map +1 -1
  142. package/dist/lib/preview/assets.js +6 -0
  143. package/dist/lib/preview/assets.js.map +1 -1
  144. package/dist/lib/routes/assets-cdn.d.ts +19 -0
  145. package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
  146. package/dist/lib/routes/assets-cdn.js +295 -17
  147. package/dist/lib/routes/assets-cdn.js.map +1 -1
  148. package/dist/lib/schema-utils/utils.d.ts +31 -1
  149. package/dist/lib/schema-utils/utils.d.ts.map +1 -1
  150. package/dist/lib/schema-utils/utils.js +68 -0
  151. package/dist/lib/schema-utils/utils.js.map +1 -1
  152. package/dist/lib/server/api/index.d.ts.map +1 -1
  153. package/dist/lib/server/api/index.js +87 -8
  154. package/dist/lib/server/api/index.js.map +1 -1
  155. package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
  156. package/dist/lib/server/api/routes/assets-bulk.js +36 -7
  157. package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
  158. package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
  159. package/dist/lib/server/api/routes/assets-by-id.js +32 -15
  160. package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
  161. package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
  162. package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  163. package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
  164. package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
  165. package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
  166. package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
  167. package/dist/lib/server/api/routes/assets-poster.js +120 -0
  168. package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
  169. package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
  170. package/dist/lib/server/api/routes/assets-references.js +64 -5
  171. package/dist/lib/server/api/routes/assets-references.js.map +1 -1
  172. package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
  173. package/dist/lib/server/api/routes/assets.js +116 -12
  174. package/dist/lib/server/api/routes/assets.js.map +1 -1
  175. package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
  176. package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
  177. package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
  178. package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
  179. package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
  180. package/dist/lib/server/api/routes/documents.js +28 -1
  181. package/dist/lib/server/api/routes/documents.js.map +1 -1
  182. package/dist/lib/server/index.d.ts +2 -0
  183. package/dist/lib/server/index.d.ts.map +1 -1
  184. package/dist/lib/server/index.js +4 -0
  185. package/dist/lib/server/index.js.map +1 -1
  186. package/dist/lib/services/asset-references-service.d.ts +93 -0
  187. package/dist/lib/services/asset-references-service.d.ts.map +1 -0
  188. package/dist/lib/services/asset-references-service.js +198 -0
  189. package/dist/lib/services/asset-references-service.js.map +1 -0
  190. package/dist/lib/services/asset-service.d.ts +115 -14
  191. package/dist/lib/services/asset-service.d.ts.map +1 -1
  192. package/dist/lib/services/asset-service.js +312 -31
  193. package/dist/lib/services/asset-service.js.map +1 -1
  194. package/dist/lib/services/references-service.d.ts +19 -15
  195. package/dist/lib/services/references-service.d.ts.map +1 -1
  196. package/dist/lib/services/references-service.js +59 -31
  197. package/dist/lib/services/references-service.js.map +1 -1
  198. package/dist/lib/services/version-service.d.ts +10 -1
  199. package/dist/lib/services/version-service.d.ts.map +1 -1
  200. package/dist/lib/services/version-service.js +26 -4
  201. package/dist/lib/services/version-service.js.map +1 -1
  202. package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
  203. package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  204. package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
  205. package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
  206. package/dist/lib/storage/index.d.ts +1 -0
  207. package/dist/lib/storage/index.d.ts.map +1 -1
  208. package/dist/lib/storage/index.js +2 -0
  209. package/dist/lib/storage/index.js.map +1 -1
  210. package/dist/lib/storage/interfaces/storage.d.ts +135 -5
  211. package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
  212. package/dist/lib/storage/keys.d.ts +96 -0
  213. package/dist/lib/storage/keys.d.ts.map +1 -0
  214. package/dist/lib/storage/keys.js +160 -0
  215. package/dist/lib/storage/keys.js.map +1 -0
  216. package/dist/lib/type-gen.d.ts.map +1 -1
  217. package/dist/lib/type-gen.js +11 -5
  218. package/dist/lib/type-gen.js.map +1 -1
  219. package/dist/lib/types/asset.d.ts +92 -12
  220. package/dist/lib/types/asset.d.ts.map +1 -1
  221. package/dist/lib/types/capabilities.d.ts +11 -0
  222. package/dist/lib/types/capabilities.d.ts.map +1 -1
  223. package/dist/lib/types/capabilities.js +20 -6
  224. package/dist/lib/types/capabilities.js.map +1 -1
  225. package/dist/lib/types/config.d.ts +127 -0
  226. package/dist/lib/types/config.d.ts.map +1 -1
  227. package/dist/lib/types/filters.d.ts +31 -0
  228. package/dist/lib/types/filters.d.ts.map +1 -1
  229. package/dist/lib/types/schemas.d.ts +14 -0
  230. package/dist/lib/types/schemas.d.ts.map +1 -1
  231. package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
  232. package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
  233. package/dist/lib/utils/asset-reference-walk.js +144 -0
  234. package/dist/lib/utils/asset-reference-walk.js.map +1 -0
  235. package/dist/lib/utils/image-url.d.ts +61 -26
  236. package/dist/lib/utils/image-url.d.ts.map +1 -1
  237. package/dist/lib/utils/image-url.js +143 -26
  238. package/dist/lib/utils/image-url.js.map +1 -1
  239. package/dist/lib/utils/video-metadata.d.ts +39 -0
  240. package/dist/lib/utils/video-metadata.d.ts.map +1 -0
  241. package/dist/lib/utils/video-metadata.js +161 -0
  242. package/dist/lib/utils/video-metadata.js.map +1 -0
  243. package/dist/local-api/collection-api.d.ts +25 -2
  244. package/dist/local-api/collection-api.d.ts.map +1 -1
  245. package/dist/local-api/collection-api.js +107 -20
  246. package/dist/preview/assets.d.ts +19 -0
  247. package/dist/preview/assets.d.ts.map +1 -1
  248. package/dist/preview/assets.js +6 -0
  249. package/dist/routes/assets-cdn.d.ts +19 -0
  250. package/dist/routes/assets-cdn.d.ts.map +1 -1
  251. package/dist/routes/assets-cdn.js +295 -17
  252. package/dist/schema-utils/utils.d.ts +31 -1
  253. package/dist/schema-utils/utils.d.ts.map +1 -1
  254. package/dist/schema-utils/utils.js +68 -0
  255. package/dist/server/api/index.d.ts.map +1 -1
  256. package/dist/server/api/index.js +87 -8
  257. package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
  258. package/dist/server/api/routes/assets-bulk.js +36 -7
  259. package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
  260. package/dist/server/api/routes/assets-by-id.js +32 -15
  261. package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
  262. package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  263. package/dist/server/api/routes/assets-direct-upload.js +163 -0
  264. package/dist/server/api/routes/assets-poster.d.ts +4 -0
  265. package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
  266. package/dist/server/api/routes/assets-poster.js +119 -0
  267. package/dist/server/api/routes/assets-references.d.ts.map +1 -1
  268. package/dist/server/api/routes/assets-references.js +64 -5
  269. package/dist/server/api/routes/assets.d.ts.map +1 -1
  270. package/dist/server/api/routes/assets.js +116 -12
  271. package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
  272. package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
  273. package/dist/server/api/routes/clear-asset-references.js +31 -0
  274. package/dist/server/api/routes/documents.d.ts.map +1 -1
  275. package/dist/server/api/routes/documents.js +28 -1
  276. package/dist/server/index.d.ts +2 -0
  277. package/dist/server/index.d.ts.map +1 -1
  278. package/dist/server/index.js +4 -0
  279. package/dist/services/asset-references-service.d.ts +93 -0
  280. package/dist/services/asset-references-service.d.ts.map +1 -0
  281. package/dist/services/asset-references-service.js +197 -0
  282. package/dist/services/asset-service.d.ts +115 -14
  283. package/dist/services/asset-service.d.ts.map +1 -1
  284. package/dist/services/asset-service.js +312 -31
  285. package/dist/services/references-service.d.ts +19 -15
  286. package/dist/services/references-service.d.ts.map +1 -1
  287. package/dist/services/references-service.js +59 -31
  288. package/dist/services/version-service.d.ts +10 -1
  289. package/dist/services/version-service.d.ts.map +1 -1
  290. package/dist/services/version-service.js +26 -4
  291. package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
  292. package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  293. package/dist/storage/adapters/local-storage-adapter.js +86 -19
  294. package/dist/storage/index.d.ts +1 -0
  295. package/dist/storage/index.d.ts.map +1 -1
  296. package/dist/storage/index.js +2 -0
  297. package/dist/storage/interfaces/storage.d.ts +135 -5
  298. package/dist/storage/interfaces/storage.d.ts.map +1 -1
  299. package/dist/storage/keys.d.ts +96 -0
  300. package/dist/storage/keys.d.ts.map +1 -0
  301. package/dist/storage/keys.js +159 -0
  302. package/dist/type-gen.d.ts.map +1 -1
  303. package/dist/type-gen.js +11 -5
  304. package/dist/types/asset.d.ts +92 -12
  305. package/dist/types/asset.d.ts.map +1 -1
  306. package/dist/types/capabilities.d.ts +11 -0
  307. package/dist/types/capabilities.d.ts.map +1 -1
  308. package/dist/types/capabilities.js +20 -6
  309. package/dist/types/config.d.ts +127 -0
  310. package/dist/types/config.d.ts.map +1 -1
  311. package/dist/types/filters.d.ts +31 -0
  312. package/dist/types/filters.d.ts.map +1 -1
  313. package/dist/types/schemas.d.ts +14 -0
  314. package/dist/types/schemas.d.ts.map +1 -1
  315. package/dist/utils/asset-reference-walk.d.ts +44 -0
  316. package/dist/utils/asset-reference-walk.d.ts.map +1 -0
  317. package/dist/utils/asset-reference-walk.js +143 -0
  318. package/dist/utils/image-url.d.ts +61 -26
  319. package/dist/utils/image-url.d.ts.map +1 -1
  320. package/dist/utils/image-url.js +143 -26
  321. package/dist/utils/video-metadata.d.ts +39 -0
  322. package/dist/utils/video-metadata.d.ts.map +1 -0
  323. package/dist/utils/video-metadata.js +160 -0
  324. package/package.json +6 -1
@@ -0,0 +1,124 @@
1
+ import { buildVariantUrl, imageConfigHash } from '../storage/keys.js';
2
+ export const DEFAULT_IMAGE_WIDTHS = [320, 640, 960, 1280, 1920];
3
+ export const DEFAULT_IMAGE_QUALITY = 80;
4
+ /**
5
+ * Normalise the user's `images` config, or return null when disabled.
6
+ *
7
+ * Widths are de-duplicated and sorted so that two configs listing the same
8
+ * widths in a different order hash identically — otherwise reordering the array
9
+ * in `aphex.config.ts` would silently orphan every previously generated
10
+ * derivative and regenerate the lot.
11
+ */
12
+ export function resolveImageConfig(images) {
13
+ if (images === null)
14
+ return null;
15
+ const raw = images?.widths ?? DEFAULT_IMAGE_WIDTHS;
16
+ const widths = [...new Set(raw.filter((w) => Number.isInteger(w) && w > 0 && w <= 10000))].sort((a, b) => a - b);
17
+ if (widths.length === 0)
18
+ return null;
19
+ const quality = images?.quality;
20
+ return {
21
+ widths,
22
+ quality: typeof quality === 'number' && quality >= 1 && quality <= 100
23
+ ? Math.round(quality)
24
+ : DEFAULT_IMAGE_QUALITY
25
+ };
26
+ }
27
+ /** Hash identifying the config a derivative was generated under. */
28
+ export function configHashFor(config) {
29
+ return imageConfigHash(config);
30
+ }
31
+ /**
32
+ * The variant record for an asset, or null when there isn't a usable one.
33
+ *
34
+ * Validates rather than asserts: `metadata` is JSON that has been through a
35
+ * database and may predate this feature entirely, so a malformed or partial
36
+ * record must read as "no variants" and be regenerated, never crash a page
37
+ * render.
38
+ */
39
+ export function getVariants(asset) {
40
+ const record = asset.metadata?.variants;
41
+ if (!record || typeof record !== 'object')
42
+ return null;
43
+ if (typeof record.config !== 'string' || !Array.isArray(record.widths))
44
+ return null;
45
+ const widths = record.widths.filter((v) => !!v &&
46
+ typeof v === 'object' &&
47
+ typeof v.w === 'number' &&
48
+ typeof v.h === 'number' &&
49
+ typeof v.key === 'string' &&
50
+ typeof v.path === 'string' &&
51
+ typeof v.url === 'string');
52
+ if (widths.length === 0)
53
+ return null;
54
+ return { config: record.config, generatedAt: record.generatedAt, widths };
55
+ }
56
+ /**
57
+ * The already-generated derivative for an exact width, under the current config.
58
+ *
59
+ * A record generated under a different config is ignored: every variant URL
60
+ * embeds the config hash, so a stale record's URLs address files that are no
61
+ * longer referenced by anything.
62
+ */
63
+ export function pickVariant(asset, width, configHash) {
64
+ const record = getVariants(asset);
65
+ if (!record || record.config !== configHash)
66
+ return null;
67
+ return record.widths.find((v) => v.w === width) ?? null;
68
+ }
69
+ /**
70
+ * The ladder widths worth offering for this asset.
71
+ *
72
+ * Widths at or above the original's own width are dropped — upscaling produces
73
+ * a larger file that looks no better. The original's width is always included
74
+ * as the top rung so a `srcset` still has something to offer above the last
75
+ * useful ladder step.
76
+ */
77
+ /**
78
+ * Build a `srcset` for an asset, listing every ladder width worth offering.
79
+ *
80
+ * The URLs it names may not exist yet — that's the point of generate-on-miss.
81
+ * The browser requests one, `/media` produces it on the spot, and every later
82
+ * request for that width is a cache hit. So a `srcset` is correct the moment an
83
+ * asset is uploaded, with no generation having happened at all.
84
+ */
85
+ export function buildSrcset(assetId, config, configHash, originalWidth) {
86
+ return usableWidths(config, originalWidth)
87
+ .map((w) => `${buildVariantUrl(assetId, w, configHash)} ${w}w`)
88
+ .join(', ');
89
+ }
90
+ /**
91
+ * Whether derivatives can be produced for this asset at all.
92
+ *
93
+ * Lives here, next to the ladder, because two callers need the same answer: the
94
+ * server building a `srcset` and the admin client picking a thumbnail. A second
95
+ * copy of this rule would drift, and the failure is quiet — a thumbnail URL that
96
+ * falls back to a 14MB original renders perfectly and costs a hundred times what
97
+ * it should.
98
+ */
99
+ export function canGenerateVariants(asset) {
100
+ if (asset.assetType !== 'image')
101
+ return false;
102
+ // Already resolution-independent; a raster derivative is strictly worse.
103
+ if (asset.mimeType === 'image/svg+xml')
104
+ return false;
105
+ // An animated source is served as-is — resizing flattens it to one frame.
106
+ if ((asset.metadata?.pages ?? 1) > 1)
107
+ return false;
108
+ return true;
109
+ }
110
+ /**
111
+ * The smallest derivative worth requesting for a thumbnail.
112
+ *
113
+ * A grid tile is a couple of hundred pixels; the bottom rung of the ladder is
114
+ * the right answer for it, and nothing about a tile justifies more.
115
+ */
116
+ export function thumbnailWidth(config, originalWidth) {
117
+ return usableWidths(config, originalWidth)[0];
118
+ }
119
+ export function usableWidths(config, originalWidth) {
120
+ if (!originalWidth || originalWidth <= 0)
121
+ return config.widths;
122
+ const below = config.widths.filter((w) => w < originalWidth);
123
+ return below.length > 0 ? below : [config.widths[0]];
124
+ }
@@ -0,0 +1,49 @@
1
+ import { z } from 'zod';
2
+ import type { DatabaseAdapter } from '../db/interfaces/index.js';
3
+ import type { SchemaType } from '../types/schemas.js';
4
+ import type { JobHandlerMap } from './types.js';
5
+ /** Reserved built-in job type. */
6
+ export declare const ASSET_REFERENCES_BACKFILL_JOB = "asset-references.backfill";
7
+ /** Reserved built-in job type for the document-to-document reference index. */
8
+ export declare const DOCUMENT_REFERENCES_BACKFILL_JOB = "references.backfill";
9
+ /**
10
+ * Bump when indexing semantics change and every org needs one more rebuild.
11
+ *
12
+ * **Anything that changes what `collectAssetReferences` finds is such a change**
13
+ * — a new wrapper shape, a fixed gap, a corrected field path. Forgetting is
14
+ * quiet and confusing: the job already completed under the old key, so the fix
15
+ * ships, nothing re-runs, and the index stays wrong in exactly the way that was
16
+ * just fixed. v3 is the rich-text image shape, which v2 ran without.
17
+ *
18
+ * The idempotency key is the marker for "this org has been backfilled" — a
19
+ * completed job row, which `scheduleJob` returns instead of inserting a
20
+ * duplicate. That makes enqueueing free to attempt on every request and correct
21
+ * to attempt only once, without a flag anywhere that a normal write could set by
22
+ * accident. The previous design inferred it from "does the index have any rows",
23
+ * which the incremental path also satisfies, so the rebuild it was gating never
24
+ * ran a second time and never could.
25
+ */
26
+ export declare const REFERENCE_BACKFILL_VERSION = 4;
27
+ export declare const assetReferencesBackfillKey: (organizationId: string) => string;
28
+ export declare const documentReferencesBackfillKey: (organizationId: string) => string;
29
+ /** Identifiers only — the handler re-reads content itself, as every job should. */
30
+ export declare const assetReferencesBackfillPayload: z.ZodObject<{
31
+ documentTypes: z.ZodArray<z.ZodString>;
32
+ }, z.core.$strip>;
33
+ export interface AssetReferenceJobDeps {
34
+ databaseAdapter: DatabaseAdapter;
35
+ schemaTypes: SchemaType[];
36
+ }
37
+ /**
38
+ * Handler for the one-time index rebuild.
39
+ *
40
+ * Idempotent by construction rather than by short-circuit: rows are *replaced*
41
+ * per document, so running it twice converges on the same index, and the
42
+ * at-least-once delivery the queue guarantees costs duplicate work at worst.
43
+ *
44
+ * An earlier version tried to be idempotent by returning early once the org had
45
+ * any rows. That is not idempotence, it is a latch — and because ordinary saves
46
+ * also create rows, it latched shut before the rebuild had ever run.
47
+ */
48
+ export declare function createAssetReferenceJobHandlers(deps: AssetReferenceJobDeps): JobHandlerMap;
49
+ //# sourceMappingURL=asset-reference-jobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-reference-jobs.d.ts","sourceRoot":"","sources":["../../src/lib/jobs/asset-reference-jobs.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,kCAAkC;AAClC,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAEzE,+EAA+E;AAC/E,eAAO,MAAM,gCAAgC,wBAAwB,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,eAAO,MAAM,0BAA0B,GAAI,gBAAgB,MAAM,WACY,CAAC;AAE9E,eAAO,MAAM,6BAA6B,GAAI,gBAAgB,MAAM,WACG,CAAC;AAExE,mFAAmF;AACnF,eAAO,MAAM,8BAA8B;;iBAEzC,CAAC;AAEH,MAAM,WAAW,qBAAqB;IACrC,eAAe,EAAE,eAAe,CAAC;IACjC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,qBAAqB,GAAG,aAAa,CA2B1F"}
@@ -0,0 +1,74 @@
1
+ // Built-in job for rebuilding the asset-reference index.
2
+ //
3
+ // The index is maintained incrementally as documents are saved, so it only needs a
4
+ // bulk pass once: for content that predates the index. That pass walks every
5
+ // document in the organization, which is exactly the shape of work that must not
6
+ // happen inside an HTTP request — it was briefly wired that way, and on a 50k
7
+ // document set the first editor to open the "Unused" filter would have worn the
8
+ // entire walk before their page rendered.
9
+ import { z } from 'zod';
10
+ import { ReferencesService } from '../services/references-service.js';
11
+ import { AssetReferencesService } from '../services/asset-references-service.js';
12
+ /** Reserved built-in job type. */
13
+ export const ASSET_REFERENCES_BACKFILL_JOB = 'asset-references.backfill';
14
+ /** Reserved built-in job type for the document-to-document reference index. */
15
+ export const DOCUMENT_REFERENCES_BACKFILL_JOB = 'references.backfill';
16
+ /**
17
+ * Bump when indexing semantics change and every org needs one more rebuild.
18
+ *
19
+ * **Anything that changes what `collectAssetReferences` finds is such a change**
20
+ * — a new wrapper shape, a fixed gap, a corrected field path. Forgetting is
21
+ * quiet and confusing: the job already completed under the old key, so the fix
22
+ * ships, nothing re-runs, and the index stays wrong in exactly the way that was
23
+ * just fixed. v3 is the rich-text image shape, which v2 ran without.
24
+ *
25
+ * The idempotency key is the marker for "this org has been backfilled" — a
26
+ * completed job row, which `scheduleJob` returns instead of inserting a
27
+ * duplicate. That makes enqueueing free to attempt on every request and correct
28
+ * to attempt only once, without a flag anywhere that a normal write could set by
29
+ * accident. The previous design inferred it from "does the index have any rows",
30
+ * which the incremental path also satisfies, so the rebuild it was gating never
31
+ * ran a second time and never could.
32
+ */
33
+ export const REFERENCE_BACKFILL_VERSION = 4;
34
+ export const assetReferencesBackfillKey = (organizationId) => `asset-references:backfill:v${REFERENCE_BACKFILL_VERSION}:${organizationId}`;
35
+ export const documentReferencesBackfillKey = (organizationId) => `references:backfill:v${REFERENCE_BACKFILL_VERSION}:${organizationId}`;
36
+ /** Identifiers only — the handler re-reads content itself, as every job should. */
37
+ export const assetReferencesBackfillPayload = z.object({
38
+ documentTypes: z.array(z.string())
39
+ });
40
+ /**
41
+ * Handler for the one-time index rebuild.
42
+ *
43
+ * Idempotent by construction rather than by short-circuit: rows are *replaced*
44
+ * per document, so running it twice converges on the same index, and the
45
+ * at-least-once delivery the queue guarantees costs duplicate work at worst.
46
+ *
47
+ * An earlier version tried to be idempotent by returning early once the org had
48
+ * any rows. That is not idempotence, it is a latch — and because ordinary saves
49
+ * also create rows, it latched shut before the rebuild had ever run.
50
+ */
51
+ export function createAssetReferenceJobHandlers(deps) {
52
+ const service = new AssetReferencesService(deps.databaseAdapter);
53
+ return {
54
+ [ASSET_REFERENCES_BACKFILL_JOB]: async ({ job }) => {
55
+ const { documentTypes } = assetReferencesBackfillPayload.parse(job.payload);
56
+ await service.backfill(job.organizationId, documentTypes);
57
+ },
58
+ /**
59
+ * The document-to-document index, same shape and for the same reason.
60
+ *
61
+ * This one had a `backfillIfEmpty` that nothing ever called, so content
62
+ * predating the index has no rows — and back-references are what the
63
+ * publish/unpublish guards read. An under-populated index there doesn't
64
+ * mislabel a badge, it lets a still-referenced document through a guard.
65
+ *
66
+ * Schemas come from the engine rather than the payload: they are code, and
67
+ * a job that outlived a schema rename should use today's list, not the one
68
+ * that existed when it was enqueued.
69
+ */
70
+ [DOCUMENT_REFERENCES_BACKFILL_JOB]: async ({ job }) => {
71
+ await new ReferencesService(deps.databaseAdapter).backfill(job.organizationId, deps.schemaTypes);
72
+ }
73
+ };
74
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"run-batch.d.ts","sourceRoot":"","sources":["../../src/lib/jobs/run-batch.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,E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obs.js';
12
12
  import { relayOutbox } from './relay.js';
13
13
  import { createDocumentJobHandlers } from './document-jobs.js';
14
+ import { createAssetReferenceJobHandlers } from './asset-reference-jobs.js';
14
15
  import { consumerJobType, toConsumerJobHandler } from '../events/consumer.js';
15
16
  /**
16
17
  * Run one full worker tick: relay the outbox, then run one bounded batch of due jobs with the
@@ -49,6 +50,10 @@ export async function runJobsBatch(services, options = {}) {
49
50
  databaseAdapter,
50
51
  handlers: {
51
52
  ...createDocumentJobHandlers({ localAPI }),
53
+ ...createAssetReferenceJobHandlers({
54
+ databaseAdapter,
55
+ schemaTypes: config.schemaTypes ?? []
56
+ }),
52
57
  ...consumerHandlers,
53
58
  ...partResolver.jobHandlers(),
54
59
  ...(config.jobs?.handlers ?? {})
@@ -1,37 +1,90 @@
1
+ import { type UploadOptions } from './upload.js';
1
2
  import type { ApiResponse } from './types.js';
2
3
  import type { Asset } from '../types/asset.js';
3
- import type { AssetReference, ListAssetsQuery, UpdateAssetRequest } from './schemas/assets.js';
4
+ import type { AssetDeleteConflict, BulkAssetDeleteConflict, AssetReference, ListAssetsQuery, UpdateAssetRequest } from './schemas/assets.js';
4
5
  export type AssetFilters = ListAssetsQuery;
5
6
  export type UpdateAssetData = UpdateAssetRequest;
6
- export type { AssetReference };
7
+ export type { AssetReference, AssetDeleteConflict, BulkAssetDeleteConflict };
7
8
  export declare class AssetsApi {
8
9
  /**
9
10
  * List assets with optional filters
10
11
  */
12
+ /**
13
+ * Attach a poster frame to an existing video.
14
+ *
15
+ * Separate from the upload because the frame's storage key derives from an
16
+ * asset id that doesn't exist until the row does: upload the video, learn the
17
+ * id, then send the frame here.
18
+ */
19
+ static uploadPoster(assetId: string, poster: Blob | undefined, info?: {
20
+ duration?: number;
21
+ width?: number;
22
+ height?: number;
23
+ }): Promise<ApiResponse<unknown>>;
11
24
  static list(filters?: ListAssetsQuery): Promise<ApiResponse<Asset[]>>;
12
25
  /**
13
26
  * Get asset by ID
14
27
  */
15
28
  static getById(id: string): Promise<ApiResponse<Asset>>;
29
+ /**
30
+ * Upload a file, choosing the transport.
31
+ *
32
+ * Direct-to-storage when the server reports it available, otherwise through
33
+ * the app. The choice is the server's to report, not the client's to guess:
34
+ * it depends on whether the adapter can sign, whether an encryption key is
35
+ * configured, and whether the operator opted in — the last of which implies
36
+ * bucket CORS that nothing here can detect.
37
+ */
38
+ static uploadFile(file: File, opts?: {
39
+ direct?: boolean;
40
+ schemaType?: string;
41
+ fieldPath?: string;
42
+ /** Read from the file in the browser; absent for non-video or an undecodable codec. */
43
+ videoDuration?: number;
44
+ videoWidth?: number;
45
+ videoHeight?: number;
46
+ } & UploadOptions): Promise<ApiResponse<Asset>>;
47
+ /**
48
+ * Three-step direct upload: get a signed URL, PUT to storage, confirm.
49
+ *
50
+ * Progress covers only the PUT — it is the whole transfer, and reporting the
51
+ * two bookkeeping calls would just make the bar jump.
52
+ */
53
+ private static uploadDirect;
16
54
  /**
17
55
  * Upload a new asset (multipart/form-data)
18
56
  * Note: Use FormData for file uploads
19
57
  */
20
- static upload(formData: FormData): Promise<ApiResponse<Asset>>;
58
+ static upload(formData: FormData, options?: UploadOptions): Promise<ApiResponse<Asset>>;
21
59
  /**
22
60
  * Update asset metadata
23
61
  */
24
62
  static update(id: string, data: UpdateAssetRequest): Promise<ApiResponse<Asset>>;
25
63
  /**
26
- * Delete an asset
64
+ * Delete an asset.
65
+ *
66
+ * Throws `ApiError` with status 409 and an {@link AssetDeleteConflict} body when
67
+ * the asset is still referenced. Pass `{ force: true }` to delete anyway —
68
+ * necessary when the reference is held by a document whose schema type is no
69
+ * longer registered, since that document can't be opened to remove it by hand.
27
70
  */
28
- static delete(id: string): Promise<ApiResponse<{
71
+ static delete(id: string, options?: {
72
+ force?: boolean;
73
+ }): Promise<ApiResponse<{
29
74
  success: boolean;
30
75
  }>>;
31
76
  /**
32
- * Bulk delete assets
77
+ * Bulk delete assets.
78
+ *
79
+ * Rejects with a 409 carrying {@link BulkAssetDeleteConflict} when any of them
80
+ * is still referenced. `{ force: true }` deletes anyway — the same escape the
81
+ * single-asset delete has, and for the same reason: a reference held by a
82
+ * document whose schema type is no longer registered cannot be removed by
83
+ * hand, so without it those assets are undeletable.
33
84
  */
34
- static deleteBulk(ids: string[]): Promise<ApiResponse<{
85
+ static deleteBulk(ids: string[], options?: {
86
+ force?: boolean;
87
+ }): Promise<ApiResponse<{
35
88
  deleted: number;
36
89
  failed: number;
37
90
  }>>;
@@ -49,8 +102,10 @@ export declare class AssetsApi {
49
102
  }
50
103
  export declare const assets: {
51
104
  list: typeof AssetsApi.list;
105
+ uploadPoster: typeof AssetsApi.uploadPoster;
52
106
  getById: typeof AssetsApi.getById;
53
107
  upload: typeof AssetsApi.upload;
108
+ uploadFile: typeof AssetsApi.uploadFile;
54
109
  update: typeof AssetsApi.update;
55
110
  delete: typeof AssetsApi.delete;
56
111
  deleteBulk: typeof AssetsApi.deleteBulk;
@@ -1 +1 @@
1
- {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../../src/lib/api/assets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI5F,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAC3C,MAAM,MAAM,eAAe,GAAG,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,qBAAa,SAAS;IACrB;;OAEG;WACU,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IAI3E;;OAEG;WACU,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAI7D;;;OAGG;WACU,MAAM,CAAC,Q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CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAItF;;;;;;;OAOG;WACU,MAAM,CAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3B,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAK7C;;;;;;;;OAQG;WACU,UAAU,CACtB,GAAG,EAAE,MAAM,EAAE,EACb,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3B,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAK5D;;OAEG;WACU,aAAa,CACzB,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,WAAW,CAAC;QAAE,UAAU,EAAE,cAAc,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAMxE;;OAEG;WACU,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAG5F;AAGD,eAAO,MAAM,MAAM;;;;;;;;;;;CAWlB,CAAC"}
@@ -1,9 +1,34 @@
1
1
  // Assets API client - manage uploaded files and images
2
- import { apiClient } from './client.js';
2
+ import { apiClient, ApiError } from './client.js';
3
+ import { putToStorage, uploadFormData } from './upload.js';
4
+ import { uploadTimeoutFor, uploadTimeoutForBytes } from './upload-timeout.js';
3
5
  export class AssetsApi {
4
6
  /**
5
7
  * List assets with optional filters
6
8
  */
9
+ /**
10
+ * Attach a poster frame to an existing video.
11
+ *
12
+ * Separate from the upload because the frame's storage key derives from an
13
+ * asset id that doesn't exist until the row does: upload the video, learn the
14
+ * id, then send the frame here.
15
+ */
16
+ static async uploadPoster(assetId,
17
+ // Optional: audio has a duration worth storing and no frame to store.
18
+ poster, info = {}) {
19
+ const body = new FormData();
20
+ if (poster)
21
+ body.append('poster', new File([poster], 'poster.webp', { type: 'image/webp' }));
22
+ // Sent with the frame because the browser reads them from the same
23
+ // `loadedmetadata`; decoding a second time to fetch them would be waste.
24
+ if (info.duration != null)
25
+ body.append('duration', String(info.duration));
26
+ if (info.width != null)
27
+ body.append('width', String(info.width));
28
+ if (info.height != null)
29
+ body.append('height', String(info.height));
30
+ return apiClient.post(`/assets/${assetId}/poster`, body);
31
+ }
7
32
  static async list(filters) {
8
33
  return apiClient.get('/assets', filters);
9
34
  }
@@ -13,12 +38,79 @@ export class AssetsApi {
13
38
  static async getById(id) {
14
39
  return apiClient.get(`/assets/${id}`);
15
40
  }
41
+ /**
42
+ * Upload a file, choosing the transport.
43
+ *
44
+ * Direct-to-storage when the server reports it available, otherwise through
45
+ * the app. The choice is the server's to report, not the client's to guess:
46
+ * it depends on whether the adapter can sign, whether an encryption key is
47
+ * configured, and whether the operator opted in — the last of which implies
48
+ * bucket CORS that nothing here can detect.
49
+ */
50
+ static async uploadFile(file, opts = {}) {
51
+ const { direct, schemaType, fieldPath, videoDuration, videoWidth, videoHeight, ...uploadOptions } = opts;
52
+ if (direct) {
53
+ try {
54
+ return await AssetsApi.uploadDirect(file, { schemaType, fieldPath }, uploadOptions);
55
+ }
56
+ catch (err) {
57
+ // Only a missing endpoint justifies retrying the other way. A CORS
58
+ // failure or a rejected signature must surface: silently proxying a
59
+ // file the platform will refuse turns a fixable misconfiguration
60
+ // into a confusing size error.
61
+ if (!(err instanceof ApiError) || err.status !== 404)
62
+ throw err;
63
+ }
64
+ }
65
+ const formData = new FormData();
66
+ formData.append('file', file);
67
+ if (schemaType)
68
+ formData.append('schemaType', schemaType);
69
+ if (fieldPath)
70
+ formData.append('fieldPath', fieldPath);
71
+ // Browser-read video facts. Claims, not proof — the server clamps them, since
72
+ // nothing stops a caller posting a duration of a billion seconds.
73
+ if (videoDuration != null)
74
+ formData.append('videoDuration', String(videoDuration));
75
+ if (videoWidth != null)
76
+ formData.append('videoWidth', String(videoWidth));
77
+ if (videoHeight != null)
78
+ formData.append('videoHeight', String(videoHeight));
79
+ return AssetsApi.upload(formData, uploadOptions);
80
+ }
81
+ /**
82
+ * Three-step direct upload: get a signed URL, PUT to storage, confirm.
83
+ *
84
+ * Progress covers only the PUT — it is the whole transfer, and reporting the
85
+ * two bookkeeping calls would just make the bar jump.
86
+ */
87
+ static async uploadDirect(file, meta, options) {
88
+ const grant = (await apiClient.post('/assets/upload-url', {
89
+ filename: file.name,
90
+ mimeType: file.type || 'application/octet-stream',
91
+ size: file.size,
92
+ ...meta
93
+ })).data;
94
+ if (!grant)
95
+ throw new ApiError(500, null, 'Malformed upload grant');
96
+ await putToStorage(grant.uploadUrl, file, grant.headers, {
97
+ ...options,
98
+ timeoutMs: options.timeoutMs ?? uploadTimeoutForBytes(file.size)
99
+ });
100
+ return apiClient.post('/assets/confirm', { assetId: grant.assetId }, { 'x-upload-ticket': grant.ticket });
101
+ }
16
102
  /**
17
103
  * Upload a new asset (multipart/form-data)
18
104
  * Note: Use FormData for file uploads
19
105
  */
20
- static async upload(formData) {
21
- return apiClient.post('/assets', formData);
106
+ static async upload(formData, options) {
107
+ return uploadFormData('/api/assets', formData, {
108
+ ...options,
109
+ // Derived from the payload rather than configured: a fixed deadline
110
+ // either aborts large uploads that were succeeding or waits far too
111
+ // long on small ones that have genuinely died.
112
+ timeoutMs: options?.timeoutMs ?? uploadTimeoutFor(formData)
113
+ });
22
114
  }
23
115
  /**
24
116
  * Update asset metadata
@@ -27,16 +119,29 @@ export class AssetsApi {
27
119
  return apiClient.patch(`/assets/${id}`, data);
28
120
  }
29
121
  /**
30
- * Delete an asset
122
+ * Delete an asset.
123
+ *
124
+ * Throws `ApiError` with status 409 and an {@link AssetDeleteConflict} body when
125
+ * the asset is still referenced. Pass `{ force: true }` to delete anyway —
126
+ * necessary when the reference is held by a document whose schema type is no
127
+ * longer registered, since that document can't be opened to remove it by hand.
31
128
  */
32
- static async delete(id) {
33
- return apiClient.delete(`/assets/${id}`);
129
+ static async delete(id, options) {
130
+ const query = options?.force ? '?force=true' : '';
131
+ return apiClient.delete(`/assets/${id}${query}`);
34
132
  }
35
133
  /**
36
- * Bulk delete assets
134
+ * Bulk delete assets.
135
+ *
136
+ * Rejects with a 409 carrying {@link BulkAssetDeleteConflict} when any of them
137
+ * is still referenced. `{ force: true }` deletes anyway — the same escape the
138
+ * single-asset delete has, and for the same reason: a reference held by a
139
+ * document whose schema type is no longer registered cannot be removed by
140
+ * hand, so without it those assets are undeletable.
37
141
  */
38
- static async deleteBulk(ids) {
39
- return apiClient.delete('/assets/bulk', { ids });
142
+ static async deleteBulk(ids, options) {
143
+ const query = options?.force ? '?force=true' : '';
144
+ return apiClient.delete(`/assets/bulk${query}`, { ids });
40
145
  }
41
146
  /**
42
147
  * Get documents that reference a specific asset
@@ -54,8 +159,10 @@ export class AssetsApi {
54
159
  // Export convenience functions for direct use
55
160
  export const assets = {
56
161
  list: AssetsApi.list.bind(AssetsApi),
162
+ uploadPoster: AssetsApi.uploadPoster.bind(AssetsApi),
57
163
  getById: AssetsApi.getById.bind(AssetsApi),
58
164
  upload: AssetsApi.upload.bind(AssetsApi),
165
+ uploadFile: AssetsApi.uploadFile.bind(AssetsApi),
59
166
  update: AssetsApi.update.bind(AssetsApi),
60
167
  delete: AssetsApi.delete.bind(AssetsApi),
61
168
  deleteBulk: AssetsApi.deleteBulk.bind(AssetsApi),
@@ -1 +1 @@
1
- {"version":3,"file":"assets.js","sourceRoot":"","sources":["../../../src/lib/api/assets.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAWrC,MAAM,OAAO,SAAS;IACrB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAyB;QAC1C,OAAO,SAAS,CAAC,GAAG,CAAU,SAAS,EAAE,OAA8C,CAAC,CAAC;IAC1F,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AG,EAAE,CAAC,CAAC;IAC/F,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,aAAa,CACzB,EAAU;QAEV,OAAO,SAAS,CAAC,GAAG,CACnB,WAAW,EAAE,aAAa,CAC1B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAa;QAC5C,OAAO,SAAS,CAAC,IAAI,CAAyB,2BAA2B,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACrF,CAAC;CACD;AAED,8CAA8C;AAC9C,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IACpC,YAAY,EAAE,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;IACpD,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IACxC,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;IAChD,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IACxC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IACxC,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;IAChD,aAAa,EAAE,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC;IACtD,kBAAkB,EAAE,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC;CAChE,CAAC"}
@@ -19,7 +19,7 @@ export declare class ApiClient {
19
19
  /**
20
20
  * POST request
21
21
  */
22
- post<T>(endpoint: string, body?: any): Promise<ApiResponse<T>>;
22
+ post<T>(endpoint: string, body?: any, headers?: Record<string, string>): Promise<ApiResponse<T>>;
23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