@celljs/ta-moves 4.29.0 → 4.30.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 +19 -3
- package/package.json +3 -3
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.
|
|
3
|
+
"version": "4.30.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.
|
|
30
|
-
"@celljs/ta-web": "4.
|
|
29
|
+
"@celljs/ta-protocol": "4.30.0",
|
|
30
|
+
"@celljs/ta-web": "4.30.0",
|
|
31
31
|
"@types/react": "^19.3.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|