!102 【轻量级PR】更新 pup 以支持定位 macOS 系统的浏览器
Merge pull request !102 from 绫仓优希/master
This commit is contained in:
commit
e8ade7c1e2
|
@ -1,7 +1,6 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
# EditorConfig 标准配置项
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
@ -10,18 +9,27 @@ insert_final_newline = true
|
|||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
max_line_length = off
|
||||
|
||||
# IntelliJ 系列配置项
|
||||
ij_any_space_before_colon = true
|
||||
ij_any_space_after_colon = true
|
||||
ij_any_keep_indents_on_empty_lines = false
|
||||
|
||||
[{*.cjs,*.js}]
|
||||
ij_javascript_align_imports = false
|
||||
ij_javascript_use_semicolon_after_statement = false
|
||||
ij_javascript_use_double_quotes = false
|
||||
ij_javascript_enforce_trailing_comma = keep
|
||||
ij_typescript_use_semicolon_after_statement = false
|
||||
ij_typescript_use_double_quotes = false
|
||||
ij_typescript_enforce_trailing_comma = keep
|
||||
ij_javascript_space_before_method_parentheses = true
|
||||
ij_javascript_spaces_within_object_literal_braces = true
|
||||
ij_javascript_indent_chained_calls = true
|
||||
ij_javascript_if_brace_force = if_multiline
|
||||
|
||||
[*.json]
|
||||
ij_any_space_before_colon = false
|
||||
[{*.json,*.json5}]
|
||||
ij_json_keep_trailing_comma = false
|
||||
ij_json_keep_blank_lines_in_code = 0
|
||||
ij_json_keep_indents_on_empty_lines = false
|
||||
ij_json_space_after_colon = true
|
||||
ij_json_space_after_comma = true
|
||||
ij_json_space_before_colon = false
|
||||
ij_json_space_before_comma = false
|
||||
ij_json_spaces_within_braces = false
|
||||
ij_json_spaces_within_brackets = false
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const os = require("os")
|
||||
const { existsSync } = require("fs")
|
||||
const { execSync } = require("child_process")
|
||||
const os = require('os')
|
||||
const { existsSync } = require('fs')
|
||||
const { execSync } = require('child_process')
|
||||
const arch = os.arch()
|
||||
|
||||
let skipDownload = false
|
||||
let executablePath
|
||||
|
||||
if (process.platform == "linux" || process.platform == "android")
|
||||
if (process.platform === 'linux' || process.platform === 'android')
|
||||
for (const item of [
|
||||
"chromium",
|
||||
"chromium-browser",
|
||||
|
@ -19,20 +19,29 @@ if (process.platform == "linux" || process.platform == "android")
|
|||
}
|
||||
} catch (err) {}
|
||||
|
||||
if (!executablePath) for (const item of [
|
||||
"/usr/bin/chromium",
|
||||
"/usr/bin/chromium-browser",
|
||||
"/usr/bin/chrome",
|
||||
"C:/Program Files/Google/Chrome/Application/chrome.exe",
|
||||
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
|
||||
// macOS
|
||||
if (process.platform === 'darwin') for (const item of [
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
||||
]) if (existsSync(item)) {
|
||||
executablePath = item
|
||||
break
|
||||
}
|
||||
|
||||
if (executablePath || arch == "arm64" || arch == "aarch64") {
|
||||
(typeof logger == "object" ? logger : console).info(`[Chromium] ${executablePath}`)
|
||||
if (!executablePath) for (const item of [
|
||||
'/usr/bin/chromium',
|
||||
'/usr/bin/chromium-browser',
|
||||
'/usr/bin/chrome',
|
||||
'C:/Program Files/Google/Chrome/Application/chrome.exe',
|
||||
'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
|
||||
]) if (existsSync(item)) {
|
||||
executablePath = item
|
||||
break
|
||||
}
|
||||
|
||||
if (executablePath || arch === 'arm64' || arch === 'aarch64') {
|
||||
(typeof logger == 'object' ? logger : console).info(`[Chromium] ${executablePath}`)
|
||||
skipDownload = true
|
||||
}
|
||||
|
||||
module.exports = { skipDownload, executablePath }
|
||||
module.exports = { skipDownload, executablePath }
|
||||
|
|
|
@ -6,10 +6,10 @@ import path from 'node:path'
|
|||
|
||||
/**
|
||||
* 发送私聊消息,仅给好友发送
|
||||
* @param user_id qq号
|
||||
* @param userId qq号
|
||||
* @param msg 消息
|
||||
*/
|
||||
async function relpyPrivate(userId, msg) {
|
||||
async function relpyPrivate (userId, msg) {
|
||||
userId = Number(userId)
|
||||
|
||||
let friend = Bot.fl.get(userId)
|
||||
|
@ -25,7 +25,7 @@ async function relpyPrivate(userId, msg) {
|
|||
* 休眠函数
|
||||
* @param ms 毫秒
|
||||
*/
|
||||
function sleep(ms) {
|
||||
function sleep (ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,9 @@ function sleep(ms) {
|
|||
* 下载保存文件
|
||||
* @param fileUrl 下载地址
|
||||
* @param savePath 保存路径
|
||||
* @param param
|
||||
*/
|
||||
async function downFile(fileUrl, savePath, param = {}) {
|
||||
async function downFile (fileUrl, savePath, param = {}) {
|
||||
try {
|
||||
mkdirs(path.dirname(savePath))
|
||||
logger.debug(`[下载文件] ${fileUrl}`)
|
||||
|
@ -48,7 +49,7 @@ async function downFile(fileUrl, savePath, param = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
function mkdirs(dirname) {
|
||||
function mkdirs (dirname) {
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true
|
||||
} else {
|
||||
|
@ -66,9 +67,11 @@ function mkdirs(dirname) {
|
|||
* @param dec 转发描述
|
||||
* @param msgsscr 转发信息是否伪装
|
||||
*/
|
||||
async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) {
|
||||
async function makeForwardMsg (e, msg = [], dec = '', msgsscr = false) {
|
||||
|
||||
if (!Array.isArray(msg)) msg = [msg]
|
||||
if (!Array.isArray(msg)) {
|
||||
msg = [msg]
|
||||
}
|
||||
|
||||
let name = msgsscr ? e.sender.card || e.user_id : Bot.nickname
|
||||
let id = msgsscr ? e.user_id : Bot.uin
|
||||
|
@ -84,14 +87,15 @@ async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) {
|
|||
}
|
||||
|
||||
let forwardMsg = []
|
||||
for (const message of msg){
|
||||
if(!message) continue
|
||||
for (const message of msg) {
|
||||
if (!message) {
|
||||
continue
|
||||
}
|
||||
forwardMsg.push({
|
||||
...userInfo,
|
||||
message: message
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/** 制作转发内容 */
|
||||
if (e?.group?.makeForwardMsg) {
|
||||
|
|
|
@ -25,4 +25,3 @@ export default {
|
|||
return ret.length > 0 ? ret : false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,4 +37,3 @@ export default {
|
|||
return rendererBackends[cfg.renderer?.name || 'puppeteer']
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import '../config/init.js'
|
||||
import log4js from 'log4js'
|
||||
import PluginsLoader from '../plugins/loader.js'
|
||||
|
@ -49,7 +48,7 @@ class Command {
|
|||
group_id: data.group_id || 826198224,
|
||||
group_name: data.group_name || '测试群',
|
||||
user_id: data.user_id,
|
||||
user_avatar:`https://q1.qlogo.cn/g?b=qq&s=0&nk=${data.user_id}`,
|
||||
user_avatar: `https://q1.qlogo.cn/g?b=qq&s=0&nk=${data.user_id}`,
|
||||
anonymous: null,
|
||||
message: [{ type: 'text', text }],
|
||||
raw_message: text,
|
||||
|
|
|
@ -23,7 +23,7 @@ export default class PuppeteerRenderer {
|
|||
/** 截图次数 */
|
||||
this.renderNum = 0
|
||||
this.config = {
|
||||
headless: Data.def(config.headless, "new"),
|
||||
headless: Data.def(config.headless, 'new'),
|
||||
args: Data.def(config.args, [
|
||||
'--disable-gpu',
|
||||
'--disable-setuid-sandbox',
|
||||
|
@ -123,7 +123,7 @@ export default class PuppeteerRenderer {
|
|||
} else {
|
||||
logger.info(`[Chromium] ${this.browser.wsEndpoint()}`)
|
||||
if (process.env.pm_id && this.browserMacKey) {
|
||||
//缓存一下实例30天
|
||||
// 缓存一下实例30天
|
||||
const expireTime = 60 * 60 * 24 * 30
|
||||
await redis.set(this.browserMacKey, this.browser.wsEndpoint(), { EX: expireTime })
|
||||
}
|
||||
|
@ -140,15 +140,19 @@ export default class PuppeteerRenderer {
|
|||
}
|
||||
|
||||
// 获取Mac地址
|
||||
getMac() {
|
||||
getMac () {
|
||||
const mac = '00:00:00:00:00:00'
|
||||
try {
|
||||
const network = os.networkInterfaces()
|
||||
for (const a in network)
|
||||
for (const i of network[a])
|
||||
if (i.mac && i.mac != mac)
|
||||
for (const a in network) {
|
||||
for (const i of network[a]) {
|
||||
if (i.mac && i.mac != mac) {
|
||||
return i.mac
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
return mac
|
||||
}
|
||||
|
||||
|
@ -173,7 +177,9 @@ export default class PuppeteerRenderer {
|
|||
const pageHeight = data.multiPageHeight || 4000
|
||||
|
||||
let savePath = this.dealTpl(name, data)
|
||||
if (!savePath) return false
|
||||
if (!savePath) {
|
||||
return false
|
||||
}
|
||||
|
||||
let buff = ''
|
||||
let start = Date.now()
|
||||
|
@ -238,7 +244,9 @@ export default class PuppeteerRenderer {
|
|||
} else {
|
||||
buff = await page.screenshot(randData)
|
||||
}
|
||||
if (num > 2) await Data.sleep(200)
|
||||
if (num > 2) {
|
||||
await Data.sleep(200)
|
||||
}
|
||||
this.renderNum++
|
||||
|
||||
/** 计算图片大小 */
|
||||
|
@ -251,7 +259,6 @@ export default class PuppeteerRenderer {
|
|||
}
|
||||
}
|
||||
page.close().catch((err) => logger.error(err))
|
||||
|
||||
} catch (error) {
|
||||
logger.error(`[图片生成][${name}] 图片生成失败:${error}`)
|
||||
/** 关闭浏览器 */
|
||||
|
@ -335,4 +342,4 @@ export default class PuppeteerRenderer {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue