-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
executable file
·61 lines (46 loc) · 1.43 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env/ deno
// import { input, select } from "npm:@inquirer/prompts";
import input from "npm:@inquirer/input";
import select from "npm:@inquirer/select";
import { writeText } from "https://deno.land/x/copy_paste/mod.ts";
import chalk from "npm:chalk";
import { oraPromise } from "npm:ora";
import { parseItem } from "./parsing.ts";
import type { SearchResult } from "./types.ts";
async function searchLoop() {
console.clear();
const query = await input({
message: "Which distro are you interested in?",
});
if (query === undefined || query === "") {
console.log("Please enter a search term");
console.log("Press enter to exit");
return 1;
}
const baseURL = "https://apibay.org/q.php?q=";
const q = baseURL + query;
const resp = await oraPromise(fetch(q));
const data = await oraPromise(resp.json()) as SearchResult[];
if (data[0].info_hash.split("").some((s: string) => s !== "0")) {
const parsed = data.map((i) => parseItem(i));
console.clear();
const selection = select({
message: "Chose a distro",
choices: parsed,
pageSize: 20,
});
const selected = await selection;
if (selected) {
writeText(selected);
}
console.log("Copied", chalk.green(selected));
console.log("Press enter to exit");
} else {
console.log("No results for", query);
console.log("Press enter to exit");
}
}
async function main() {
await searchLoop();
}
main();