UNPKG

askai-img

Version:

AI Art Generation Tool

41 lines (40 loc) 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TelegraphService = void 0; const telegraph_node_1 = __importDefault(require("telegraph-node")); class TelegraphService { constructor() { this.AUTH_NAME = 'Somnium'; this.PACKAGE_URL = 'https://www.npmjs.com/package/somnium'; this.token = null; this.client = new telegraph_node_1.default(); } async ensureAccount() { if (!this.token) { const account = await this.client.createAccount(this.AUTH_NAME); this.token = account.access_token; } } async post(title, html) { try { await this.ensureAccount(); const page = await this.client.createPage(this.token, title, [{ tag: 'div', children: [html] }], { author_name: this.AUTH_NAME, author_url: this.PACKAGE_URL, return_content: false }); return `https://telegra.ph/${page.path}`; } catch (error) { console.error('Failed to post to Telegraph:', error); throw new Error('Failed to create Telegraph page'); } } } exports.TelegraphService = TelegraphService;