vslides 1.0.31 → 1.0.32
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 +70 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3261,6 +3261,36 @@ 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 data = await response.json();
|
|
3290
|
+
return { ok: response.ok, status: response.status, data };
|
|
3291
|
+
}
|
|
3292
|
+
throw new Error("Sandbox failed to wake up after 5 minutes");
|
|
3293
|
+
}
|
|
3264
3294
|
async function exportSlides(slug, token, format) {
|
|
3265
3295
|
const response = await fetch(`${BASE_URL}/api/slides/export?format=${format}`, {
|
|
3266
3296
|
headers: {
|
|
@@ -5504,6 +5534,45 @@ async function librarySupersede(id, options) {
|
|
|
5504
5534
|
info("Users with existing imports will be prompted to upgrade.");
|
|
5505
5535
|
}
|
|
5506
5536
|
|
|
5537
|
+
// src/commands/pdf-import.ts
|
|
5538
|
+
var import_node_fs10 = require("node:fs");
|
|
5539
|
+
var import_node_path9 = require("node:path");
|
|
5540
|
+
async function pdfImport(file, options) {
|
|
5541
|
+
const { config: cfg, token } = requireToken();
|
|
5542
|
+
if (!(0, import_node_fs10.existsSync)(file)) {
|
|
5543
|
+
error(`File not found: ${file}`);
|
|
5544
|
+
process.exit(ExitCode.ValidationError);
|
|
5545
|
+
}
|
|
5546
|
+
const ext = (0, import_node_path9.extname)(file).toLowerCase();
|
|
5547
|
+
if (ext !== ".pdf") {
|
|
5548
|
+
error(`Invalid file type: ${ext}`);
|
|
5549
|
+
info("Expected: .pdf");
|
|
5550
|
+
process.exit(ExitCode.ValidationError);
|
|
5551
|
+
}
|
|
5552
|
+
const filename = (0, import_node_path9.basename)(file);
|
|
5553
|
+
const content = (0, import_node_fs10.readFileSync)(file);
|
|
5554
|
+
info(`Importing ${filename}...`);
|
|
5555
|
+
const result = await importPdf(cfg.slug, token, filename, content, {
|
|
5556
|
+
pages: options.pages || "all",
|
|
5557
|
+
name: options.name
|
|
5558
|
+
});
|
|
5559
|
+
if (!result.ok) {
|
|
5560
|
+
error(`Failed to import PDF: ${JSON.stringify(result.data)}`);
|
|
5561
|
+
process.exit(ExitCode.NetworkError);
|
|
5562
|
+
}
|
|
5563
|
+
const data = result.data;
|
|
5564
|
+
success(`Imported ${data.pagesConverted} slides from ${filename}`);
|
|
5565
|
+
newline();
|
|
5566
|
+
info("Slides created:");
|
|
5567
|
+
for (const slide of data.slides) {
|
|
5568
|
+
info(` #${slide.sourcePage}: ${slide.src}`);
|
|
5569
|
+
}
|
|
5570
|
+
newline();
|
|
5571
|
+
info("Use in slides.md:");
|
|
5572
|
+
newline();
|
|
5573
|
+
info(data.usage);
|
|
5574
|
+
}
|
|
5575
|
+
|
|
5507
5576
|
// src/cli.ts
|
|
5508
5577
|
function wrapCommand(fn) {
|
|
5509
5578
|
return (...args) => {
|
|
@@ -5546,6 +5615,7 @@ program.command("get").description("Download current slides from server").action
|
|
|
5546
5615
|
program.command("push").description("Upload slides.md to server").option("--force", "Bypass version check").action(wrapCommand((options) => push(options)));
|
|
5547
5616
|
program.command("sync").description("Smart bidirectional sync").action(wrapCommand(sync));
|
|
5548
5617
|
program.command("upload <file>").description("Upload an image or media file").action(wrapCommand(upload));
|
|
5618
|
+
program.command("pdf-import <file>").description("Import PDF pages as slide components").option("--pages <spec>", 'Pages to import: "all", "1-5,8", or "3,7,12"', "all").option("--name <prefix>", "Component name prefix (default: derived from filename)").action(wrapCommand((file, options) => pdfImport(file, options)));
|
|
5549
5619
|
program.command("export <format>").description("Export presentation to PDF or PPTX").action(wrapCommand(exportSlides2));
|
|
5550
5620
|
program.command("deploy").description("Deploy presentation as static site").option("--status", "Check deployment status").action(wrapCommand((options) => deploy2(options)));
|
|
5551
5621
|
program.command("history").description("List saved versions").action(wrapCommand(history));
|