mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-04-23 11:13:18 +00:00

* remove blks first try * dprint.json seems to be OK, some forgotten functions * add some more space-after-keyword settings * server remove blks * add **/files to dprint exclude * dprint.js fixes a typo * add boot.js and bootprefix.js to dprint exclude * dprint change dprint.json * add dprint fmt as script * remove jslint comments * fix whitespace * fix whitespace * remove function-wrapper from geospatial plugin * fix whitespace * add function wrapper to dyannotate-startup * remove dpring.json
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
/*\
|
|
title: $:/core/modules/server/routes/get-file.js
|
|
type: application/javascript
|
|
module-type: route
|
|
|
|
GET /files/:filepath
|
|
|
|
\*/
|
|
"use strict";
|
|
|
|
exports.method = "GET";
|
|
|
|
exports.path = /^\/files\/(.+)$/;
|
|
|
|
exports.handler = function(request,response,state) {
|
|
var path = require("path"),
|
|
fs = require("fs"),
|
|
util = require("util"),
|
|
suppliedFilename = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
|
baseFilename = path.resolve(state.boot.wikiPath,"files"),
|
|
filename = path.resolve(baseFilename,suppliedFilename),
|
|
extension = path.extname(filename);
|
|
// Check that the filename is inside the wiki files folder
|
|
if(path.relative(baseFilename,filename).indexOf("..") !== 0) {
|
|
// Send the file
|
|
fs.readFile(filename,function(err,content) {
|
|
var status,content,type = "text/plain";
|
|
if(err) {
|
|
console.log("Error accessing file " + filename + ": " + err.toString());
|
|
status = 404;
|
|
content = "File '" + suppliedFilename + "' not found";
|
|
} else {
|
|
status = 200;
|
|
content = content;
|
|
type = ($tw.config.fileExtensionInfo[extension] ? $tw.config.fileExtensionInfo[extension].type : "application/octet-stream");
|
|
}
|
|
state.sendResponse(status,{"Content-Type": type},content);
|
|
});
|
|
} else {
|
|
state.sendResponse(404,{"Content-Type": "text/plain"},"File '" + suppliedFilename + "' not found");
|
|
}
|
|
};
|