cli
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
#!/usr/bin/env node

import { parseArgs } from "util";
import readline from "readline";

const QUICKPASTE_URL = process.env.QUICKPASTE_URL || "https://quickpaste.net";

const options = {
  lang: {
    type: "string",
    short: "l",
    default: "",
  },
  deleteAfter: {
    type: "string",
    short: "d",
    default: "7",
  },
};

const {
  values: { lang, deleteAfter },
} = parseArgs({ options });

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let text = "";
for await (const line of rl) {
  text += `${line}\n`;
}

const body = new FormData();
body.append("text", text.trim());
body.append("lang", lang);
body.append("deleteAfter", deleteAfter);

const response = await fetch(`${QUICKPASTE_URL}/save`, {
  method: "POST",
  headers: {
    Accept: "text/plain",
  },
  body,
});

console.log(await response.text());