@posterly/cli 0.2.0 → 0.2.1

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 (2) hide show
  1. package/bin/posterly.mjs +18 -2
  2. package/package.json +1 -1
package/bin/posterly.mjs CHANGED
@@ -409,6 +409,8 @@ async function main() {
409
409
  }
410
410
 
411
411
  function parseArgs(args) {
412
+ // Flags that are plain on/off switches and never take the next argument.
413
+ const BOOLEAN_FLAGS = new Set(['pinContentType']);
412
414
  const [command, ...rest] = args;
413
415
  const flags = {};
414
416
  const positional = [];
@@ -426,6 +428,12 @@ function parseArgs(args) {
426
428
  flags[key] = arg.slice(eq + 1);
427
429
  continue;
428
430
  }
431
+ // Pure boolean flags never take the next argument as their value, so
432
+ // `a.jpg --pin-content-type b.jpg` keeps both files.
433
+ if (BOOLEAN_FLAGS.has(key)) {
434
+ flags[key] = true;
435
+ continue;
436
+ }
429
437
  const next = rest[i + 1];
430
438
  if (!next || next.startsWith('--')) {
431
439
  flags[key] = true;
@@ -900,9 +908,17 @@ async function mediaUploadPayload(flags, positional) {
900
908
  // (unchanged). Several files, up to 20 in one call: pass local paths with no
901
909
  // --content-type, `media:signed-upload a.jpg b.jpg c.mp4`, and the CLI reads
902
910
  // each name, type and size from disk. `--files '[{"filename","content_type",
903
- // "size"}]'` sends a batch you describe yourself.
911
+ // "size"}]'` sends a batch you describe yourself. `--pin-content-type` locks
912
+ // each slot to the declared content type: the PUT must then send exactly the
913
+ // returned Content-Type header or storage answers 403.
914
+ function takePinContentType(flags) {
915
+ // --pin-content-type (true) or --pin-content-type=true|false
916
+ return flagEnabled(flags.pinContentType) ? { pin_content_type: true } : {};
917
+ }
918
+
904
919
  async function mediaSignedUploadPayload(flags, positional) {
905
- const workspace = flags.workspaceId ? { workspace_id: flags.workspaceId } : {};
920
+ const pin = takePinContentType(flags);
921
+ const workspace = { ...(flags.workspaceId ? { workspace_id: flags.workspaceId } : {}), ...pin };
906
922
  if (flags.files !== undefined) {
907
923
  const files = jsonFlag(flags.files);
908
924
  if (!Array.isArray(files)) throw new Error('--files must be a JSON array of { filename, content_type, size }');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posterly/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Command line interface for the posterly API",
5
5
  "license": "MIT",
6
6
  "type": "module",