wiki-plugin-assets
Advanced tools
Comparing version 0.4.1-pre1 to 0.5.0
@@ -51,2 +51,3 @@ "use strict"; | ||
$item.empty(); | ||
$item.off(); | ||
emit($item, item); | ||
@@ -71,2 +72,5 @@ return bind($item, item); | ||
assets = item.text.match(/([\w\/-]*)/)[1]; | ||
if (assets === 'PAGE') { | ||
assets = "/pages/" + $item.parents('.page')[0].id.split('_rev')[0]; | ||
} | ||
filename = url.split('/').reverse()[0]; | ||
@@ -94,3 +98,6 @@ return fetch(url).then(function (response) { | ||
file = url.split('/').reverse()[0]; | ||
assets = item.text; | ||
assets = item.text.match(/([\w\/-]*)/)[1]; | ||
if (assets === 'PAGE') { | ||
assets = "/pages/" + $item.parents('.page')[0].id.split('_rev')[0]; | ||
} | ||
return $.ajax({ | ||
@@ -101,2 +108,3 @@ url: "/plugin/assets/delete?file=".concat(file, "&assets=").concat(assets), | ||
$item.empty(); | ||
$item.off(); | ||
emit($item, item); | ||
@@ -185,3 +193,2 @@ return bind($item, item); | ||
}; | ||
$item.append("<div style=\"background-color:#eee;padding:15px; margin-block-start:1em; margin-block-end:1em;\">\n <dl style=\"margin:0;color:gray\"></dl>\n ".concat(uploader(), "\n</div>")); | ||
assetsData = {}; | ||
@@ -193,2 +200,11 @@ $item.addClass('assets-source'); | ||
assets = item.text.match(/([\w\/-]*)/)[1]; | ||
if (assets === 'PAGE') { | ||
if ($item.parents('.page')[0].id.endsWith('template')) { | ||
$item.append("<div style=\"background-color:#eee;padding:15px; margin-block-start:1em; margin-block-end:1em;\">\n <p><i>This asset item will use a folder name derived from the title of the created page.</i></p>\n</div>"); | ||
return; | ||
} else { | ||
assets = "/pages/" + $item.parents('.page')[0].id.split('_rev')[0]; | ||
} | ||
} | ||
$item.append("<div style=\"background-color:#eee;padding:15px; margin-block-start:1em; margin-block-end:1em;\">\n <dl style=\"margin:0;color:gray\"></dl>\n ".concat(uploader(), "\n</div>")); | ||
ref = context($item); | ||
@@ -206,2 +222,5 @@ results = []; | ||
assets = item.text.match(/([\w\/-]*)/)[1]; | ||
if (assets === 'PAGE') { | ||
assets = "/pages/" + $item.parents('.page')[0].id.split('_rev')[0]; | ||
} | ||
$item.on('dblclick', function () { | ||
@@ -208,0 +227,0 @@ return wiki.textEditor($item, item); |
{ | ||
"name": "wiki-plugin-assets", | ||
"version": "0.4.1-pre1", | ||
"version": "0.5.0", | ||
"description": "Federated Wiki - Assets Plugin", | ||
@@ -21,11 +21,11 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/preset-env": "^7.4.5", | ||
"@babel/core": "^7.24.5", | ||
"@babel/preset-env": "^7.24.5", | ||
"expect.js": "^0.3.1", | ||
"grunt": "^1.0.4", | ||
"grunt": "^1.6.1", | ||
"grunt-contrib-coffee": "^2.1.0", | ||
"grunt-contrib-watch": "^1.1.0", | ||
"grunt-git-authors": "^3.2.0", | ||
"grunt-mocha-test": "^0.13.2", | ||
"mocha": "^10.1.0" | ||
"grunt-mocha-test": "^0.13.3", | ||
"mocha": "^10.4.0" | ||
}, | ||
@@ -41,9 +41,7 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10" | ||
"node": ">=0.20" | ||
}, | ||
"dependencies": { | ||
"async": "^2.6.0", | ||
"formidable": "^1.1.1", | ||
"mkdirp": "^1.0.3" | ||
"multer": "^1.4.5-lts.1" | ||
} | ||
} |
@@ -1,123 +0,99 @@ | ||
"use strict"; | ||
// assets plugin - server-side component | ||
// these handlers are launched with the wiki server. | ||
(function () { | ||
// assets plugin, server-side component | ||
// These handlers are launched with the wiki server. | ||
var async, basename, cors, formidable, fs, mkdirp, startServer; | ||
fs = require('fs'); | ||
var _require = require('path'); | ||
basename = _require.basename; | ||
mkdirp = require('mkdirp'); | ||
async = require('async'); | ||
formidable = require('formidable'); | ||
cors = function cors(req, res, next) { | ||
res.header('Access-Control-Allow-Origin', '*'); | ||
return next(); | ||
}; | ||
startServer = function startServer(params) { | ||
var app, argv; | ||
app = params.app; | ||
argv = params.argv; | ||
app.get('/plugin/assets/list', cors, function (req, res) { | ||
var assets, isFile, path; | ||
assets = (req.query.assets || '').match(/([\w\/-]*)/)[1]; | ||
path = "".concat(argv.assets, "/").concat(assets); | ||
isFile = function isFile(name, done) { | ||
if (name.match(/^\./)) { | ||
return done(false); | ||
} | ||
return fs.stat("".concat(path, "/").concat(name), function (error, stats) { | ||
if (error) { | ||
return done(error); | ||
const fs = require('fs') | ||
const path = require('path') | ||
const multer = require('multer') | ||
const startServer = (params) => { | ||
const { app, argv } = params | ||
const upload = multer({ dest: path.join(argv.assets, 'uploads') }) | ||
const authorized = (req, res, next) => { | ||
if (app['securityhandler'].isAuthorized(req)) { | ||
next() | ||
} else { | ||
res.status(403).send('must be owner') | ||
} | ||
} | ||
const cors = (req, res, next) => { | ||
res.header('Access-Control-Allow-Origin', '*') | ||
next() | ||
} | ||
app.get('/plugin/assets/list', cors, (req, res) => { | ||
assetsPath = path.join(argv.assets, (req.query.assets || '').match(/([\w\/-]*)/)[1]) | ||
fs.readdir(assetsPath, { withFileTypes: true }, (error, files) => { | ||
if (error) { | ||
return res.json({ error }) | ||
} | ||
const filtered = files.filter(file => file.isFile()).map(file => file.name) | ||
return res.json({error, files: filtered}) | ||
}) | ||
}) | ||
app.get('/plugin/assets/index', cors, (req, res) => { | ||
const walk = (dir) => { | ||
const files = fs.readdirSync(path.join(argv.assets, dir), {withFileTypes: true}) | ||
return files.map((file) => { | ||
if (!file.name.startsWith('.')) { | ||
if (file.isFile()) { | ||
return { file: path.join(path.sep, dir, file.name), size: fs.statSync(path.join(argv.assets, dir, file.name)).size } | ||
} | ||
return done(null, stats.isFile()); | ||
}); | ||
}; | ||
return fs.readdir(path, function (error, names) { | ||
if (error) { | ||
return res.json({ | ||
error: error | ||
}); | ||
} | ||
return async.filter(names, isFile, function (error, files) { | ||
return res.json({ | ||
error: error, | ||
files: files | ||
}); | ||
}); | ||
}); | ||
}); | ||
app.get('/plugin/assets/index', cors, function (req, res) { | ||
var _walk; | ||
_walk = function walk(root) { | ||
return fs.readdirSync("".concat(argv.assets, "/").concat(root)).flatMap(function (name) { | ||
var path, stat; | ||
path = "".concat(root, "/").concat(name); | ||
stat = fs.statSync("".concat(argv.assets, "/").concat(path)); | ||
if (stat.isDirectory()) { | ||
return _walk(path); | ||
} else { | ||
return { | ||
file: path, | ||
size: stat.size | ||
}; | ||
if (file.isDirectory()) { | ||
return walk(path.join(dir, file.name)).flat() | ||
} | ||
}); | ||
}; | ||
return res.json(_walk("")); | ||
}); | ||
app.post('/plugin/assets/upload', function (req, res) { | ||
var form; | ||
if (!app.securityhandler.isAuthorized(req)) { | ||
return res.status(401).send("must be logged in owner"); | ||
} | ||
form = new formidable.IncomingForm(); | ||
form.multiples = true; | ||
form.uploadDir = "".concat(argv.assets); | ||
mkdirp.sync(form.uploadDir); | ||
form.on('field', function (name, value) { | ||
var assets; | ||
if (name !== 'assets') { | ||
return; | ||
return [] | ||
} else { | ||
return [] | ||
} | ||
assets = (value || '').match(/([\w\/-]*)/)[1]; | ||
form.uploadDir = "".concat(argv.assets, "/").concat(assets); | ||
return mkdirp.sync(form.uploadDir); | ||
}); | ||
form.on('file', function (field, file) { | ||
return fs.rename(file.path, "".concat(form.uploadDir, "/").concat(file.name), function (err) { | ||
if (err) { | ||
return res.status(500).send("rename error: ".concat(err)); | ||
} | ||
}); | ||
}); | ||
form.on('error', function (err) { | ||
console.log("upload error: ".concat(err)); | ||
return res.status(500).send("upload error: ".concat(err)); | ||
}); | ||
form.on('end', function () { | ||
return res.end('success'); | ||
}); | ||
return form.parse(req); | ||
}); | ||
return app.post('/plugin/assets/delete', function (req, res) { | ||
var assets, file, ref, ref1, ref2, ref3, toRemove; | ||
if (!(((ref = req.session) != null ? (ref1 = ref.passport) != null ? ref1.user : void 0 : void 0) || ((ref2 = req.session) != null ? ref2.email : void 0) || ((ref3 = req.session) != null ? ref3.friend : void 0))) { | ||
return res.status(401).send("must login"); | ||
} | ||
file = basename(req.query.file || ''); | ||
assets = (req.query.assets || '').match(/([\w\/-]*)/)[1]; | ||
toRemove = "".concat(argv.assets, "/").concat(assets, "/").concat(file); | ||
return fs.unlink(toRemove, function (err) { | ||
}).flat() | ||
} | ||
return res.json(walk('')) | ||
}) | ||
app.post('/plugin/assets/upload', authorized, upload.any(), (req, res) => { | ||
const assetPath = path.join(argv.assets, (req.body.assets || '').match(/([\w\/-]*)/)[1]) | ||
fs.mkdirSync(assetPath, { recursive: true }) | ||
let errors = [] | ||
req.files.forEach(((element) => { | ||
const uploaded = element.path | ||
const assetDestination = path.join(assetsPath, element.originalname) | ||
fs.rename(uploaded, assetDestination, (err) => { | ||
if (err) { | ||
return res.status(500).send(err.message); | ||
errors.push(`rename failed for ${element.originalname}`) | ||
} | ||
return res.status(200).send('ok'); | ||
}); | ||
}); | ||
}; | ||
module.exports = { | ||
startServer: startServer | ||
}; | ||
}).call(void 0); | ||
//# sourceMappingURL=server.js.map | ||
}) | ||
})) | ||
if (errors.length > 0) { | ||
res.status(500).send(errors.join('\n')) | ||
} else { | ||
res.end('success') | ||
} | ||
}) | ||
app.post('/plugin/assets/delete', authorized, (req, res) => { | ||
const file = path.basename(req.query.file || '') | ||
if (file) { | ||
const assets = (req.query.assets || '').match(/([\w\/-]*)/)[1] | ||
toRemove = path.join(argv.assets, assets, file) | ||
fs.unlink(toRemove, (err) => { | ||
if (err) { | ||
res.status(500).send(err.message) | ||
} else { | ||
res.status(200).send('ok') | ||
} | ||
}) | ||
} else { | ||
res.status(500).send('No file specified') | ||
} | ||
}) | ||
} | ||
module.exports = { startServer } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
54317
1
352
1
+ Addedmulter@^1.4.5-lts.1
+ Addedappend-field@1.0.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedbusboy@1.6.0(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedmulter@1.4.5-lts.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstreamsearch@1.1.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedasync@^2.6.0
- Removedformidable@^1.1.1
- Removedmkdirp@^1.0.3
- Removedasync@2.6.4(transitive)
- Removedformidable@1.2.6(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmkdirp@1.0.4(transitive)