@fluid-app/fluid-cli-theme-dev 0.1.1066 → 0.1.1068

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/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, re
4
4
  import { execFileSync, spawn } from "node:child_process";
5
5
  import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
6
6
  import * as core from "@fluid-app/fluid-cli";
7
- import { declareInputs, getAuthToken, gitSyncActorFromMe, gitSyncCommitSubject, readConfig, resolveGitSyncActor, summarizeChanges, updateConfig } from "@fluid-app/fluid-cli";
7
+ import { damAssetCodeOf, damAssetUrlOf, declareInputs, getAuthToken, gitSyncActorFromMe, gitSyncCommitSubject, readConfig, resolveGitSyncActor, summarizeChanges, updateConfig, uploadToDam } from "@fluid-app/fluid-cli";
8
8
  import prompts from "prompts";
9
9
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
10
10
  import { createHash, randomBytes, randomUUID } from "node:crypto";
@@ -4061,8 +4061,8 @@ var Syncer = class {
4061
4061
  * response so the caller can thread it forward on the next PUT.
4062
4062
  *
4063
4063
  * Accepts any `application_theme_resource` shape — text uploads pass
4064
- * `{ key, content }`; binary uploads (after DAM + ImageKit
4065
- * orchestration) pass `{ key, dam_asset: { ... } }`. Both must route
4064
+ * `{ key, content }`; binary uploads (after the upload.fluid.app
4065
+ * DAM upload) pass `{ key, dam_asset: { ... } }`. Both must route
4066
4066
  * through here so `lastKnownRemoteSha` stays in lockstep with every
4067
4067
  * write the server has ack'd, mixed text/binary pushes included.
4068
4068
  *
@@ -4177,64 +4177,44 @@ var Syncer = class {
4177
4177
  return new PushConflictError(meta?.remote_sha ?? null);
4178
4178
  }
4179
4179
  async uploadBinaryFile(file, baseSha, bytes) {
4180
- const asset = (await this.api.post("/api/dam/assets", { placeholder_asset: {
4181
- description: `Uploaded via Fluid CLI: ${file.name}`,
4182
- mime_type: file.mime.name,
4183
- name: file.name
4184
- } })).asset;
4185
- const authBody = await this.api.post("/api/dam/assets/imagekit_auth", {});
4186
- const folder = this.canonicalPathToImageKitFolder(asset.canonical_path);
4187
- const formData = new FormData();
4188
- const blob = new Blob([bytes], { type: file.mime.name });
4189
- formData.append("file", blob, file.name);
4190
- formData.append("token", authBody.token);
4191
- formData.append("signature", authBody.signature);
4192
- formData.append("expire", String(authBody.expire));
4193
- formData.append("folder", folder);
4194
- formData.append("fileName", file.name);
4195
- formData.append("publicKey", "public_j7s4Ih9ETh/OCp41mVQH7tlXBdU=");
4196
- const ikResp = await fetch("https://upload.imagekit.io/api/v1/files/upload", {
4197
- method: "POST",
4198
- body: formData
4180
+ const token = getAuthToken$1();
4181
+ if (!token) throw new Error("Not logged in. Run `fluid login` first.");
4182
+ const answer = await uploadToDam({
4183
+ token,
4184
+ file: {
4185
+ bytes: new Uint8Array(bytes),
4186
+ name: file.name
4187
+ },
4188
+ description: `Uploaded via Fluid CLI: ${file.name}`
4199
4189
  });
4200
- if (!ikResp.ok) throw new Error(`ImageKit upload failed: ${ikResp.status}`);
4201
- const ikBody = await ikResp.json();
4202
- const backfillPayload = { asset: {
4203
- id: asset.id,
4204
- imagekit_file_id: ikBody.fileId,
4205
- imagekit_url: ikBody.url,
4206
- mime_type: file.mime.name,
4207
- name: file.name,
4208
- file_size: ikBody.size,
4209
- expected_path: asset.canonical_path
4210
- } };
4211
- if (ikBody.height) backfillPayload["asset"]["height"] = ikBody.height;
4212
- if (ikBody.width) backfillPayload["asset"]["width"] = ikBody.width;
4213
- const backfillBody = await this.api.post("/api/dam/assets/backfill_imagekit", backfillPayload);
4190
+ const url = damAssetUrlOf(answer);
4191
+ const code = damAssetCodeOf(answer);
4192
+ if (url === null || code === null) throw new Error(`The DAM stored ${file.name} but sent no asset code or CDN address for it. Push again.`);
4193
+ const size = bytes.length;
4214
4194
  const update = await this.putResource({
4215
4195
  key: file.relativePath,
4216
4196
  dam_asset: {
4217
- dam_asset_code: backfillBody.asset.code,
4197
+ dam_asset_code: code,
4218
4198
  content_type: file.mime.name,
4219
- content_size: ikBody.size,
4199
+ content_size: size,
4220
4200
  filename: file.name,
4221
- handle: backfillBody.asset.code,
4222
- url: backfillBody.asset.default_variant_url,
4223
- preview_image_url: ikBody.thumbnailUrl
4201
+ handle: code,
4202
+ url,
4203
+ preview_image_url: url
4224
4204
  }
4225
4205
  }, baseSha);
4226
4206
  return {
4227
4207
  ...update,
4228
4208
  key: update.key || file.relativePath,
4229
- url: update.url ?? backfillBody.asset.default_variant_url,
4230
- damAssetCode: backfillBody.asset.code,
4209
+ url: update.url ?? url,
4210
+ damAssetCode: code,
4231
4211
  assetMetadata: {
4232
- url: backfillBody.asset.default_variant_url,
4212
+ url,
4233
4213
  contentType: file.mime.name,
4234
- contentSize: ikBody.size,
4235
- previewImageUrl: ikBody.thumbnailUrl,
4214
+ contentSize: size,
4215
+ previewImageUrl: url,
4236
4216
  altText: file.name,
4237
- handle: backfillBody.asset.code
4217
+ handle: code
4238
4218
  }
4239
4219
  };
4240
4220
  }
@@ -4270,19 +4250,6 @@ var Syncer = class {
4270
4250
  }
4271
4251
  file.remove();
4272
4252
  }
4273
- canonicalPathToImageKitFolder(canonicalPath) {
4274
- const parts = canonicalPath.split(".");
4275
- const companyId = parts[0] ?? "unknown";
4276
- const category = parts[1] ?? "files";
4277
- const assetCode = parts[2] ?? "unknown";
4278
- return `${companyId}/${{
4279
- images: "images",
4280
- videos: "videos",
4281
- audio: "audio",
4282
- documents: "documents",
4283
- files: "files"
4284
- }[category] ?? "files"}/${assetCode}`;
4285
- }
4286
4253
  async deleteRemoteFile(relativePath, baseSha) {
4287
4254
  assertMemberConfigurationRetained([relativePath]);
4288
4255
  this.assetManifest.reload();