wiki-server 0.19.2 → 0.20.1
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/AUTHORS.txt +2 -0
- package/lib/defaultargs.coffee +1 -1
- package/lib/search.coffee +5 -5
- package/lib/server.coffee +31 -33
- package/lib/sitemap.coffee +3 -0
- package/package.json +4 -3
package/AUTHORS.txt
CHANGED
package/lib/defaultargs.coffee
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = (argv) ->
|
|
|
28
28
|
argv.status or= path.join(argv.data, 'status')
|
|
29
29
|
argv.assets or= path.join(argv.data, 'assets')
|
|
30
30
|
argv.recycler or= path.join(argv.data, 'recycle')
|
|
31
|
-
argv.url or= 'http://localhost' + (':' + argv.port)
|
|
31
|
+
argv.url or= 'http://localhost' + (if argv.port is 80 then '' else ':' + argv.port)
|
|
32
32
|
argv.id or= path.join(argv.status, 'owner.json')
|
|
33
33
|
argv.uploadLimit or= '5mb'
|
|
34
34
|
argv.cookieSecret or= require('crypto').randomBytes(64).toString('hex')
|
package/lib/search.coffee
CHANGED
|
@@ -165,18 +165,18 @@ module.exports = exports = (argv) ->
|
|
|
165
165
|
try
|
|
166
166
|
switch currentItem.type
|
|
167
167
|
when 'paragraph'
|
|
168
|
-
pageText += ' ' + currentItem.text.replace /\[{
|
|
168
|
+
pageText += ' ' + currentItem.text.replace /\[{2}|\[(?:[\S]+)|\]{1,2}/g, ''
|
|
169
169
|
when 'markdown'
|
|
170
|
-
# really need to extract text from the markdown, but for now just remove link brackets...
|
|
171
|
-
pageText += ' ' + currentItem.text.replace /\[{
|
|
170
|
+
# really need to extract text from the markdown, but for now just remove link brackets, urls...
|
|
171
|
+
pageText += ' ' + currentItem.text.replace /\[{2}|\[(?:[\S]+)|\]{1,2}/g, ''
|
|
172
172
|
when 'html'
|
|
173
173
|
pageText += ' ' + currentItem.text.replace /<[^>]*>/g, ''
|
|
174
174
|
else
|
|
175
175
|
if currentItem.text?
|
|
176
176
|
for line in currentItem.text.split /\r\n?|\n/
|
|
177
|
-
pageText += ' ' + line.replace /\[{
|
|
177
|
+
pageText += ' ' + line.replace /\[{2}|\[(?:[\S]+)|\]{1,2}/g, '' unless line.match /^[A-Z]+[ ].*/
|
|
178
178
|
catch err
|
|
179
|
-
|
|
179
|
+
throw new Error("Error extracting text from #{currentIndex}")
|
|
180
180
|
pageText
|
|
181
181
|
|
|
182
182
|
|
package/lib/server.coffee
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
fs = require 'fs'
|
|
23
23
|
path = require 'path'
|
|
24
24
|
http = require 'http'
|
|
25
|
+
url = require 'url'
|
|
25
26
|
|
|
26
27
|
# From npm
|
|
27
28
|
mkdirp = require 'mkdirp'
|
|
@@ -31,6 +32,7 @@ glob = require 'glob'
|
|
|
31
32
|
async = require 'async'
|
|
32
33
|
f = require('flates')
|
|
33
34
|
sanitize = require '@mapbox/sanitize-caja'
|
|
35
|
+
fetch = require 'node-fetch'
|
|
34
36
|
|
|
35
37
|
# Express 4 middleware
|
|
36
38
|
logger = require 'morgan'
|
|
@@ -139,33 +141,24 @@ module.exports = exports = (argv) ->
|
|
|
139
141
|
|
|
140
142
|
|
|
141
143
|
remoteGet = (remote, slug, cb) ->
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
cb(null, 'Page not found', 404)
|
|
161
|
-
else if responsedata
|
|
162
|
-
cb(null, JSON.parse(responsedata), resp.statusCode)
|
|
163
|
-
else
|
|
164
|
-
cb(null, 'Page not found', 404)
|
|
165
|
-
|
|
166
|
-
).on 'error', (e) ->
|
|
167
|
-
cb(e, 'Page not found', 404)
|
|
168
|
-
|
|
144
|
+
# assume http, as we know no better at this point and we need to specify a protocol.
|
|
145
|
+
remoteURL = new URL("http://#{remote}/#{slug}.json").toString()
|
|
146
|
+
# set a two second timeout
|
|
147
|
+
fetch(remoteURL, {timeout: 2000})
|
|
148
|
+
.then (res) ->
|
|
149
|
+
if res.ok
|
|
150
|
+
return res
|
|
151
|
+
throw new Error(res.statusText)
|
|
152
|
+
.then (res) ->
|
|
153
|
+
return res.json()
|
|
154
|
+
.then (json) ->
|
|
155
|
+
cb(null, json, 200)
|
|
156
|
+
.catch (err) ->
|
|
157
|
+
console.error('Unable to fetch remote resource', remote, slug, err)
|
|
158
|
+
cb(err, 'Page not found', 404)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
169
162
|
#### Express configuration ####
|
|
170
163
|
# Set up all the standard express server options,
|
|
171
164
|
# including hbs to use handlebars/mustache templates
|
|
@@ -233,7 +226,7 @@ module.exports = exports = (argv) ->
|
|
|
233
226
|
plugins.map (plugin) ->
|
|
234
227
|
pluginName = plugin.slice(12, -7)
|
|
235
228
|
pluginPath = '/plugins/' + pluginName
|
|
236
|
-
app.use(pluginPath, express.static(path.join(argv.packageDir, plugin), staticPathOptions))
|
|
229
|
+
app.use(pluginPath, cors, express.static(path.join(argv.packageDir, plugin), staticPathOptions))
|
|
237
230
|
|
|
238
231
|
# Add static routes to the security client.
|
|
239
232
|
if argv.security != './security'
|
|
@@ -453,20 +446,24 @@ module.exports = exports = (argv) ->
|
|
|
453
446
|
# Send an array of pages currently in the recycler via json
|
|
454
447
|
app.get '/recycler/system/slugs.json', authorized, (req, res) ->
|
|
455
448
|
fs.readdir argv.recycler, (e, files) ->
|
|
456
|
-
|
|
449
|
+
|
|
457
450
|
doRecyclermap = (file, cb) ->
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if e
|
|
451
|
+
recycleFile = 'recycler/' + file
|
|
452
|
+
pagehandler.get recycleFile, (e, page, status) ->
|
|
453
|
+
if e or status is 404
|
|
461
454
|
console.log 'Problem building recycler map:', file, 'e: ',e
|
|
455
|
+
# this will leave an undefined/empty item in the array, which we will filter out later
|
|
462
456
|
return cb()
|
|
463
457
|
cb null, {
|
|
464
458
|
slug: file
|
|
465
459
|
title: page.title
|
|
466
460
|
}
|
|
467
461
|
|
|
462
|
+
if e then return res.e e
|
|
468
463
|
async.map files, doRecyclermap, (e, recyclermap) ->
|
|
469
464
|
return cb(e) if e
|
|
465
|
+
# remove any empty items
|
|
466
|
+
recyclermap = recyclermap.filter( (el) -> return !!el )
|
|
470
467
|
res.send(recyclermap)
|
|
471
468
|
|
|
472
469
|
# Fetching page from the recycler
|
|
@@ -678,7 +675,8 @@ module.exports = exports = (argv) ->
|
|
|
678
675
|
# otherwise ask pagehandler for it.
|
|
679
676
|
if action.fork
|
|
680
677
|
pagehandler.saveToRecycler req.params[0], (err) ->
|
|
681
|
-
if err
|
|
678
|
+
if err and err isnt 'page does not exist'
|
|
679
|
+
console.log "Error saving #{req.params[0]} before fork: #{err}"
|
|
682
680
|
remoteGet(action.fork, req.params[0], actionCB)
|
|
683
681
|
else if action.type is 'create'
|
|
684
682
|
# Prevent attempt to write circular structure
|
package/lib/sitemap.coffee
CHANGED
|
@@ -58,6 +58,9 @@ module.exports = exports = (argv) ->
|
|
|
58
58
|
while (match = linkRe.exec(currentItem.text)) != null
|
|
59
59
|
if not collaborativeLinks.has(asSlug(match[1]))
|
|
60
60
|
collaborativeLinks.set(asSlug(match[1]), currentItem.id)
|
|
61
|
+
if 'reference' == currentItem.type
|
|
62
|
+
if not collaborativeLinks.has(currentItem.slug)
|
|
63
|
+
collaborativeLinks.set(currentItem.slug, currentItem.id)
|
|
61
64
|
catch err
|
|
62
65
|
console.log "METADATA *** #{wikiName} Error extracting links from #{currentIndex} of #{JSON.stringify(array)}", err.message
|
|
63
66
|
collaborativeLinks
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-server",
|
|
3
3
|
"description": "A Federated Wiki Server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ward Cunningham",
|
|
7
7
|
"email": "ward@c2.com",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"minisearch": "^2.1.3",
|
|
37
37
|
"mkdirp": "^0.5.5",
|
|
38
38
|
"morgan": "^1.9.1",
|
|
39
|
+
"node-fetch": "^2.6.1",
|
|
39
40
|
"request": "^2.88.0",
|
|
40
41
|
"write-file-atomic": "^2.4.3",
|
|
41
42
|
"xml2js": "^0.4.23"
|
|
@@ -52,12 +53,12 @@
|
|
|
52
53
|
"mocha": "^8.0.1",
|
|
53
54
|
"should": "^13.2.3",
|
|
54
55
|
"supertest": "^4.0.2",
|
|
55
|
-
"wiki-client": "^0.
|
|
56
|
+
"wiki-client": "^0.23.0",
|
|
56
57
|
"wiki-plugin-activity": "^0.4.6",
|
|
57
58
|
"wiki-plugin-video": "^0.2.10"
|
|
58
59
|
},
|
|
59
60
|
"engines": {
|
|
60
|
-
"node": ">=
|
|
61
|
+
"node": ">=12.x"
|
|
61
62
|
},
|
|
62
63
|
"testling": {
|
|
63
64
|
"harness": "mocha"
|