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: {
|
||||
wait: { type: "boolean" },
|
||||
w: { type: "boolean" },
|
||||
url: { type: "boolean" },
|
||||
u: { type: "boolean" },
|
||||
url: { type: "string" },
|
||||
u: { type: "string" },
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
|
|
@ -22,23 +22,23 @@ const { values: args } = parseArgs({
|
|||
|
||||
const wait = args.wait ?? args.w;
|
||||
const url = args.url ?? args.u;
|
||||
let text = await Bun.stdin.text();
|
||||
let input = url ? url : await Bun.stdin.text();
|
||||
|
||||
if (url) {
|
||||
const result = await fetch(text.trim());
|
||||
const window = new Window({ url: text.trim() });
|
||||
if (url !== undefined) {
|
||||
const result = await fetch(input.trim());
|
||||
const window = new Window({ url: input.trim() });
|
||||
const doc = window.document;
|
||||
doc.write(await result.text());
|
||||
await window.happyDOM.waitUntilComplete();
|
||||
const readable = new Readability(doc).parse();
|
||||
if (readable?.textContent) text = readable.textContent;
|
||||
if (text.trim() === result.url) {
|
||||
if (readable?.textContent) input = readable.textContent;
|
||||
if (input.trim() === result.url) {
|
||||
console.error("Unable to read web page.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!text) {
|
||||
if (!input) {
|
||||
console.error("No input given.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ console.log(
|
|||
const koko = Bun.spawn({
|
||||
cmd: ["uv", "run", "--", "python", "-u", "main.py"],
|
||||
cwd,
|
||||
stdin: Buffer.from(text),
|
||||
stdin: Buffer.from(input),
|
||||
stdout: "pipe",
|
||||
stderr: "inherit",
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue