wiki-plugin-linkitylink 0.0.7 → 0.0.9
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/client/linkitylink.js +123 -0
- package/package.json +2 -3
- package/server/server.js +60 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
window.plugins.linkitylink = {
|
|
4
|
+
emit: function($item, item) {
|
|
5
|
+
const div = $item[0];
|
|
6
|
+
div.innerHTML = '<p style="background-color:#eee;padding:15px;">Loading Linkitylink status...</p>';
|
|
7
|
+
|
|
8
|
+
// Fetch version status
|
|
9
|
+
fetch('/plugin/linkitylink/version-status')
|
|
10
|
+
.then(res => res.json())
|
|
11
|
+
.then(data => {
|
|
12
|
+
div.innerHTML = renderVersionStatus(data);
|
|
13
|
+
|
|
14
|
+
// Add click handler for update button
|
|
15
|
+
const updateBtn = div.querySelector('.linkitylink-update-btn');
|
|
16
|
+
if (updateBtn) {
|
|
17
|
+
updateBtn.addEventListener('click', () => updateLinkitylink(div));
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
.catch(err => {
|
|
21
|
+
div.innerHTML = `<p style="background-color:#fee;padding:15px;">❌ Error loading Linkitylink status: ${err.message}</p>`;
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
bind: function($item, item) {
|
|
26
|
+
// Nothing to bind
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function renderVersionStatus(data) {
|
|
31
|
+
const { installed, published, updateAvailable } = data;
|
|
32
|
+
|
|
33
|
+
// Plugmatic-style colors
|
|
34
|
+
const color = {
|
|
35
|
+
gray: '#ccc',
|
|
36
|
+
red: '#f55',
|
|
37
|
+
yellow: '#fb0',
|
|
38
|
+
green: '#0e0',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Determine status color (matching plugmatic)
|
|
42
|
+
let statusColor, statusText;
|
|
43
|
+
if (!installed) {
|
|
44
|
+
statusColor = color.red;
|
|
45
|
+
statusText = 'Not installed';
|
|
46
|
+
} else if (updateAvailable) {
|
|
47
|
+
statusColor = color.yellow;
|
|
48
|
+
statusText = 'Update available';
|
|
49
|
+
} else {
|
|
50
|
+
statusColor = color.green;
|
|
51
|
+
statusText = 'Up to date';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let html = `
|
|
55
|
+
<div style="border: 2px solid ${statusColor}; padding: 15px; border-radius: 8px; background-color: #fafafa;">
|
|
56
|
+
<h3 style="margin-top: 0;">
|
|
57
|
+
<span style="color: ${statusColor}; font-size: 20px;">◉</span> Linkitylink Service ${statusText}
|
|
58
|
+
</h3>
|
|
59
|
+
<table style="width: 100%; border-collapse: collapse;">
|
|
60
|
+
<tr>
|
|
61
|
+
<td style="padding: 8px; border-bottom: 1px solid #ddd;"><strong>Installed Version:</strong></td>
|
|
62
|
+
<td style="padding: 8px; border-bottom: 1px solid #ddd;">${installed || 'Not installed'}</td>
|
|
63
|
+
</tr>
|
|
64
|
+
<tr>
|
|
65
|
+
<td style="padding: 8px; border-bottom: 1px solid #ddd;"><strong>Latest Version:</strong></td>
|
|
66
|
+
<td style="padding: 8px; border-bottom: 1px solid #ddd;">${published || 'Unknown'}</td>
|
|
67
|
+
</tr>
|
|
68
|
+
</table>
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
if (updateAvailable) {
|
|
72
|
+
html += `
|
|
73
|
+
<button class="linkitylink-update-btn" style="
|
|
74
|
+
margin-top: 15px;
|
|
75
|
+
padding: 10px 20px;
|
|
76
|
+
background-color: #2196F3;
|
|
77
|
+
color: white;
|
|
78
|
+
border: none;
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
">
|
|
83
|
+
⬆️ Update to ${published}
|
|
84
|
+
</button>
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
html += `</div>`;
|
|
89
|
+
return html;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function updateLinkitylink(div) {
|
|
93
|
+
div.innerHTML = '<p style="background-color:#fef3cd;padding:15px;">⏳ Updating Linkitylink service...</p>';
|
|
94
|
+
|
|
95
|
+
fetch('/plugin/linkitylink/update', { method: 'POST' })
|
|
96
|
+
.then(res => res.json())
|
|
97
|
+
.then(data => {
|
|
98
|
+
if (data.success) {
|
|
99
|
+
div.innerHTML = `
|
|
100
|
+
<div style="background-color:#d4edda;padding:15px;border-radius:4px;color:#155724;">
|
|
101
|
+
✅ Linkitylink updated successfully to version ${data.version}!
|
|
102
|
+
<br><br>
|
|
103
|
+
<em>Please restart your wiki server for changes to take effect.</em>
|
|
104
|
+
</div>
|
|
105
|
+
`;
|
|
106
|
+
} else {
|
|
107
|
+
div.innerHTML = `
|
|
108
|
+
<div style="background-color:#f8d7da;padding:15px;border-radius:4px;color:#721c24;">
|
|
109
|
+
❌ Update failed: ${data.error}
|
|
110
|
+
</div>
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
.catch(err => {
|
|
115
|
+
div.innerHTML = `
|
|
116
|
+
<div style="background-color:#f8d7da;padding:15px;border-radius:4px;color:#721c24;">
|
|
117
|
+
❌ Update error: ${err.message}
|
|
118
|
+
</div>
|
|
119
|
+
`;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-linkitylink",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Linkitylink integration plugin for federated wiki",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wiki",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
"type": "commonjs",
|
|
22
22
|
"main": "index.js",
|
|
23
23
|
"scripts": {
|
|
24
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
|
-
"postinstall": "npm install linkitylink@latest"
|
|
24
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
27
|
"linkitylink": "latest",
|
package/server/server.js
CHANGED
|
@@ -238,7 +238,66 @@ async function startServer(params) {
|
|
|
238
238
|
}
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
//
|
|
241
|
+
// Version status endpoint
|
|
242
|
+
app.get('/plugin/linkitylink/version-status', async function(req, res) {
|
|
243
|
+
try {
|
|
244
|
+
const linkitylinkPackagePath = path.join(LINKITYLINK_PATH, 'package.json');
|
|
245
|
+
let installed = null;
|
|
246
|
+
|
|
247
|
+
if (fs.existsSync(linkitylinkPackagePath)) {
|
|
248
|
+
const packageData = JSON.parse(fs.readFileSync(linkitylinkPackagePath, 'utf8'));
|
|
249
|
+
installed = packageData.version;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Fetch latest version from npm
|
|
253
|
+
const npmResponse = await fetch('https://registry.npmjs.org/linkitylink/latest');
|
|
254
|
+
const npmData = await npmResponse.json();
|
|
255
|
+
const published = npmData.version;
|
|
256
|
+
|
|
257
|
+
const updateAvailable = installed && published && installed !== published;
|
|
258
|
+
|
|
259
|
+
res.json({
|
|
260
|
+
installed,
|
|
261
|
+
published,
|
|
262
|
+
updateAvailable
|
|
263
|
+
});
|
|
264
|
+
} catch (err) {
|
|
265
|
+
console.error('[wiki-plugin-linkitylink] Error checking version:', err);
|
|
266
|
+
res.status(500).json({ error: err.message });
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Update endpoint
|
|
271
|
+
app.post('/plugin/linkitylink/update', function(req, res) {
|
|
272
|
+
const { exec } = require('child_process');
|
|
273
|
+
|
|
274
|
+
console.log('[wiki-plugin-linkitylink] Updating linkitylink to latest version...');
|
|
275
|
+
|
|
276
|
+
// Run npm install linkitylink@latest in the plugin directory
|
|
277
|
+
exec('npm install linkitylink@latest', { cwd: path.join(__dirname, '..') }, (err, stdout, stderr) => {
|
|
278
|
+
if (err) {
|
|
279
|
+
console.error('[wiki-plugin-linkitylink] Update failed:', stderr);
|
|
280
|
+
return res.json({ success: false, error: stderr || err.message });
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
console.log('[wiki-plugin-linkitylink] Update output:', stdout);
|
|
284
|
+
|
|
285
|
+
// Try to get the new version
|
|
286
|
+
try {
|
|
287
|
+
const linkitylinkPackagePath = path.join(LINKITYLINK_PATH, 'package.json');
|
|
288
|
+
const packageData = JSON.parse(fs.readFileSync(linkitylinkPackagePath, 'utf8'));
|
|
289
|
+
const newVersion = packageData.version;
|
|
290
|
+
|
|
291
|
+
console.log(`[wiki-plugin-linkitylink] ✅ Updated to version ${newVersion}`);
|
|
292
|
+
res.json({ success: true, version: newVersion });
|
|
293
|
+
} catch (readErr) {
|
|
294
|
+
console.log('[wiki-plugin-linkitylink] ✅ Update completed');
|
|
295
|
+
res.json({ success: true, version: 'unknown' });
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Proxy all OTHER linkitylink routes
|
|
242
301
|
// Maps /plugin/linkitylink/* -> http://localhost:3010/*
|
|
243
302
|
app.all('/plugin/linkitylink/*', function(req, res) {
|
|
244
303
|
// Remove /plugin/linkitylink prefix
|