forked from HenryQW/mercury-parser-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.js
More file actions
39 lines (36 loc) · 1.32 KB
/
tools.js
File metadata and controls
39 lines (36 loc) · 1.32 KB
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
const fetch = require('cross-fetch');
const CryptoJS = require('crypto-js');
async function cloud_cookie(host, uuid, password, link) {
const content_url = new URL(link);
const hostname = content_url.hostname;
const domainParts = hostname.split('.');
const mainDomain = domainParts.slice(-2).join('.');
const url = host + '/get/' + uuid;
const ret = await fetch(url);
const json = await ret.json();
let cookies = [];
if (json && json.encrypted) {
const { cookie_data } = cookie_decrypt(uuid, json.encrypted, password);
for (const key in cookie_data) {
if (key === mainDomain) {
// merge cookie_data[key] to cookies
cookies = cookies.concat(
cookie_data[key].map((item) => {
if (item.sameSite === 'unspecified') item.sameSite = 'Lax';
return item;
})
);
}
}
}
return cookies;
}
function cookie_decrypt(uuid, encrypted, password) {
const the_key = CryptoJS.MD5(uuid + '-' + password)
.toString()
.substring(0, 16);
const decrypted = CryptoJS.AES.decrypt(encrypted, the_key).toString(CryptoJS.enc.Utf8);
const parsed = JSON.parse(decrypted);
return parsed;
}
module.exports = { cloud_cookie };