33 lines
1.0 KiB
JavaScript
Executable File
33 lines
1.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
import { exit } from "node:process";
|
|
import { log } from "node:console";
|
|
|
|
import { users } from "../.env.js";
|
|
const credentials= users[0];
|
|
|
|
const host= "https://rss.jaandrle.cz/";
|
|
const Authorization= "Basic " + toBase64(credentials);
|
|
const headers= { Authorization, Accept: "application/json" };
|
|
|
|
const rootCategory= await fetch(host+"rest/category/get", { headers }).then(res=> res.json());
|
|
const unreadEntries= await fetch(host+"rest/category/entries?id=all&readType=unread", { headers }).then(res=> res.json());
|
|
|
|
log({
|
|
rootCategory,
|
|
unreadEntries,
|
|
});
|
|
exit(0);
|
|
|
|
function toBase64(data) {
|
|
const existsTextEncoder= typeof TextEncoder !== 'undefined';
|
|
if (!existsTextEncoder)
|
|
return btoa(data);
|
|
const existsUint8ArrayToBase64= typeof Uint8Array.prototype.toBase64 === 'function';
|
|
if (existsUint8ArrayToBase64)
|
|
return new TextEncoder().encode(data).toBase64();
|
|
|
|
const binString= Array.from(new TextEncoder().encode(data))
|
|
.map(x=> String.fromCharCode(x)).join("");
|
|
return btoa(binString);
|
|
}
|