!102 【轻量级PR】更新 pup 以支持定位 macOS 系统的浏览器
Merge pull request !102 from 绫仓优希/master
This commit is contained in:
commit
e8ade7c1e2
|
@ -1,7 +1,6 @@
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
# EditorConfig 标准配置项
|
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
@ -10,18 +9,27 @@ insert_final_newline = true
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
max_line_length = off
|
max_line_length = off
|
||||||
|
|
||||||
# IntelliJ 系列配置项
|
|
||||||
ij_any_space_before_colon = true
|
ij_any_space_before_colon = true
|
||||||
ij_any_space_after_colon = true
|
ij_any_space_after_colon = true
|
||||||
ij_any_keep_indents_on_empty_lines = false
|
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_semicolon_after_statement = false
|
||||||
ij_javascript_use_double_quotes = false
|
ij_javascript_use_double_quotes = false
|
||||||
ij_javascript_enforce_trailing_comma = keep
|
ij_javascript_enforce_trailing_comma = keep
|
||||||
ij_typescript_use_semicolon_after_statement = false
|
ij_javascript_space_before_method_parentheses = true
|
||||||
ij_typescript_use_double_quotes = false
|
ij_javascript_spaces_within_object_literal_braces = true
|
||||||
ij_typescript_enforce_trailing_comma = keep
|
ij_javascript_indent_chained_calls = true
|
||||||
|
ij_javascript_if_brace_force = if_multiline
|
||||||
|
|
||||||
[*.json]
|
[{*.json,*.json5}]
|
||||||
ij_any_space_before_colon = false
|
|
||||||
ij_json_keep_trailing_comma = false
|
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 os = require('os')
|
||||||
const { existsSync } = require("fs")
|
const { existsSync } = require('fs')
|
||||||
const { execSync } = require("child_process")
|
const { execSync } = require('child_process')
|
||||||
const arch = os.arch()
|
const arch = os.arch()
|
||||||
|
|
||||||
let skipDownload = false
|
let skipDownload = false
|
||||||
let executablePath
|
let executablePath
|
||||||
|
|
||||||
if (process.platform == "linux" || process.platform == "android")
|
if (process.platform === 'linux' || process.platform === 'android')
|
||||||
for (const item of [
|
for (const item of [
|
||||||
"chromium",
|
"chromium",
|
||||||
"chromium-browser",
|
"chromium-browser",
|
||||||
|
@ -19,19 +19,28 @@ if (process.platform == "linux" || process.platform == "android")
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
if (!executablePath) for (const item of [
|
// macOS
|
||||||
"/usr/bin/chromium",
|
if (process.platform === 'darwin') for (const item of [
|
||||||
"/usr/bin/chromium-browser",
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||||
"/usr/bin/chrome",
|
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
||||||
"C:/Program Files/Google/Chrome/Application/chrome.exe",
|
|
||||||
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
|
|
||||||
]) if (existsSync(item)) {
|
]) if (existsSync(item)) {
|
||||||
executablePath = item
|
executablePath = item
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (executablePath || arch == "arm64" || arch == "aarch64") {
|
if (!executablePath) for (const item of [
|
||||||
(typeof logger == "object" ? logger : console).info(`[Chromium] ${executablePath}`)
|
'/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
|
skipDownload = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import path from 'node:path'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送私聊消息,仅给好友发送
|
* 发送私聊消息,仅给好友发送
|
||||||
* @param user_id qq号
|
* @param userId qq号
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
async function relpyPrivate (userId, msg) {
|
async function relpyPrivate (userId, msg) {
|
||||||
|
@ -33,6 +33,7 @@ function sleep(ms) {
|
||||||
* 下载保存文件
|
* 下载保存文件
|
||||||
* @param fileUrl 下载地址
|
* @param fileUrl 下载地址
|
||||||
* @param savePath 保存路径
|
* @param savePath 保存路径
|
||||||
|
* @param param
|
||||||
*/
|
*/
|
||||||
async function downFile (fileUrl, savePath, param = {}) {
|
async function downFile (fileUrl, savePath, param = {}) {
|
||||||
try {
|
try {
|
||||||
|
@ -68,7 +69,9 @@ function mkdirs(dirname) {
|
||||||
*/
|
*/
|
||||||
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 name = msgsscr ? e.sender.card || e.user_id : Bot.nickname
|
||||||
let id = msgsscr ? e.user_id : Bot.uin
|
let id = msgsscr ? e.user_id : Bot.uin
|
||||||
|
@ -85,14 +88,15 @@ async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) {
|
||||||
|
|
||||||
let forwardMsg = []
|
let forwardMsg = []
|
||||||
for (const message of msg) {
|
for (const message of msg) {
|
||||||
if(!message) continue
|
if (!message) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
forwardMsg.push({
|
forwardMsg.push({
|
||||||
...userInfo,
|
...userInfo,
|
||||||
message: message
|
message: message
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** 制作转发内容 */
|
/** 制作转发内容 */
|
||||||
if (e?.group?.makeForwardMsg) {
|
if (e?.group?.makeForwardMsg) {
|
||||||
forwardMsg = await e.group.makeForwardMsg(forwardMsg)
|
forwardMsg = await e.group.makeForwardMsg(forwardMsg)
|
||||||
|
|
|
@ -25,4 +25,3 @@ export default {
|
||||||
return ret.length > 0 ? ret : false
|
return ret.length > 0 ? ret : false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,4 +37,3 @@ export default {
|
||||||
return rendererBackends[cfg.renderer?.name || 'puppeteer']
|
return rendererBackends[cfg.renderer?.name || 'puppeteer']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import '../config/init.js'
|
import '../config/init.js'
|
||||||
import log4js from 'log4js'
|
import log4js from 'log4js'
|
||||||
import PluginsLoader from '../plugins/loader.js'
|
import PluginsLoader from '../plugins/loader.js'
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default class PuppeteerRenderer {
|
||||||
/** 截图次数 */
|
/** 截图次数 */
|
||||||
this.renderNum = 0
|
this.renderNum = 0
|
||||||
this.config = {
|
this.config = {
|
||||||
headless: Data.def(config.headless, "new"),
|
headless: Data.def(config.headless, 'new'),
|
||||||
args: Data.def(config.args, [
|
args: Data.def(config.args, [
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
'--disable-setuid-sandbox',
|
'--disable-setuid-sandbox',
|
||||||
|
@ -144,11 +144,15 @@ export default class PuppeteerRenderer {
|
||||||
const mac = '00:00:00:00:00:00'
|
const mac = '00:00:00:00:00:00'
|
||||||
try {
|
try {
|
||||||
const network = os.networkInterfaces()
|
const network = os.networkInterfaces()
|
||||||
for (const a in network)
|
for (const a in network) {
|
||||||
for (const i of network[a])
|
for (const i of network[a]) {
|
||||||
if (i.mac && i.mac != mac)
|
if (i.mac && i.mac != mac) {
|
||||||
return i.mac
|
return i.mac
|
||||||
} catch (e) {}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
return mac
|
return mac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +177,9 @@ export default class PuppeteerRenderer {
|
||||||
const pageHeight = data.multiPageHeight || 4000
|
const pageHeight = data.multiPageHeight || 4000
|
||||||
|
|
||||||
let savePath = this.dealTpl(name, data)
|
let savePath = this.dealTpl(name, data)
|
||||||
if (!savePath) return false
|
if (!savePath) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
let buff = ''
|
let buff = ''
|
||||||
let start = Date.now()
|
let start = Date.now()
|
||||||
|
@ -238,7 +244,9 @@ export default class PuppeteerRenderer {
|
||||||
} else {
|
} else {
|
||||||
buff = await page.screenshot(randData)
|
buff = await page.screenshot(randData)
|
||||||
}
|
}
|
||||||
if (num > 2) await Data.sleep(200)
|
if (num > 2) {
|
||||||
|
await Data.sleep(200)
|
||||||
|
}
|
||||||
this.renderNum++
|
this.renderNum++
|
||||||
|
|
||||||
/** 计算图片大小 */
|
/** 计算图片大小 */
|
||||||
|
@ -251,7 +259,6 @@ export default class PuppeteerRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page.close().catch((err) => logger.error(err))
|
page.close().catch((err) => logger.error(err))
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[图片生成][${name}] 图片生成失败:${error}`)
|
logger.error(`[图片生成][${name}] 图片生成失败:${error}`)
|
||||||
/** 关闭浏览器 */
|
/** 关闭浏览器 */
|
||||||
|
|
Loading…
Reference in New Issue