fix: change URL flag from boolean to string type for proper URL passing
This commit is contained in:
parent
7441a9fc19
commit
03dee78e0c
1 changed files with 10 additions and 10 deletions
20
tts.ts
20
tts.ts
|
|
@ -13,8 +13,8 @@ const { values: args } = parseArgs({
|
||||||
options: {
|
options: {
|
||||||
wait: { type: "boolean" },
|
wait: { type: "boolean" },
|
||||||
w: { type: "boolean" },
|
w: { type: "boolean" },
|
||||||
url: { type: "boolean" },
|
url: { type: "string" },
|
||||||
u: { type: "boolean" },
|
u: { type: "string" },
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
|
|
@ -22,23 +22,23 @@ const { values: args } = parseArgs({
|
||||||
|
|
||||||
const wait = args.wait ?? args.w;
|
const wait = args.wait ?? args.w;
|
||||||
const url = args.url ?? args.u;
|
const url = args.url ?? args.u;
|
||||||
let text = await Bun.stdin.text();
|
let input = url ? url : await Bun.stdin.text();
|
||||||
|
|
||||||
if (url) {
|
if (url !== undefined) {
|
||||||
const result = await fetch(text.trim());
|
const result = await fetch(input.trim());
|
||||||
const window = new Window({ url: text.trim() });
|
const window = new Window({ url: input.trim() });
|
||||||
const doc = window.document;
|
const doc = window.document;
|
||||||
doc.write(await result.text());
|
doc.write(await result.text());
|
||||||
await window.happyDOM.waitUntilComplete();
|
await window.happyDOM.waitUntilComplete();
|
||||||
const readable = new Readability(doc).parse();
|
const readable = new Readability(doc).parse();
|
||||||
if (readable?.textContent) text = readable.textContent;
|
if (readable?.textContent) input = readable.textContent;
|
||||||
if (text.trim() === result.url) {
|
if (input.trim() === result.url) {
|
||||||
console.error("Unable to read web page.");
|
console.error("Unable to read web page.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!text) {
|
if (!input) {
|
||||||
console.error("No input given.");
|
console.error("No input given.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ console.log(
|
||||||
const koko = Bun.spawn({
|
const koko = Bun.spawn({
|
||||||
cmd: ["uv", "run", "--", "python", "-u", "main.py"],
|
cmd: ["uv", "run", "--", "python", "-u", "main.py"],
|
||||||
cwd,
|
cwd,
|
||||||
stdin: Buffer.from(text),
|
stdin: Buffer.from(input),
|
||||||
stdout: "pipe",
|
stdout: "pipe",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue