mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🐞 fix: V1.5.5 [#I96AOZ]修复插件更新后配置文件会重置 & 解决xhs无法解析视频的bug
1. 解决xhs无法解析视频的bug(感谢群友Melatonin提供bug例子) 2. [#I96AOZ] beta: 修复插件更新后配置文件会重置
This commit is contained in:
parent
073ff99395
commit
1dd533b9fb
@ -676,7 +676,7 @@ export class tools extends plugin {
|
|||||||
const reg = /window\.__INITIAL_STATE__=(.*?)<\/script>/;
|
const reg = /window\.__INITIAL_STATE__=(.*?)<\/script>/;
|
||||||
const res = xhsHtml.match(reg)[1].replace(/undefined/g, "null");
|
const res = xhsHtml.match(reg)[1].replace(/undefined/g, "null");
|
||||||
const resJson = JSON.parse(res);
|
const resJson = JSON.parse(res);
|
||||||
const noteData = resJson.note.noteDetailMap[id].note
|
const noteData = resJson.note.noteDetailMap[id].note;
|
||||||
const { title, desc, type } = noteData;
|
const { title, desc, type } = noteData;
|
||||||
let imgPromise = [];
|
let imgPromise = [];
|
||||||
if (type === "video") {
|
if (type === "video") {
|
||||||
@ -684,7 +684,7 @@ export class tools extends plugin {
|
|||||||
const cover = noteData.imageList?.[0].urlDefault;
|
const cover = noteData.imageList?.[0].urlDefault;
|
||||||
e.reply([segment.image(cover), `识别:小红书, ${ title }\n${ desc }`]);
|
e.reply([segment.image(cover), `识别:小红书, ${ title }\n${ desc }`]);
|
||||||
// 构造xhs视频链接
|
// 构造xhs视频链接
|
||||||
const xhsVideoUrl = `${ XHS_VIDEO }${ noteData.video.consumer.originVideoKey.replace('pre_post\/', '') }`;
|
const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl;
|
||||||
// 下载视频
|
// 下载视频
|
||||||
this.downloadVideo(xhsVideoUrl).then(path => {
|
this.downloadVideo(xhsVideoUrl).then(path => {
|
||||||
if (path === undefined) {
|
if (path === undefined) {
|
||||||
|
@ -3,8 +3,10 @@ import Version from "../model/version.js";
|
|||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
||||||
import lodash from "lodash";
|
import lodash from "lodash";
|
||||||
|
import YAML from "yaml";
|
||||||
|
|
||||||
import { exec, execSync } from "node:child_process";
|
import { exec, execSync } from "node:child_process";
|
||||||
|
import { copyFiles, deleteFolderRecursive, readCurrentDir } from "../utils/file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理插件更新1
|
* 处理插件更新1
|
||||||
@ -57,6 +59,9 @@ export class update extends plugin {
|
|||||||
|
|
||||||
const pluginName = "rconsole-plugin";
|
const pluginName = "rconsole-plugin";
|
||||||
|
|
||||||
|
// 保存配置文件
|
||||||
|
await copyFiles(`./plugins/${pluginName}/config`, "./temp/rconsole-update-tmp");
|
||||||
|
|
||||||
let command = `git -C ./plugins/${pluginName}/ pull --no-rebase`;
|
let command = `git -C ./plugins/${pluginName}/ pull --no-rebase`;
|
||||||
if (isForce) {
|
if (isForce) {
|
||||||
command = `git -C ./plugins/${pluginName}/ checkout . && ${command}`;
|
command = `git -C ./plugins/${pluginName}/ checkout . && ${command}`;
|
||||||
@ -78,6 +83,18 @@ export class update extends plugin {
|
|||||||
e.reply(`R插件更新成功,最后更新时间:${time}`);
|
e.reply(`R插件更新成功,最后更新时间:${time}`);
|
||||||
e.reply(await this.getLog(pluginName));
|
e.reply(await this.getLog(pluginName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 读取配置文件比对更新
|
||||||
|
const confFiles = await readCurrentDir("./temp/rconsole-update-tmp");
|
||||||
|
for (let confFile of confFiles) {
|
||||||
|
await this.compareAndUpdateYaml(
|
||||||
|
`./temp/rconsole-update-tmp/${confFile}`,
|
||||||
|
`./plugins/${pluginName}/config/${confFile}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// 删除临时文件
|
||||||
|
await deleteFolderRecursive("./temp/rconsole-update-tmp");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,8 +165,8 @@ export class update extends plugin {
|
|||||||
} else if (errMsg.includes("be overwritten by merge")) {
|
} else if (errMsg.includes("be overwritten by merge")) {
|
||||||
await this.reply(
|
await this.reply(
|
||||||
msg +
|
msg +
|
||||||
`存在冲突:\n${errMsg}\n` +
|
`存在冲突:\n${errMsg}\n` +
|
||||||
"请解决冲突后再更新,或者执行#强制更新,放弃本地修改",
|
"请解决冲突后再更新,或者执行#强制更新,放弃本地修改",
|
||||||
);
|
);
|
||||||
} else if (stdout.includes("CONFLICT")) {
|
} else if (stdout.includes("CONFLICT")) {
|
||||||
await this.reply([
|
await this.reply([
|
||||||
@ -162,4 +179,37 @@ export class update extends plugin {
|
|||||||
await this.reply([errMsg, stdout]);
|
await this.reply([errMsg, stdout]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async compareAndUpdateYaml(sourcePath, updatedPath) {
|
||||||
|
try {
|
||||||
|
// Step 1 & 2: Read and parse YAML files
|
||||||
|
const sourceContent = await fs.readFileSync(sourcePath, 'utf8');
|
||||||
|
const updatedContent = await fs.readFileSync(updatedPath, 'utf8');
|
||||||
|
const sourceObj = YAML.parse(sourceContent);
|
||||||
|
const updatedObj = YAML.parse(updatedContent);
|
||||||
|
|
||||||
|
// Step 3: Compare objects and merge changes
|
||||||
|
Object.keys(updatedObj).forEach(key => {
|
||||||
|
if (!sourceObj.hasOwnProperty(key)) {
|
||||||
|
sourceObj[key] = updatedObj[key]; // Add new keys with updated values
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.keys(sourceObj).forEach(key => {
|
||||||
|
if (!updatedObj.hasOwnProperty(key)) {
|
||||||
|
delete sourceObj[key]; // Remove keys not present in updated object
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Step 4 & 5: Convert object back to YAML
|
||||||
|
const newYamlContent = YAML.stringify(sourceObj);
|
||||||
|
|
||||||
|
// Step 6: Write the updated YAML back to the updatedPath
|
||||||
|
await fs.writeFileSync(updatedPath, newYamlContent, 'utf8');
|
||||||
|
|
||||||
|
logger.info(`[R插件更新配置文件记录]${updatedPath}`);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
- {
|
- {
|
||||||
version: 1.5.4,
|
version: 1.5.5,
|
||||||
data:
|
data:
|
||||||
[
|
[
|
||||||
新增<span class="cmd">Pixivision解析</span>功能,
|
新增<span class="cmd">Pixivision解析</span>功能,
|
||||||
|
@ -77,4 +77,27 @@ export async function readCurrentDir(path) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拷贝文件
|
||||||
|
* @param srcDir
|
||||||
|
* @param destDir
|
||||||
|
* @returns {Promise<*|null>}
|
||||||
|
*/
|
||||||
|
export async function copyFiles(srcDir, destDir) {
|
||||||
|
try {
|
||||||
|
await mkdirIfNotExists(destDir);
|
||||||
|
|
||||||
|
const files = await readCurrentDir(srcDir);
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const srcFile = path.join(srcDir, file);
|
||||||
|
const destFile = path.join(destDir, file);
|
||||||
|
await fs.promises.copyFile(srcFile, destFile);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user