UNPKG

bili-sender

Version:

It is used to automatically send barrages to the Bilibili live broadcast room

41 lines (40 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Config { static get wkfb() { const code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; return `----WebKitFormBoundary${new Array(16) .fill('') .map(() => code.at(this.getRandomNumber(0, code.length))) .join('')}`; } static parseCookie(cookie, key) { for (let item of cookie.split(';')) { const data = item.split('='); const [cookieKey, cookieValue] = [ data.at(0).replaceAll(' ', ''), data.at(1) ]; if (cookieKey === key) { return cookieValue; } } return key; } static generateHeaders(cookie) { const headers = new Headers([ ['Origin', 'https://live.bilibili.com'], [ 'User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0' ] ]); headers.set('Content-Type', `multipart/form-data; boundary=${Config.wkfb}`); headers.set('Cookie', cookie); return headers; } static getRandomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } } exports.default = Config;