koishi-plugin-rocom 1.0.6 → 1.0.8
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/LICENSE +661 -0
- package/lib/client.d.ts +4 -0
- package/lib/client.js +56 -1
- package/lib/commands/account.d.ts +1 -1
- package/lib/commands/account.js +42 -7
- package/lib/commands/merchant.js +1 -1
- package/lib/commands/query.js +648 -14
- package/lib/render-templates/pet-panel/index.html +61 -0
- package/lib/render-templates/pet-panel/style.css +183 -0
- package/lib/render-templates/pet-panel-detail/index.html +123 -0
- package/lib/render-templates/pet-panel-detail/style.css +258 -0
- package/lib/render.d.ts +3 -3
- package/lib/render.js +33 -14
- package/package.json +1 -1
- package/readme.md +51 -519
package/lib/render.js
CHANGED
|
@@ -60,36 +60,53 @@ class Renderer {
|
|
|
60
60
|
this.resPath = resPath;
|
|
61
61
|
}
|
|
62
62
|
resourceUrl(relativePath) {
|
|
63
|
-
return (0, node_url_1.pathToFileURL)(node_path_1.default.join(this.
|
|
63
|
+
return (0, node_url_1.pathToFileURL)(node_path_1.default.join(this.getPreferredResourceRoot(), relativePath)).href;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
getPreferredResourceRoot() {
|
|
66
66
|
const builtRoot = node_path_1.default.join(this.resPath, 'lib');
|
|
67
67
|
if (node_fs_1.default.existsSync(node_path_1.default.join(builtRoot, 'render-templates')))
|
|
68
68
|
return builtRoot;
|
|
69
69
|
return node_path_1.default.join(this.resPath, 'src');
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
getTemplateCandidateRoots() {
|
|
72
|
+
const roots = [
|
|
73
|
+
node_path_1.default.join(this.resPath, 'lib'),
|
|
74
|
+
node_path_1.default.join(this.resPath, 'src'),
|
|
75
|
+
];
|
|
76
|
+
return Array.from(new Set(roots));
|
|
73
77
|
}
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
resolveTemplatePath(templateName) {
|
|
79
|
+
for (const root of this.getTemplateCandidateRoots()) {
|
|
80
|
+
const templateRoot = node_path_1.default.join(root, 'render-templates');
|
|
81
|
+
const directHtmlPath = node_path_1.default.join(templateRoot, `${templateName}.html`);
|
|
82
|
+
if (node_fs_1.default.existsSync(directHtmlPath)) {
|
|
83
|
+
return { templatePath: directHtmlPath, resourceRoot: root };
|
|
84
|
+
}
|
|
85
|
+
const indexHtmlPath = node_path_1.default.join(templateRoot, templateName, 'index.html');
|
|
86
|
+
if (node_fs_1.default.existsSync(indexHtmlPath)) {
|
|
87
|
+
return { templatePath: indexHtmlPath, resourceRoot: root };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
79
91
|
}
|
|
80
92
|
getStylePath(templateName) {
|
|
81
|
-
|
|
93
|
+
const resolved = this.resolveTemplatePath(templateName);
|
|
94
|
+
if (!resolved)
|
|
95
|
+
return '';
|
|
96
|
+
return node_path_1.default.join(resolved.resourceRoot, 'render-templates', templateName, 'style.css');
|
|
82
97
|
}
|
|
83
98
|
async renderHtml(ctx, templateName, data) {
|
|
84
99
|
try {
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
87
|
-
|
|
100
|
+
const resolvedTemplate = this.resolveTemplatePath(templateName);
|
|
101
|
+
if (!resolvedTemplate) {
|
|
102
|
+
const checked = this.getTemplateCandidateRoots().map(root => node_path_1.default.join(root, 'render-templates', templateName));
|
|
103
|
+
logger.error(`template file missing: ${checked.join(' | ')}`);
|
|
88
104
|
return null;
|
|
89
105
|
}
|
|
106
|
+
const { templatePath, resourceRoot } = resolvedTemplate;
|
|
90
107
|
const templateContent = node_fs_1.default.readFileSync(templatePath, 'utf-8');
|
|
91
108
|
const normalizedTemplateContent = normalizeTemplateResourcePaths(templateContent);
|
|
92
|
-
const resPathUrl = toDirectoryFileUrl(
|
|
109
|
+
const resPathUrl = toDirectoryFileUrl(resourceRoot);
|
|
93
110
|
const renderData = { ...data, _res_path: resPathUrl, pluResPath: resPathUrl };
|
|
94
111
|
const html = template.render(normalizedTemplateContent, renderData);
|
|
95
112
|
if (!ctx.puppeteer?.page) {
|
|
@@ -153,6 +170,8 @@ class Renderer {
|
|
|
153
170
|
'.student-page',
|
|
154
171
|
'.merchant-page',
|
|
155
172
|
'.home-page',
|
|
173
|
+
'.pet-panel-page',
|
|
174
|
+
'.pet-detail-page',
|
|
156
175
|
];
|
|
157
176
|
let target = null;
|
|
158
177
|
for (const selector of selectors) {
|