vslides 1.0.31 → 1.0.33
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/cli.js +92 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3261,6 +3261,47 @@ async function uploadAsset(slug, token, filename, content) {
|
|
|
3261
3261
|
body: content.toString("base64")
|
|
3262
3262
|
});
|
|
3263
3263
|
}
|
|
3264
|
+
async function importPdf(slug, token, filename, content, options) {
|
|
3265
|
+
for (let i = 0; i < MAX_RETRIES; i++) {
|
|
3266
|
+
const formData = new FormData();
|
|
3267
|
+
formData.append("file", new Blob([new Uint8Array(content)], { type: "application/pdf" }), filename);
|
|
3268
|
+
formData.append("pages", options.pages);
|
|
3269
|
+
if (options.name) {
|
|
3270
|
+
formData.append("name", options.name);
|
|
3271
|
+
}
|
|
3272
|
+
const response = await fetch(`${BASE_URL}/api/slides/pdf-import`, {
|
|
3273
|
+
method: "POST",
|
|
3274
|
+
headers: {
|
|
3275
|
+
"X-Slug": slug,
|
|
3276
|
+
"X-Session-Token": token
|
|
3277
|
+
},
|
|
3278
|
+
body: formData
|
|
3279
|
+
});
|
|
3280
|
+
if (response.status === 503) {
|
|
3281
|
+
console.log("Sandbox waking up...");
|
|
3282
|
+
await sleep(RETRY_DELAY);
|
|
3283
|
+
continue;
|
|
3284
|
+
}
|
|
3285
|
+
if (response.status === 401) {
|
|
3286
|
+
clearCLIAuth();
|
|
3287
|
+
throw new AuthExpiredError();
|
|
3288
|
+
}
|
|
3289
|
+
const contentType = response.headers.get("content-type") || "";
|
|
3290
|
+
let data;
|
|
3291
|
+
if (contentType.includes("application/json")) {
|
|
3292
|
+
try {
|
|
3293
|
+
data = await response.json();
|
|
3294
|
+
} catch {
|
|
3295
|
+
data = { success: false, slides: [], pageCount: 0, pagesConverted: 0, usage: "", error: "Invalid JSON response from server" };
|
|
3296
|
+
}
|
|
3297
|
+
} else {
|
|
3298
|
+
const text = await response.text();
|
|
3299
|
+
data = { success: false, slides: [], pageCount: 0, pagesConverted: 0, usage: "", error: text.slice(0, 500) };
|
|
3300
|
+
}
|
|
3301
|
+
return { ok: response.ok, status: response.status, data };
|
|
3302
|
+
}
|
|
3303
|
+
throw new Error("Sandbox failed to wake up after 5 minutes");
|
|
3304
|
+
}
|
|
3264
3305
|
async function exportSlides(slug, token, format) {
|
|
3265
3306
|
const response = await fetch(`${BASE_URL}/api/slides/export?format=${format}`, {
|
|
3266
3307
|
headers: {
|
|
@@ -5504,6 +5545,56 @@ async function librarySupersede(id, options) {
|
|
|
5504
5545
|
info("Users with existing imports will be prompted to upgrade.");
|
|
5505
5546
|
}
|
|
5506
5547
|
|
|
5548
|
+
// src/commands/pdf-import.ts
|
|
5549
|
+
var import_node_fs10 = require("node:fs");
|
|
5550
|
+
var import_node_path9 = require("node:path");
|
|
5551
|
+
async function pdfImport(file, options) {
|
|
5552
|
+
if (!options.pages) {
|
|
5553
|
+
error("Missing required option: --pages");
|
|
5554
|
+
newline();
|
|
5555
|
+
info("AGENT: Ask the user which slides they want to import.");
|
|
5556
|
+
newline();
|
|
5557
|
+
info("Usage:");
|
|
5558
|
+
info(' --pages "all" All pages');
|
|
5559
|
+
info(' --pages "1-5,8-10" Range');
|
|
5560
|
+
info(' --pages "2,5,7" Specific pages');
|
|
5561
|
+
process.exit(ExitCode.ValidationError);
|
|
5562
|
+
}
|
|
5563
|
+
const { config: cfg, token } = requireToken();
|
|
5564
|
+
if (!(0, import_node_fs10.existsSync)(file)) {
|
|
5565
|
+
error(`File not found: ${file}`);
|
|
5566
|
+
process.exit(ExitCode.ValidationError);
|
|
5567
|
+
}
|
|
5568
|
+
const ext = (0, import_node_path9.extname)(file).toLowerCase();
|
|
5569
|
+
if (ext !== ".pdf") {
|
|
5570
|
+
error(`Invalid file type: ${ext}`);
|
|
5571
|
+
info("Expected: .pdf");
|
|
5572
|
+
process.exit(ExitCode.ValidationError);
|
|
5573
|
+
}
|
|
5574
|
+
const filename = (0, import_node_path9.basename)(file);
|
|
5575
|
+
const content = (0, import_node_fs10.readFileSync)(file);
|
|
5576
|
+
info(`Importing ${filename}...`);
|
|
5577
|
+
const result = await importPdf(cfg.slug, token, filename, content, {
|
|
5578
|
+
pages: options.pages,
|
|
5579
|
+
name: options.name
|
|
5580
|
+
});
|
|
5581
|
+
if (!result.ok) {
|
|
5582
|
+
error(`Failed to import PDF: ${JSON.stringify(result.data)}`);
|
|
5583
|
+
process.exit(ExitCode.NetworkError);
|
|
5584
|
+
}
|
|
5585
|
+
const data = result.data;
|
|
5586
|
+
success(`Imported ${data.pagesConverted} slides from ${filename}`);
|
|
5587
|
+
newline();
|
|
5588
|
+
info("Slides created:");
|
|
5589
|
+
for (const slide of data.slides) {
|
|
5590
|
+
info(` #${slide.sourcePage}: ${slide.src}`);
|
|
5591
|
+
}
|
|
5592
|
+
newline();
|
|
5593
|
+
info("Use in slides.md:");
|
|
5594
|
+
newline();
|
|
5595
|
+
info(data.usage);
|
|
5596
|
+
}
|
|
5597
|
+
|
|
5507
5598
|
// src/cli.ts
|
|
5508
5599
|
function wrapCommand(fn) {
|
|
5509
5600
|
return (...args) => {
|
|
@@ -5546,6 +5637,7 @@ program.command("get").description("Download current slides from server").action
|
|
|
5546
5637
|
program.command("push").description("Upload slides.md to server").option("--force", "Bypass version check").action(wrapCommand((options) => push(options)));
|
|
5547
5638
|
program.command("sync").description("Smart bidirectional sync").action(wrapCommand(sync));
|
|
5548
5639
|
program.command("upload <file>").description("Upload an image or media file").action(wrapCommand(upload));
|
|
5640
|
+
program.command("pdf-import <file>").description("Import PDF pages as slide components").option("--pages <spec>", "Pages to import (required)").option("--name <prefix>", "Component name prefix (default: derived from filename)").action(wrapCommand((file, options) => pdfImport(file, options)));
|
|
5549
5641
|
program.command("export <format>").description("Export presentation to PDF or PPTX").action(wrapCommand(exportSlides2));
|
|
5550
5642
|
program.command("deploy").description("Deploy presentation as static site").option("--status", "Check deployment status").action(wrapCommand((options) => deploy2(options)));
|
|
5551
5643
|
program.command("history").description("List saved versions").action(wrapCommand(history));
|