UNPKG

ecoledirecte.js

Version:

Good-looking client for EcoleDirecte's private API.

34 lines (33 loc) 1.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchPhoto = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); const util_1 = require("./util"); const EdHeadersPhoto = { Referer: "https://www.ecoledirecte.com/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", }; async function fetchPhoto(account) { if (!account.__raw.profile.photo) return; const res = await (0, node_fetch_1.default)("https:" + account.__raw.profile.photo, { method: "GET", headers: { ...EdHeadersPhoto, ...util_1.Config.get("addedHeaders") }, redirect: "follow", }).catch(() => undefined); if (!res) return; const token = res.headers.get("x-token"); if (token) account.token = token; const buf = await res.buffer(); const str = "data:" + res.headers.get("Content-Type") + ";base64," + buf.toString("base64"); return [buf, str]; } exports.fetchPhoto = fetchPhoto;