@fabriktor/fx 0.0.183 → 0.0.184
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/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/storage/capture.d.ts +42 -0
- package/dist/src/storage/capture.js +102 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export * from "./routes/tracking.js";
|
|
|
55
55
|
export * from "./routes/validation.js";
|
|
56
56
|
export * from "./routes/workspace.js";
|
|
57
57
|
export * from "./session/session.js";
|
|
58
|
+
export * from "./storage/capture.js";
|
|
58
59
|
export * from "./storage/storage.js";
|
|
59
60
|
export * from "./timesheets/access.js";
|
|
60
61
|
export * from "./timesheets/timesheets.js";
|
package/dist/src/index.js
CHANGED
|
@@ -55,6 +55,7 @@ export * from "./routes/tracking.js";
|
|
|
55
55
|
export * from "./routes/validation.js";
|
|
56
56
|
export * from "./routes/workspace.js";
|
|
57
57
|
export * from "./session/session.js";
|
|
58
|
+
export * from "./storage/capture.js";
|
|
58
59
|
export * from "./storage/storage.js";
|
|
59
60
|
export * from "./timesheets/access.js";
|
|
60
61
|
export * from "./timesheets/timesheets.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { InMemo } from "@fabriktor/schema";
|
|
2
|
+
import type { ChatFXOperator } from "../chat/chat.js";
|
|
3
|
+
import type { ChatSendQueue } from "../chat/send-queue.js";
|
|
4
|
+
import { type StorageFXOperator, type StorageUploadResult } from "./storage.js";
|
|
5
|
+
export declare const CaptureKind: {
|
|
6
|
+
readonly Photo: "photo";
|
|
7
|
+
readonly Video: "video";
|
|
8
|
+
};
|
|
9
|
+
export type CaptureKind = (typeof CaptureKind)[keyof typeof CaptureKind];
|
|
10
|
+
export declare function captureKinds(accept?: string): CaptureKind[];
|
|
11
|
+
export declare const RecordingDestination: {
|
|
12
|
+
readonly Chat: "chat";
|
|
13
|
+
readonly Memo: "memo";
|
|
14
|
+
readonly Storage: "storage";
|
|
15
|
+
};
|
|
16
|
+
export type RecordingDestination = (typeof RecordingDestination)[keyof typeof RecordingDestination];
|
|
17
|
+
export type RecordedMemoDraft = {
|
|
18
|
+
input: InMemo;
|
|
19
|
+
files: File[];
|
|
20
|
+
};
|
|
21
|
+
export type RecordedFileWorkflowOptions = {
|
|
22
|
+
file: File;
|
|
23
|
+
owner_id: string;
|
|
24
|
+
current: () => boolean;
|
|
25
|
+
chat: Pick<ChatFXOperator, "ensureChatRoom">;
|
|
26
|
+
queue: Pick<ChatSendQueue, "enqueue">;
|
|
27
|
+
storage: Pick<StorageFXOperator, "uploadUserObjects">;
|
|
28
|
+
};
|
|
29
|
+
export declare class RecordedFileWorkflow {
|
|
30
|
+
private readonly opts;
|
|
31
|
+
private readonly abort;
|
|
32
|
+
private readonly key;
|
|
33
|
+
private busy;
|
|
34
|
+
private completed;
|
|
35
|
+
constructor(opts: RecordedFileWorkflowOptions);
|
|
36
|
+
sendToChat(members: readonly string[]): Promise<string | undefined>;
|
|
37
|
+
saveToStorage(): Promise<StorageUploadResult | undefined>;
|
|
38
|
+
memoDraft(label: string): RecordedMemoDraft | undefined;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
private current;
|
|
41
|
+
private ready;
|
|
42
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { newChatInput } from "../chat/optimistic.js";
|
|
2
|
+
import { validateStorageUploadFiles, } from "./storage.js";
|
|
3
|
+
export const CaptureKind = { Photo: "photo", Video: "video" };
|
|
4
|
+
export function captureKinds(accept = "") {
|
|
5
|
+
const types = accept
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.split(",")
|
|
8
|
+
.map((value) => value.trim());
|
|
9
|
+
const all = !accept.trim() || types.includes("*/*");
|
|
10
|
+
const out = [];
|
|
11
|
+
if (all ||
|
|
12
|
+
types.some((value) => ["image/*", "image/jpeg", ".jpg", ".jpeg"].includes(value)))
|
|
13
|
+
out.push(CaptureKind.Photo);
|
|
14
|
+
if (all ||
|
|
15
|
+
types.some((value) => [
|
|
16
|
+
"video/*",
|
|
17
|
+
"video/mp4",
|
|
18
|
+
"video/webm",
|
|
19
|
+
"video/quicktime",
|
|
20
|
+
".mp4",
|
|
21
|
+
".webm",
|
|
22
|
+
".mov",
|
|
23
|
+
].includes(value)))
|
|
24
|
+
out.push(CaptureKind.Video);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
export const RecordingDestination = {
|
|
28
|
+
Chat: "chat",
|
|
29
|
+
Memo: "memo",
|
|
30
|
+
Storage: "storage",
|
|
31
|
+
};
|
|
32
|
+
// One recording, one destination. Retrying storage keeps its idempotency key.
|
|
33
|
+
export class RecordedFileWorkflow {
|
|
34
|
+
opts;
|
|
35
|
+
abort = new AbortController();
|
|
36
|
+
key = crypto.randomUUID();
|
|
37
|
+
busy = false;
|
|
38
|
+
completed = false;
|
|
39
|
+
constructor(opts) {
|
|
40
|
+
this.opts = opts;
|
|
41
|
+
validateStorageUploadFiles([opts.file]);
|
|
42
|
+
}
|
|
43
|
+
async sendToChat(members) {
|
|
44
|
+
if (!this.ready() || !members.length)
|
|
45
|
+
return;
|
|
46
|
+
this.busy = true;
|
|
47
|
+
try {
|
|
48
|
+
const room = await this.opts.chat.ensureChatRoom({
|
|
49
|
+
members: [...new Set(members)],
|
|
50
|
+
});
|
|
51
|
+
if (!this.current())
|
|
52
|
+
return;
|
|
53
|
+
const out = this.opts.queue.enqueue(newChatInput({ chat_room_id: room, text: "", has_objects: true }), {
|
|
54
|
+
files: [this.opts.file],
|
|
55
|
+
save_to_personal_box: false,
|
|
56
|
+
full_quality: false,
|
|
57
|
+
});
|
|
58
|
+
this.completed = true;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
this.busy = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async saveToStorage() {
|
|
66
|
+
if (!this.ready())
|
|
67
|
+
return;
|
|
68
|
+
this.busy = true;
|
|
69
|
+
try {
|
|
70
|
+
const out = await this.opts.storage.uploadUserObjects({
|
|
71
|
+
user_id: this.opts.owner_id,
|
|
72
|
+
uploader_id: this.opts.owner_id,
|
|
73
|
+
files: [this.opts.file],
|
|
74
|
+
full_quality: false,
|
|
75
|
+
idempotency_key: this.key,
|
|
76
|
+
signal: this.abort.signal,
|
|
77
|
+
});
|
|
78
|
+
this.completed = true;
|
|
79
|
+
return this.current() ? out : undefined;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
this.busy = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
memoDraft(label) {
|
|
86
|
+
if (!this.ready())
|
|
87
|
+
return;
|
|
88
|
+
return {
|
|
89
|
+
input: { is_archived: false, folder_id: "", title: "", text: label },
|
|
90
|
+
files: [this.opts.file],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
dispose() {
|
|
94
|
+
this.abort.abort();
|
|
95
|
+
}
|
|
96
|
+
current() {
|
|
97
|
+
return !this.abort.signal.aborted && this.opts.current();
|
|
98
|
+
}
|
|
99
|
+
ready() {
|
|
100
|
+
return !this.busy && !this.completed && this.current();
|
|
101
|
+
}
|
|
102
|
+
}
|