@stndrds/cli 1.0.0-alpha.255 → 1.0.0-alpha.257
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/bin.mjs +27 -11
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -279,6 +279,23 @@ function registerConnectorsCommand(program) {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// src/commands/documents.ts
|
|
282
|
+
var BYTE_UNITS = ["B", "KB", "MB", "GB", "TB"];
|
|
283
|
+
function formatFileSize(bytes) {
|
|
284
|
+
if (bytes <= 0) return "0 B";
|
|
285
|
+
const k = 1e3;
|
|
286
|
+
const unitIndex = Math.min(BYTE_UNITS.length - 1, Math.floor(Math.log(bytes) / Math.log(k)));
|
|
287
|
+
const value = Number.parseFloat((bytes / k ** unitIndex).toFixed(1));
|
|
288
|
+
return `${value} ${BYTE_UNITS[unitIndex]}`;
|
|
289
|
+
}
|
|
290
|
+
function toFileRow(file) {
|
|
291
|
+
return {
|
|
292
|
+
id: file.id,
|
|
293
|
+
position: file.position,
|
|
294
|
+
type: file.mimeType,
|
|
295
|
+
size: formatFileSize(file.size),
|
|
296
|
+
ocrStatus: file.ocrStatus
|
|
297
|
+
};
|
|
298
|
+
}
|
|
282
299
|
function registerDocumentsCommand(program) {
|
|
283
300
|
const documents = program.command("documents").description("Manage documents");
|
|
284
301
|
documents.command("list").description("List documents").option("--limit <n>", "max documents to return").option("--offset <n>", "number of documents to skip").action(async (opts, cmd) => {
|
|
@@ -320,23 +337,22 @@ function registerDocumentsCommand(program) {
|
|
|
320
337
|
const result = await client.get(`/documents/${id}/preview`);
|
|
321
338
|
formatOutput(result, getFormat(cmd));
|
|
322
339
|
});
|
|
323
|
-
documents.command("
|
|
340
|
+
documents.command("files").description("List files in a document's pack (position-ordered)").argument("<id>", "document ID").action(async (id, _opts, cmd) => {
|
|
324
341
|
const client = getClientFromCommand(cmd);
|
|
325
|
-
const
|
|
326
|
-
|
|
342
|
+
const files = await client.get(`/documents/${id}/files`);
|
|
343
|
+
const sorted = [...files].sort((a, b) => a.position - b.position);
|
|
344
|
+
const format = getFormat(cmd);
|
|
345
|
+
formatOutput(format === "table" ? sorted.map(toFileRow) : sorted, format);
|
|
327
346
|
});
|
|
328
|
-
documents.command("add-
|
|
347
|
+
documents.command("add-file").description("Append a file to a document's pack").argument("<id>", "document ID").requiredOption("--file-id <fileId>", "file ID").action(async (id, opts, cmd) => {
|
|
329
348
|
const client = getClientFromCommand(cmd);
|
|
330
|
-
const result = await client.post(`/documents/${id}/
|
|
331
|
-
slotName: opts.slotName,
|
|
332
|
-
fileId: opts.fileId
|
|
333
|
-
});
|
|
349
|
+
const result = await client.post(`/documents/${id}/files`, { fileId: opts.fileId });
|
|
334
350
|
formatOutput(result, getFormat(cmd));
|
|
335
351
|
});
|
|
336
|
-
documents.command("remove-
|
|
352
|
+
documents.command("remove-file").description("Remove a file from a document's pack").argument("<id>", "document ID").argument("<fileId>", "file ID").action(async (id, fileId, _opts, cmd) => {
|
|
337
353
|
const client = getClientFromCommand(cmd);
|
|
338
|
-
await client.delete(`/documents/${id}/
|
|
339
|
-
process.stdout.write(`
|
|
354
|
+
await client.delete(`/documents/${id}/files/${fileId}`);
|
|
355
|
+
process.stdout.write(`File ${fileId} removed.
|
|
340
356
|
`);
|
|
341
357
|
});
|
|
342
358
|
}
|