karin-plugin-qgroup-file2openlist 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/apps/help.js CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ ensurePluginResources
3
+ } from "../chunk-QB3GSENE.js";
1
4
  import {
2
5
  dir
3
6
  } from "../chunk-IZS467MR.js";
@@ -21,6 +24,7 @@ var formatDateTime = (date) => {
21
24
  };
22
25
  var helpImage = karin.command(/^#?(群文件帮助|同步群文件帮助|openlist帮助)$/i, async (e) => {
23
26
  try {
27
+ await ensurePluginResources();
24
28
  const html = path.join(dir.defResourcesDir, "template", "help.html");
25
29
  const img = await render.render({
26
30
  name: "qgroup-help",
@@ -1,3 +1,6 @@
1
+ import {
2
+ ensurePluginResources
3
+ } from "../chunk-QB3GSENE.js";
1
4
  import {
2
5
  config
3
6
  } from "../chunk-5WVKHIPK.js";
@@ -9,6 +12,7 @@ import {
9
12
  import { karin, render, segment, logger } from "node-karin";
10
13
  var image = karin.command(/^#?测试渲染$/, async (e) => {
11
14
  try {
15
+ await ensurePluginResources();
12
16
  const html = dir.defResourcesDir + "/template/test.html";
13
17
  const image2 = dir.defResourcesDir + "/image/\u542F\u7A0B\u5BA3\u53D1.png";
14
18
  const img = await render.render({
@@ -43,6 +47,7 @@ var image = karin.command(/^#?测试渲染$/, async (e) => {
43
47
  var renderUrl = karin.command(/^#?渲染/, async (e) => {
44
48
  const file = e.msg.replace(/^#?渲染/, "").trim();
45
49
  try {
50
+ await ensurePluginResources();
46
51
  const img = await render.render({
47
52
  name: "render",
48
53
  encoding: "base64",
@@ -0,0 +1,36 @@
1
+ import {
2
+ dir
3
+ } from "./chunk-IZS467MR.js";
4
+
5
+ // src/utils/resources.ts
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import { createPluginDir, getAllFilesSync } from "node-karin";
9
+ var ensurePromise = null;
10
+ var ensurePluginResources = async () => {
11
+ if (ensurePromise) return ensurePromise;
12
+ ensurePromise = (async () => {
13
+ const sourceDir = path.join(dir.pluginDir, "resources");
14
+ const targetDir = dir.defResourcesDir;
15
+ if (!fs.existsSync(sourceDir)) return;
16
+ await createPluginDir(dir.name, ["resources"]);
17
+ const files = getAllFilesSync(sourceDir, { returnType: "rel" });
18
+ for (const rel of files) {
19
+ const normalizedRel = rel.replaceAll("\\", "/");
20
+ const shouldOverwrite = normalizedRel.startsWith("template/");
21
+ const sourcePath = path.join(sourceDir, rel);
22
+ const targetPath = path.join(targetDir, rel);
23
+ if (fs.existsSync(targetPath) && !shouldOverwrite) continue;
24
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
25
+ fs.copyFileSync(sourcePath, targetPath);
26
+ }
27
+ })().catch((error) => {
28
+ ensurePromise = null;
29
+ throw error;
30
+ });
31
+ return ensurePromise;
32
+ };
33
+
34
+ export {
35
+ ensurePluginResources
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karin-plugin-qgroup-file2openlist",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "author": "429",
5
5
  "type": "module",
6
6
  "description": "karin plugin for QGroupFile backup",