Merge pull request #412 from xwiki-labs/downloadFiles

Download files
pull/1/head
ansuz 5 years ago committed by GitHub
commit c66e1f02c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,7 +8,7 @@ define([
module.main = function (userDoc, cb) { module.main = function (userDoc, cb) {
var mode = userDoc.highlightMode || 'gfm'; var mode = userDoc.highlightMode || 'gfm';
var content = userDoc.content; var content = userDoc.content;
module.type = SFCodeMirror.getContentExtension(mode); module.ext = SFCodeMirror.getContentExtension(mode);
cb(SFCodeMirror.fileExporter(content)); cb(SFCodeMirror.fileExporter(content));
}; };

@ -6,141 +6,141 @@ define([
// mode language (extension) // mode language (extension)
var list = Modes.list = [ var list = Modes.list = [
"APL apl .apl", "APL apl .apl",
"ASCII-Armor asciiarmor", "ASCII-Armor asciiarmor .asc",
"ASN.1 asn.1", "ASN.1 asn.1 .asn1",
"Asterisk asterisk", "Asterisk asterisk",
"Brainfuck brainfuck .b", "Brainfuck brainfuck .b",
"C text/x-csrc .c", "C text/x-csrc .c",
"C text/x-c++src .cpp", "C text/x-c++src .cpp",
"C-like clike", "C-like clike .c",
"Clojure clojure", "Clojure clojure .clj",
"CMake cmake", "CMake cmake _", /* no extension */
"COBOL cobol", "COBOL cobol .cbl",
"CoffeeScript coffeescript", "CoffeeScript coffeescript .coffee",
"Common_Lisp commonlisp", "Common_Lisp commonlisp .lisp",
"Crystal crystal", "Crystal crystal .cr",
"CSS css .css", "CSS css .css",
"Cypher cypher", "Cypher cypher .cypher",
"D d", "D d .d",
"Dart dart", "Dart dart .dart",
"Diff diff", "Diff diff .diff",
"Django django", "Django django .py",
"Dockerfile dockerfile", "Dockerfile dockerfile _", /* no extension */
"DTD dtd", "DTD dtd .dtd",
"Dylan dylan", "Dylan dylan .dylan",
"EBNF ebnf", "EBNF ebnf .ebnf",
"ECL ecl", "ECL ecl .ecl",
"Eiffel eiffel", "Eiffel eiffel .e",
"Elm elm .elm", "Elm elm .elm",
"Erlang erlang", "Erlang erlang .erl",
"Factor factor", "Factor factor .factor",
"FCL fcl", "FCL fcl .fcl",
"Forth forth", "Forth forth .fs",
"Fortran fortran", "Fortran fortran .f90",
"GAS gas", "GAS gas .gas",
"Gherkin gherkin", "Gherkin gherkin .feature",
"Go go", "Go go .go",
"Groovy groovy", "Groovy groovy .groovy",
"Haml haml", "Haml haml .haml",
"Handlebars handlebars", "Handlebars handlebars .hbs",
"Haskell haskell .hs", "Haskell haskell .hs",
"Haskell-Literate haskell-literate", "Haskell-Literate haskell-literate .lhs",
"Haxe haxe", "Haxe haxe .hx",
"HTML htmlmixed .html", "HTML htmlmixed .html",
"HTTP http", "HTTP http _", /* no extension */
"IDL idl", "IDL idl .idl",
"JADE jade", "JADE jade .jade",
"Java text/x-java .java", "Java text/x-java .java",
"JavaScript javascript .js", "JavaScript javascript .js",
"Jinja2 jinja2", "Jinja2 jinja2 .j2",
"JSX jsx .jsx", "JSX jsx .jsx",
"Julia julia", "Julia julia .jl",
"LiveScript livescript", "LiveScript livescript .ls",
"Lua lua", "Lua lua .lua",
"Markdown gfm .md", "Markdown gfm .md",
//"markdown markdown .md", //"markdown markdown .md",
"Mathematica mathematica", "Mathematica mathematica .nb",
"mIRC mirc", "mIRC mirc .irc",
"ML mllike", "ML mllike _", /* no extension */
"Modelica modelica", "Modelica modelica .mo",
"MscGen mscgen", "MscGen mscgen .mscgen",
"MUMPS mumps", "MUMPS mumps .m",
"Nginx nginx", "Nginx nginx .conf",
"NSIS nsis", "NSIS nsis .nsi",
"N-Triples ntriples", "N-Triples ntriples .nq",
"Objective-C text/x-objectivec .m", "Objective-C text/x-objectivec .m",
"Octave octave", "Octave octave .m",
"Org-mode orgmode .org", "Org-mode orgmode .org",
"Oz oz", "Oz oz .oz",
"Pascal pascal", "Pascal pascal .pas",
"PEG.js pegjs", "PEG.js pegjs .pegjs",
"Perl perl", "Perl perl .pl",
"PHP php", "PHP php .php",
"Pig pig", "Pig pig .pig",
"PowerShell powershell", "PowerShell powershell .ps1",
"Properties properties", "Properties properties .properties",
"Protocol_Buffers protobuf", "Protocol_Buffers protobuf .proto",
"Puppet puppet", "Puppet puppet .pp",
"Python python .py", "Python python .py",
"Q q", "Q q .q",
"R r", "R r .r",
"RPM rpm", "RPM rpm .rpm",
"RST rst", "RST rst .rst",
"Ruby ruby", "Ruby ruby .rb",
"Rust rust", "Rust rust .rs",
"Sass sass", "Sass sass .sass",
"Scheme scheme .scm", "Scheme scheme .scm",
"Shell shell .sh", "Shell shell .sh",
"Sieve sieve", "Sieve sieve .sieve",
"Slim slim", "Slim slim .slim",
"Smalltalk smalltalk", "Smalltalk smalltalk _", /* no extension */
"Smarty smarty", "Smarty smarty _", /* no extension */
"Solr solr", "Solr solr _", /* no extension */
"Soy soy", "Soy soy .soy",
"SPARQL sparql", "SPARQL sparql .rq",
"Spreadsheet spreadsheet", "Spreadsheet spreadsheet .xls",
"SQL sql", "SQL sql .sql",
"sTeX stex", "sTeX stex .stex",
"Stylus stylus", "Stylus stylus .styl",
"Swift swift", "Swift swift .swift",
"Tcl tcl", "Tcl tcl .tcl",
"Text text .txt", "Text text .txt",
"Textile textile", "Textile textile .textile",
"TiddlyWiki tiddlywiki", "TiddlyWiki tiddlywiki .tw",
"Tiki tiki", "Tiki tiki _", /* no extension */
"TOML toml", "TOML toml .toml",
"Tornado tornado", "Tornado tornado .tornado",
"troff troff", "troff troff .troff",
"TTCN ttcn", "TTCN ttcn",
"TTCN-cfg ttcn-cfg", "TTCN-cfg ttcn-cfg",
"Turtle turtle", "Turtle turtle .ttl",
"Twig twig", "Twig twig .twig",
"Visual_Basic vb", "Visual_Basic vb .vb",
"VBScript vbscript", "VBScript vbscript .vbs",
"Velocity velocity", "Velocity velocity .vm",
"Verilog verilog", "Verilog verilog .v",
"VHDL vhdl", "VHDL vhdl .vhdl",
"Vue vue", "Vue vue .vue",
"XML xml", "XML xml .xml",
//"xwiki xwiki21", //"xwiki xwiki21",
"XQuery xquery", "XQuery xquery .xquery",
"YAML yaml .yaml", "YAML yaml .yaml",
"YAML_Frontmatter yaml-frontmatter", "YAML_Frontmatter yaml-frontmatter _", /* no extension */
"Z80 z80" "Z80 z80 .z80"
].map(function (line) { ].map(function (line) {
var kv = line.split(/\s/); var kv = line.split(/\s/);
return { return {
language: kv[0].replace(/_/g, ' '), language: kv[0].replace(/_/g, ' '),
mode: kv[1], mode: kv[1],
ext: kv[2], ext: kv[2] === '_' ? '' : kv[2],
}; };
}); });
Modes.extensionOf = function (mode) { Modes.extensionOf = function (mode) {
var ext = ''; var ext;
list.some(function (o) { list.some(function (o) {
if (o.mode !== mode) { return; } if (o.mode !== mode) { return; }
ext = o.ext || ''; ext = o.ext;
return true; return true;
}); });
return ext; return ext;

@ -401,7 +401,7 @@ define([
var ext = (typeof(extension) === 'function') ? extension() : extension; var ext = (typeof(extension) === 'function') ? extension() : extension;
var suggestion = title.suggestTitle('cryptpad-document'); var suggestion = title.suggestTitle('cryptpad-document');
UI.prompt(Messages.exportPrompt, UI.prompt(Messages.exportPrompt,
Util.fixFileName(suggestion) + '.' + ext, function (filename) Util.fixFileName(suggestion) + ext, function (filename)
{ {
if (!(typeof(filename) === 'string' && filename)) { return; } if (!(typeof(filename) === 'string' && filename)) { return; }
if (async) { if (async) {
@ -454,7 +454,7 @@ define([
return; return;
} }
if (!mediaTagEmbedder) { console.log('mediaTagEmbedder missing'); return; } if (!mediaTagEmbedder) { console.log('mediaTagEmbedder missing'); return; }
if (data.type !== 'file') { console.log('unhandled embed type ' + data.type); return; } if (data.type !== 'file') { console.log('unhandled embed type ' + data.type); return; }
var privateDat = cpNfInner.metadataMgr.getPrivateData(); var privateDat = cpNfInner.metadataMgr.getPrivateData();
var origin = privateDat.fileHost || privateDat.origin; var origin = privateDat.fileHost || privateDat.origin;
var src = data.src = origin + data.src; var src = data.src = origin + data.src;

@ -39,7 +39,8 @@ define([
}; };
module.getContentExtension = function (mode) { module.getContentExtension = function (mode) {
return (Modes.extensionOf(mode) || '.txt').slice(1); var ext = Modes.extensionOf(mode);
return ext !== undefined ? ext : '.txt';
}; };
module.fileExporter = function (content) { module.fileExporter = function (content) {
return new Blob([ content ], { type: 'text/plain;charset=utf-8' }); return new Blob([ content ], { type: 'text/plain;charset=utf-8' });

@ -2,7 +2,9 @@
// Pads from the code app will be exported using this format instead of plain text. // Pads from the code app will be exported using this format instead of plain text.
define([ define([
], function () { ], function () {
var module = {}; var module = {
ext: '.json'
};
module.main = function (userDoc, cb) { module.main = function (userDoc, cb) {
var content = userDoc.content; var content = userDoc.content;

@ -367,7 +367,7 @@ define([
}); });
} }
framework.setFileExporter('json', function () { framework.setFileExporter('.json', function () {
return new Blob([JSON.stringify(kanban.getBoardsJSON(), 0, 2)], { return new Blob([JSON.stringify(kanban.getBoardsJSON(), 0, 2)], {
type: 'application/json', type: 'application/json',
}); });

@ -5,7 +5,7 @@ define([
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
], function ($, Util, Hyperjson, nThen) { ], function ($, Util, Hyperjson, nThen) {
var module = { var module = {
type: 'html' ext: '.html'
}; };
var exportMediaTags = function (inner, cb) { var exportMediaTags = function (inner, cb) {

@ -786,7 +786,7 @@ define([
}); });
}, true); }, true);
framework.setFileExporter(Exporter.type, function (cb) { framework.setFileExporter(Exporter.ext, function (cb) {
Exporter.main(inner, cb); Exporter.main(inner, cb);
}, true); }, true);

@ -3,7 +3,9 @@
define([ define([
'/customize/messages.js', '/customize/messages.js',
], function (Messages) { ], function (Messages) {
var module = {}; var module = {
ext: '.csv'
};
var copyObject = function (obj) { var copyObject = function (obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));

@ -34,7 +34,7 @@ define([
var path = '/' + type + '/export.js'; var path = '/' + type + '/export.js';
require([path], function (Exporter) { require([path], function (Exporter) {
Exporter.main(json, function (data) { Exporter.main(json, function (data) {
result.ext = '.' + Exporter.type; result.ext = Exporter.ext || '';
result.data = data; result.data = data;
cb(result); cb(result);
}); });
@ -163,12 +163,12 @@ define([
var existingNames = []; var existingNames = [];
Object.keys(root).forEach(function (k) { Object.keys(root).forEach(function (k) {
var el = root[k]; var el = root[k];
if (typeof el === "object") { if (typeof el === "object" && el.metadata !== true) { // if folder
var fName = getUnique(sanitize(k), '', existingNames); var fName = getUnique(sanitize(k), '', existingNames);
existingNames.push(fName.toLowerCase()); existingNames.push(fName.toLowerCase());
return void makeFolder(ctx, el, zip.folder(fName), fd); return void makeFolder(ctx, el, zip.folder(fName), fd);
} }
if (ctx.data.sharedFolders[el]) { if (ctx.data.sharedFolders[el]) { // if shared folder
var sfData = ctx.sf[el].metadata; var sfData = ctx.sf[el].metadata;
var sfName = getUnique(sanitize(sfData.title || 'Folder'), '', existingNames); var sfName = getUnique(sanitize(sfData.title || 'Folder'), '', existingNames);
existingNames.push(sfName.toLowerCase()); existingNames.push(sfName.toLowerCase());

@ -4,7 +4,7 @@ define([
'/common/sframe-common-codemirror.js', '/common/sframe-common-codemirror.js',
], function (SFCodeMirror) { ], function (SFCodeMirror) {
var module = { var module = {
type: 'md' ext: '.md'
}; };
module.main = function (userDoc, cb) { module.main = function (userDoc, cb) {

@ -538,7 +538,7 @@ define([
editor.on('change', framework.localChange); editor.on('change', framework.localChange);
framework.setFileExporter(CodeMirror.getContentExtension, CodeMirror.fileExporter); framework.setFileExporter(".md", CodeMirror.fileExporter);
framework.setFileImporter({}, CodeMirror.fileImporter); framework.setFileImporter({}, CodeMirror.fileImporter);
framework.start(); framework.start();

@ -14,7 +14,7 @@ define([
var canvas = new Fabric.Canvas(canvas_node); var canvas = new Fabric.Canvas(canvas_node);
var content = userDoc.content; var content = userDoc.content;
canvas.loadFromJSON(content, function () { canvas.loadFromJSON(content, function () {
module.type = 'svg'; module.ext = '.svg';
cb(canvas.toSVG()); cb(canvas.toSVG());
}); });
}; };

@ -415,11 +415,11 @@ define([
setEditable(!locked); setEditable(!locked);
}); });
framework.setFileExporter('png', function (cb) { framework.setFileExporter('.png', function (cb) {
$canvas[0].toBlob(function (blob) { $canvas[0].toBlob(function (blob) {
cb(blob); cb(blob);
}); });
}); }, true);
framework.setNormalizer(function (c) { framework.setNormalizer(function (c) {
return { return {

Loading…
Cancel
Save