UNPKG

@ginstone/nga-api

Version:

109 lines (108 loc) 3.05 kB
"use strict"; //post.php 使用的参数 Object.defineProperty(exports, "__esModule", { value: true }); exports.PostParam = exports.PrepareModify = exports.PrepareReply = exports.PrepareQuote = exports.PrepareNew = void 0; const PostAction_1 = require("../enums/PostAction"); const UnicodeUtils_1 = require("@ginstone/common-utils/dist/src/utils/UnicodeUtils"); const AT_BBS_CODE_PATTERN = /\[@(.+?)]/g; /** * 准备新主题 */ class PrepareNew { constructor(fid, stid) { this.action = PostAction_1.PostAction.NEW; this.fid = fid; this.stid = stid; } } exports.PrepareNew = PrepareNew; /** * 准备引用 */ class PrepareQuote { constructor(tid, pid) { this.action = PostAction_1.PostAction.QUOTE; this.tid = tid; this.pid = pid; } } exports.PrepareQuote = PrepareQuote; /** * 准备回复 */ class PrepareReply { constructor(tid, pid, comment) { this.action = PostAction_1.PostAction.REPLY; this.tid = tid; this.pid = pid; this.comment = comment; } } exports.PrepareReply = PrepareReply; /** * 准备编辑 */ class PrepareModify { constructor(tid, pid) { this.action = PostAction_1.PostAction.MODIFY; this.tid = tid; this.pid = pid; } } exports.PrepareModify = PrepareModify; /** * 正式发布参数 */ class PostParam { constructor(title, content, attachs, modify_append, hidden, anony) { this.step = 2; //自动字数补丁 if (!content) content = ''; if (content.length < 6) content += '[b][/b]'; this.post_content = PostParam.encodeUnicode(content); if (title) this.post_subject = title; if (modify_append) this.modify_append = modify_append; if (hidden) this.hidden = hidden; if (anony) this.anony = anony; if (attachs) { this.attachments = attachs.map(i => i.attachments).join("\t"); this.attachments_check = attachs.map(i => i.attachments_check).join("\t"); } // 检查是否有@代码 const arr = []; let matcher; while (matcher = AT_BBS_CODE_PATTERN.exec(content)) { arr.push(matcher[1]); } if (arr.length > 0) { this.mention = arr.join("\t"); } } /** * unicode编码, 编码韩文和其他字符 * @param raw 待编码字符串 */ static encodeUnicode(raw) { const content = []; for (const symbol of raw) { const lang = (0, UnicodeUtils_1.language)(symbol); const codePoint = symbol.codePointAt(0); if (codePoint) { if (lang === 'ko' || (lang === 'other' && codePoint > 65535)) { content.push(`&#${codePoint};`); } else { content.push(symbol); } } } return content.join(''); } } exports.PostParam = PostParam;