New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wiki-plugin-assets

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wiki-plugin-assets - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

122

client/assets.js

@@ -1,11 +0,14 @@

(function() {
var bind, context, emit, expand, fetch;
"use strict";
expand = function(text) {
(function () {
var _bind, context, emit, expand, fetch;
expand = function expand(text) {
return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};
context = function($item) {
context = function context($item) {
var action, i, journal, len, ref, remote, sites;
sites = [location.host];
if (remote = $item.parents('.page').data('site')) {

@@ -16,17 +19,22 @@ if (remote !== location.host) {

}
journal = $item.parents('.page').data('data').journal;
ref = journal.slice(0).reverse();
for (i = 0, len = ref.length; i < len; i++) {
action = ref[i];
if ((action.site != null) && !sites.includes(action.site)) {
if (action.site != null && !sites.includes(action.site)) {
sites.push(action.site);
}
}
return sites;
};
fetch = function($report, assets, remote) {
fetch = function fetch($report, assets, remote) {
var assetsURL, link, render, requestSite, trouble;
requestSite = remote != null ? remote : null;
assetsURL = wiki.site(requestSite).getDirectURL('assets');
if (assetsURL === '') {

@@ -36,7 +44,10 @@ $report.text("site not currently reachable.");

}
link = function(file) {
return `<a href="${assetsURL}/${(assets === '' ? "" : assets + "/")}${encodeURIComponent(file)}" target=_blank>${expand(file)}</a>`;
link = function link(file) {
return "<a href=\"".concat(assetsURL, "/").concat(assets === '' ? "" : assets + "/").concat(encodeURIComponent(file), "\" target=_blank>").concat(expand(file), "</a>");
};
render = function(data) {
render = function render(data) {
var file, files;
if (data.error) {

@@ -46,11 +57,16 @@ if (data.error.code === 'ENOENT') {

}
return $report.text(`plugin reports: ${data.error.code}`);
return $report.text("plugin reports: ".concat(data.error.code));
}
files = data.files;
if (files.length === 0) {
return $report.text("no files");
}
return $report.html(((function() {
return $report.html(function () {
var i, len, results;
results = [];
for (i = 0, len = files.length; i < len; i++) {

@@ -60,11 +76,16 @@ file = files[i];

}
return results;
})()).join("<br>"));
}().join("<br>"));
};
trouble = function(e) {
return $report.text(`plugin error: ${e.statusText} ${e.responseText || ''}`);
trouble = function trouble(e) {
return $report.text("plugin error: ".concat(e.statusText, " ").concat(e.responseText || ''));
};
return $.ajax({
url: wiki.site(requestSite).getURL('plugin/assets/list'),
data: {assets},
data: {
assets: assets
},
dataType: 'json',

@@ -76,50 +97,60 @@ success: render,

emit = function($item, item) {
emit = function emit($item, item) {
var $report, assets, i, len, ref, results, site, uploader;
uploader = function() {
uploader = function uploader() {
if ($item.parents('.page').hasClass('remote')) {
return '';
}
return "<div style=\"background-color:#ddd;\" class=\"progress-bar\" role=\"progressbar\"></div>\n<center><button>upload</button></center>\n<input style=\"display: none;\" type=\"file\" name=\"uploads[]\" multiple=\"multiple\">";
};
$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 ${uploader()}\n</div>`);
$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>"));
assets = item.text.match(/([\w\/-]*)/)[1];
ref = context($item);
results = [];
for (i = 0, len = ref.length; i < len; i++) {
site = ref[i];
$report = $item.find('dl').prepend(`<dt><img width=12 src="${wiki.site(site).flag()}"> ${site}</dt>\n<dd style="margin:8px;"></dd>`);
$report = $item.find('dl').prepend("<dt><img width=12 src=\"".concat(wiki.site(site).flag(), "\"> ").concat(site, "</dt>\n<dd style=\"margin:8px;\"></dd>"));
results.push(fetch($report.find('dd:first'), assets, site));
}
return results;
};
bind = function($item, item) {
_bind = function bind($item, item) {
var $button, $input, $progress, assets, ignore, tick, upload;
assets = item.text.match(/([\w\/-]*)/)[1];
$item.dblclick(function() {
$item.dblclick(function () {
return wiki.textEditor($item, item);
});
// https://coligo.io/building-ajax-file-uploader-with-node/
}); // https://coligo.io/building-ajax-file-uploader-with-node/
$button = $item.find('button');
$input = $item.find('input');
$progress = $item.find('.progress-bar');
ignore = function(e) {
ignore = function ignore(e) {
e.preventDefault();
return e.stopPropagation();
};
tick = function(e) {
tick = function tick(e) {
var percentComplete;
if (!e.lengthComputable) {
return;
}
percentComplete = e.loaded / e.total;
percentComplete = parseInt(percentComplete * 100);
$progress.text(`${percentComplete}%`);
return $progress.width(`${percentComplete}%`);
$progress.text("".concat(percentComplete, "%"));
return $progress.width("".concat(percentComplete, "%"));
};
$button.click(function(e) {
$button.click(function (e) {
return $input.click();
});
$input.on('change', function(e) {
$input.on('change', function (e) {
return upload($(this).get(0).files);

@@ -129,3 +160,3 @@ });

$item.on('dragenter', ignore);
$item.on('drop', function(e) {
$item.on('drop', function (e) {
var ref;

@@ -135,9 +166,12 @@ ignore(e);

});
return upload = function(files) {
return upload = function upload(files) {
var file, form, i, len;
if (!(files != null ? files.length : void 0)) {
return;
}
form = new FormData();
form.append('assets', assets);
for (i = 0, len = files.length; i < len; i++) {

@@ -147,2 +181,3 @@ file = files[i];

}
return $.ajax({

@@ -154,15 +189,15 @@ url: '/plugin/assets/upload',

contentType: false,
success: function() {
success: function success() {
$item.empty();
emit($item, item);
return bind($item, item);
return _bind($item, item);
},
error: function(e) {
error: function error(e) {
console.log('error', e);
$progress.text(`upload error: ${e.statusText} ${e.responseText || ''}`);
$progress.text("upload error: ".concat(e.statusText, " ").concat(e.responseText || ''));
return $progress.width('100%');
},
xhr: function() {
xhr: function xhr() {
var xhr;
xhr = new XMLHttpRequest;
xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', tick, false);

@@ -176,11 +211,14 @@ return xhr;

if (typeof window !== "undefined" && window !== null) {
window.plugins.assets = {emit, bind};
window.plugins.assets = {
emit: emit,
bind: _bind
};
}
if (typeof module !== "undefined" && module !== null) {
module.exports = {expand};
module.exports = {
expand: expand
};
}
}).call(this);
}).call(void 0);
//# sourceMappingURL=assets.js.map
{
"name": "wiki-plugin-assets",
"version": "0.2.2",
"version": "0.2.3",
"description": "Federated Wiki - Assets Plugin",

@@ -21,2 +21,4 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"expect.js": "^0.3.1",

@@ -33,6 +35,6 @@ "grunt": "^1.0.4",

"type": "git",
"url": "https://github.com/wardcunningham/wiki-plugin-assets.git"
"url": "https://github.com/fedwiki/wiki-plugin-assets.git"
},
"bugs": {
"url": "https://github.com/wardcunningham/wiki-plugin-assets/issues"
"url": "https://github.com/fedwiki/wiki-plugin-assets/issues"
},

@@ -39,0 +41,0 @@ "engines": {

@@ -1,15 +0,13 @@

(function() {
"use strict";
(function () {
// assets plugin, server-side component
// These handlers are launched with the wiki server.
var async, cors, formidable, fs, mkdirp, startServer;
fs = require('fs');
mkdirp = require('mkdirp');
async = require('async');
formidable = require('formidable');
cors = function(req, res, next) {
cors = function cors(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');

@@ -19,60 +17,74 @@ return next();

startServer = function(params) {
startServer = function startServer(params) {
var app, argv;
app = params.app;
argv = params.argv;
app.get('/plugin/assets/list', cors, function(req, res) {
app.get('/plugin/assets/list', cors, function (req, res) {
var assets, isFile, path;
assets = (req.query.assets || '').match(/([\w\/-]*)/)[1];
path = `${argv.assets}/${assets}`;
isFile = function(name, done) {
path = "".concat(argv.assets, "/").concat(assets);
isFile = function isFile(name, done) {
if (name.match(/^\./)) {
return done(false);
}
return fs.stat(`${path}/${name}`, function(error, stats) {
return fs.stat("".concat(path, "/").concat(name), function (error, stats) {
if (error) {
return done(error);
}
return done(null, stats.isFile());
});
};
return fs.readdir(path, function(error, names) {
return fs.readdir(path, function (error, names) {
if (error) {
return res.json({error});
return res.json({
error: error
});
}
return async.filter(names, isFile, function(error, files) {
return res.json({error, files});
return async.filter(names, isFile, function (error, files) {
return res.json({
error: error,
files: files
});
});
});
});
app.post('/plugin/assets/upload', function(req, res) {
app.post('/plugin/assets/upload', function (req, res) {
var form, ref, ref1, ref2, ref3;
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");
}
form = new formidable.IncomingForm;
form = new formidable.IncomingForm();
form.multiples = true;
form.uploadDir = `${argv.assets}`;
form.uploadDir = "".concat(argv.assets);
mkdirp.sync(form.uploadDir);
form.on('field', function(name, value) {
form.on('field', function (name, value) {
var assets;
if (name !== 'assets') {
return;
}
assets = (value || '').match(/([\w\/-]*)/)[1];
form.uploadDir = `${argv.assets}/${assets}`;
form.uploadDir = "".concat(argv.assets, "/").concat(assets);
return mkdirp.sync(form.uploadDir);
});
form.on('file', function(field, file) {
return fs.rename(file.path, `${form.uploadDir}/${file.name}`, function(err) {
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: ${err}`);
return res.status(500).send("rename error: ".concat(err));
}
});
});
form.on('error', function(err) {
console.log(`upload error: ${err}`);
return res.status(500).send(`upload error: ${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() {
form.on('end', function () {
return res.end('success');

@@ -82,13 +94,15 @@ });

});
return app.get('/plugin/assets/:thing', function(req, res) {
return app.get('/plugin/assets/:thing', function (req, res) {
var thing;
thing = req.params.thing;
return res.json({thing});
return res.json({
thing: thing
});
});
};
module.exports = {startServer};
}).call(this);
module.exports = {
startServer: startServer
};
}).call(void 0);
//# sourceMappingURL=server.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc