-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
127 lines (105 loc) · 3.47 KB
/
index.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const qs = require("query-string");
const curl = new (require("./curl"))();
const fs = require("fs");
const fetch = require("node-fetch");
const stream = fs.createWriteStream("output.txt", { flags: "a" });
const DM_ID = "CHANGE-ME";
const BEFORE_VALUE = decodeURIComponent("CHANGE-ME");
const AUTH_HEADER = "CHANGE-ME";
const QUILL_SESSION = "CHANGE-ME";
const getUrl = (dm, before) => {
const url = new URL("https://api.quill.chat/thread/history");
const search = new URLSearchParams({
includeThread: true,
dm,
});
if (before) {
search.set("before", before);
}
url.search = search.toString();
return url.toString();
};
function getFile(dm, file, name) {
return fetch(
`https://api.quill.chat/file/?dm=${dm}&file=${file}&name=${name}`,
{
headers: {
Host: "api.quill.chat",
Accept:
"image/webp,image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5",
Connection: "keep-alive",
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) QuillMacOS/1.44.0 Release (iPhone) Version/13.1.1 Safari/605.1.15",
"Accept-Language": "en-GB,en;q=0.9",
Referer: "https://app.quill.chat/",
},
}
).then((res) => res.body.pipe(fs.createWriteStream(`./files/${name}`)));
}
async function getDms(id, before) {
curl.setHeaders([
"Host: api.quill.chat",
"Accept: application/json",
`Authorization: ${AUTH_HEADER}`,
`X-Quill-Session: ${QUILL_SESSION}`,
"X-Quill-Version: appversion=1.153.0 platform=macOS package=chat.quill.app browser=safari",
"Accept-Language: en-GB,en;q=0.9",
"Cache-Control: max-age=0",
"Origin: https://app.quill.chat",
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) QuillMacOS/1.44.0 ,Release (iPhone) Version/13.1.1 Safari/605.1.15",
"Referer: https://app.quill.chat/",
"Connection: keep-alive",
"Content-Type: application/json",
]);
const u = getUrl(id, before);
const res = await curl.get(u);
console.log("run!");
for (let i = 0; i < res.body?.messages?.length; i++) {
const { message } = res.body.messages[i];
if (message?.file) {
await getFile(id, message?.file?.file, message?.file?.name);
continue;
}
if (message?.quote?.quoted) {
const quotes = message?.quote?.quoted.map(
(quote) => `> ${quote?.user}: ${quote?.text?.body}`
);
quotes.forEach((quote) => {
// console.log(`${message.user}: ${quote}`);
stream.write(`${message.user}: ${quote}\n`);
});
continue;
}
if (message?.link?.url) {
// console.log(`${message.user}: ${message?.link?.url}`);
stream.write(`${message.user}: ${message?.link?.url}\n`);
continue;
}
if (message?.slackMessage?.message?.activityRowText) {
// console.log(
// `${message.user}: ${message?.slackMessage?.message?.activityRowText}\n`
// );
stream.write(
`${message.user}: ${message?.slackMessage?.activityRowText}\n`
);
continue;
}
if (message?.text?.body) {
stream.write(`${message.user}: ${message?.text?.body}\n`);
continue;
}
console.log("unknown type");
}
if (res.body?.beforeCursor?.hasMore) {
return getDms(
id,
new Date(res.body?.beforeCursor?.timestamp).toISOString()
);
}
return;
}
async function init() {
await getDms(DM_ID, BEFORE_VALUE);
stream.end();
}
init();