@celljs/ta-moves 4.29.0 → 4.31.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/host/index.mjs CHANGED
@@ -129,19 +129,32 @@ class MovesHost {
129
129
  faces;
130
130
  ffmpeg;
131
131
  ffprobe;
132
+ now;
132
133
  uploads = new Map;
133
- constructor(dir, faces, ffmpeg = MovesHost.find("ffmpeg"), ffprobe = MovesHost.find("ffprobe")) {
134
+ constructor(dir, faces, ffmpeg = MovesHost.find("ffmpeg"), ffprobe = MovesHost.find("ffprobe"), now = Date.now) {
134
135
  this.dir = dir;
135
136
  this.faces = faces;
136
137
  this.ffmpeg = ffmpeg;
137
138
  this.ffprobe = ffprobe;
139
+ this.now = now;
138
140
  }
141
+ sweep() {
142
+ for (const [id, upload] of this.uploads) {
143
+ if (this.now() - upload.at > MovesHost.UPLOAD_IDLE_MS) {
144
+ this.drop(id);
145
+ }
146
+ }
147
+ if (!this.uploads.size) {
148
+ rmSync(join(this.dir, "incoming"), { recursive: true, force: true });
149
+ }
150
+ }
151
+ static UPLOAD_IDLE_MS = 30 * 60 * 1000;
139
152
  list() {
140
153
  return this.read();
141
154
  }
142
155
  begin(draft) {
143
156
  const title = String(draft?.title ?? "").trim().slice(0, 24);
144
- const replace = draft?.replace && BUILT_IN[draft.replace] ? draft.replace : undefined;
157
+ const replace = typeof draft?.replace === "string" && typeof BUILT_IN[draft.replace] === "string" ? draft.replace : undefined;
145
158
  const kind = replace ? BUILT_IN[replace] : MOVE_KINDS.includes(draft?.kind) ? draft.kind : "say";
146
159
  const words = ClipCheck.words((draft?.words ?? []).join(`
147
160
  `));
@@ -157,18 +170,20 @@ class MovesHost {
157
170
  if (!this.ffmpeg || !this.ffprobe) {
158
171
  throw MoveErrors.error("no-ffmpeg");
159
172
  }
173
+ this.sweep();
160
174
  const id = randomBytes(8).toString("hex");
161
175
  const incoming = join(this.dir, "incoming");
162
176
  mkdirSync(incoming, { recursive: true });
163
177
  const file = join(incoming, id);
164
178
  writeFileSync(file, "");
165
- this.uploads.set(id, { draft: { title, kind, words, replace, size: draft.size }, file, received: 0 });
179
+ this.uploads.set(id, { draft: { title, kind, words, replace, size: draft.size }, file, received: 0, at: this.now() });
166
180
  return { id };
167
181
  }
168
182
  put(id, data) {
169
183
  const upload = this.upload(id);
170
184
  const bytes = Buffer.from(String(data), "base64");
171
185
  upload.received += bytes.length;
186
+ upload.at = this.now();
172
187
  if (upload.received > MAX_BYTES) {
173
188
  this.drop(id);
174
189
  throw MoveErrors.error("too-big", MAX_BYTES / 1024 / 1024);
@@ -417,6 +432,7 @@ function isFile(file) {
417
432
  async function activate(host) {
418
433
  const root = (await host.listPackages()).find((pkg) => pkg.name === NAME)?.root;
419
434
  const moves = new MovesHost(join(host.agentDir, "call-moves"), MovesHost.faces(root));
435
+ moves.sweep();
420
436
  return {
421
437
  list: () => moves.list(),
422
438
  begin: (draft) => moves.begin(draft),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-moves",
3
- "version": "4.29.0",
3
+ "version": "4.31.0",
4
4
  "description": "A pi package for Ta: the user's own clips of the person of video calls, checked, made like Ta's own and played with her moves",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -26,8 +26,8 @@
26
26
  "watch": "tsc -b -w --preserveWatchOutput"
27
27
  },
28
28
  "devDependencies": {
29
- "@celljs/ta-protocol": "4.29.0",
30
- "@celljs/ta-web": "4.29.0",
29
+ "@celljs/ta-protocol": "4.31.0",
30
+ "@celljs/ta-web": "4.31.0",
31
31
  "@types/react": "^19.3.0"
32
32
  },
33
33
  "publishConfig": {
package/web/index.js CHANGED
@@ -81,7 +81,7 @@ var EN = {
81
81
  remove: "Remove",
82
82
  retry: "Try again",
83
83
  problem: "Her own move plays in its place: {reason}",
84
- none: "No moves of yours yet.",
84
+ none: "No moves of yours yet",
85
85
  errors: {
86
86
  "no-ffmpeg": "Needs ffmpeg on this computer (brew install ffmpeg).",
87
87
  "not-video": "Not a video Ta can read.",
@@ -130,7 +130,7 @@ var ZH = {
130
130
  remove: "删除",
131
131
  retry: "再试一次",
132
132
  problem: "用她自带的动作代替:{reason}",
133
- none: "还没有你自己的动作。",
133
+ none: "还没有你自己的动作",
134
134
  errors: {
135
135
  "no-ffmpeg": "这台电脑需要装 ffmpeg(brew install ffmpeg)。",
136
136
  "not-video": "不是 Ta 能读的视频。",
@@ -179,7 +179,7 @@ var ZH_TW = {
179
179
  remove: "刪除",
180
180
  retry: "再試一次",
181
181
  problem: "用她內建的動作代替:{reason}",
182
- none: "還沒有你自己的動作。",
182
+ none: "還沒有你自己的動作",
183
183
  errors: {
184
184
  "no-ffmpeg": "這台電腦需要安裝 ffmpeg(brew install ffmpeg)。",
185
185
  "not-video": "不是 Ta 能讀的影片。",
@@ -235,7 +235,7 @@ var JA = {
235
235
  remove: "削除",
236
236
  retry: "もう一度",
237
237
  problem: "代わりに内蔵の動きを使います:{reason}",
238
- none: "まだあなたの動きはありません。",
238
+ none: "まだあなたの動きはありません",
239
239
  errors: {
240
240
  "no-ffmpeg": "このコンピューターに ffmpeg が必要です(brew install ffmpeg)。",
241
241
  "not-video": "Ta が読める動画ではありません。",
@@ -293,7 +293,7 @@ function bind(react) {
293
293
  var STYLE = `
294
294
  .tmv-panel { display: flex; flex-direction: column; gap: 12px; width: 100%; }
295
295
  .tmv-note { margin: 0; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); line-height: 1.5; }
296
- .tmv-bad { color: var(--ta-danger, #d93025); }
296
+ .tmv-bad { color: var(--ta-red); }
297
297
  .tmv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border-radius: 12px; background: var(--ta-raised); }
298
298
  .tmv-move { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
299
299
  .tmv-move + .tmv-move { box-shadow: inset 0 1px 0 var(--ta-border-muted); }
@@ -302,11 +302,12 @@ var STYLE = `
302
302
  .tmv-form { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 12px; background: var(--ta-raised); }
303
303
  .tmv-head { font-weight: 600; }
304
304
  .tmv-field { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; font-size: calc(14px * var(--ta-font-scale)); }
305
- .tmv-field input:not([type='file']), .tmv-field select { height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--ta-border); background: var(--ta-main); color: var(--ta-text); font: inherit; min-width: 0; }
305
+ .tmv-field .ta-input { min-width: 0; }
306
+ .tmv-field .ta-select { width: 100%; height: 36px; padding: 0 10px; font-size: inherit; }
307
+ .tmv-pick { display: flex; align-items: center; gap: 8px; min-width: 0; }
308
+ .tmv-file { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
306
309
  .tmv-actions { display: flex; justify-content: flex-end; }
307
- .tmv-button { height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--ta-border); background: transparent; color: var(--ta-text); font: inherit; font-weight: 500; cursor: pointer; flex: none; }
308
- .tmv-button:disabled { opacity: 0.5; cursor: default; }
309
- .tmv-primary { background: var(--ta-accent); border-color: var(--ta-accent); color: #fff; }
310
+ .tmv-move > .ta-button { flex: none; }
310
311
  [data-layout='compact'] .tmv-field { grid-template-columns: 1fr; gap: 4px; }
311
312
  `;
312
313
  function injectStyle() {
@@ -481,30 +482,41 @@ function MovesPanel({ pi }) {
481
482
  className: `tmv-note${move.problem ? " tmv-bad" : ""}`
482
483
  }, move.problem ? MovesWords.fill(words.problem, { reason: move.problem }) : words.ok, move.blended ? ` · ${MovesWords.fill(words.blended, { first: move.seat.first, last: move.seat.last })}` : "")), move.problem && /* @__PURE__ */ React.createElement("button", {
483
484
  type: "button",
484
- className: `tmv-button${busy ? " ta-busy" : ""}`,
485
+ className: `ta-button${busy ? " ta-busy" : ""}`,
485
486
  disabled: busy,
486
487
  onClick: () => void run(() => act("retry", move.name))
487
488
  }, words.retry), /* @__PURE__ */ React.createElement("button", {
488
489
  type: "button",
489
- className: `tmv-button${busy ? " ta-busy" : ""}`,
490
+ className: `ta-button${busy ? " ta-busy" : ""}`,
490
491
  disabled: busy,
491
492
  onClick: () => void run(() => act("remove", move.name))
492
- }, words.remove)))) : /* @__PURE__ */ React.createElement("p", {
493
- className: "tmv-note"
494
- }, words.none), /* @__PURE__ */ React.createElement("div", {
493
+ }, words.remove)))) : /* @__PURE__ */ React.createElement(pi.ui.Empty, {
494
+ compact: true,
495
+ title: words.none
496
+ }), /* @__PURE__ */ React.createElement("div", {
495
497
  className: "tmv-form"
496
498
  }, /* @__PURE__ */ React.createElement("div", {
497
499
  className: "tmv-head"
498
- }, words.add), /* @__PURE__ */ React.createElement("label", {
500
+ }, words.add), /* @__PURE__ */ React.createElement("div", {
499
501
  className: "tmv-field"
500
- }, /* @__PURE__ */ React.createElement("span", null, words.file), /* @__PURE__ */ React.createElement("input", {
502
+ }, /* @__PURE__ */ React.createElement("span", null, words.file), /* @__PURE__ */ React.createElement("span", {
503
+ className: "tmv-pick"
504
+ }, /* @__PURE__ */ React.createElement("button", {
505
+ type: "button",
506
+ className: "ta-button",
507
+ onClick: () => input.current?.click()
508
+ }, words.pick), file && /* @__PURE__ */ React.createElement("span", {
509
+ className: "tmv-note tmv-file"
510
+ }, file.name)), /* @__PURE__ */ React.createElement("input", {
501
511
  ref: input,
502
512
  type: "file",
503
513
  accept: "video/*",
514
+ hidden: true,
504
515
  onChange: (event) => setFile(event.currentTarget.files?.[0])
505
516
  })), /* @__PURE__ */ React.createElement("label", {
506
517
  className: "tmv-field"
507
518
  }, /* @__PURE__ */ React.createElement("span", null, words.name), /* @__PURE__ */ React.createElement("input", {
519
+ className: "ta-input",
508
520
  value: title,
509
521
  maxLength: 24,
510
522
  placeholder: words.namePlaceholder,
@@ -512,6 +524,7 @@ function MovesPanel({ pi }) {
512
524
  })), /* @__PURE__ */ React.createElement("label", {
513
525
  className: "tmv-field"
514
526
  }, /* @__PURE__ */ React.createElement("span", null, words.replace), /* @__PURE__ */ React.createElement("select", {
527
+ className: "ta-input ta-select",
515
528
  value: replace,
516
529
  onChange: (event) => setReplace(event.currentTarget.value)
517
530
  }, /* @__PURE__ */ React.createElement("option", {
@@ -522,6 +535,7 @@ function MovesPanel({ pi }) {
522
535
  }, words.builtIn[name] ?? name)))), !replace && /* @__PURE__ */ React.createElement("label", {
523
536
  className: "tmv-field"
524
537
  }, /* @__PURE__ */ React.createElement("span", null, words.kind), /* @__PURE__ */ React.createElement("select", {
538
+ className: "ta-input ta-select",
525
539
  value: kind,
526
540
  onChange: (event) => setKind(event.currentTarget.value)
527
541
  }, MOVE_KINDS.map((one) => /* @__PURE__ */ React.createElement("option", {
@@ -530,6 +544,7 @@ function MovesPanel({ pi }) {
530
544
  }, words.kinds[one])))), (replace || kind === "say" || kind === "after") && /* @__PURE__ */ React.createElement("label", {
531
545
  className: "tmv-field"
532
546
  }, /* @__PURE__ */ React.createElement("span", null, words.words), /* @__PURE__ */ React.createElement("input", {
547
+ className: "ta-input",
533
548
  value: said,
534
549
  placeholder: words.wordsPlaceholder,
535
550
  onChange: (event) => setSaid(event.currentTarget.value)
@@ -545,7 +560,7 @@ function MovesPanel({ pi }) {
545
560
  className: "tmv-actions"
546
561
  }, /* @__PURE__ */ React.createElement("button", {
547
562
  type: "button",
548
- className: `tmv-button tmv-primary${busy ? " ta-busy" : ""}`,
563
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
549
564
  disabled: busy || !file || !title.trim(),
550
565
  onClick: () => void run(add)
551
566
  }, words.add))));