summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-04-12 22:27:16 +0200
committerJo-Philipp Wich <jo@mein.io>2020-04-12 22:51:28 +0200
commitfde144c9be61d7886e81240233328a61d7088d08 (patch)
treec3761e58f8624abf43bd5468b76a25bf908f3495 /modules/luci-base/htdocs
parente523bfd879f34ee92824e97bf57ceead3ac7bc37 (diff)
luci-base: luci.js: add LuCI.fspath() helper
The LuCI.fspath() function allows constructing absolute filesystem paths from path segments relative to the document root. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/luci.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js
index 5984ad184a..e1aa65a34d 100644
--- a/modules/luci-base/htdocs/luci-static/resources/luci.js
+++ b/modules/luci-base/htdocs/luci-static/resources/luci.js
@@ -2597,6 +2597,37 @@
env: {},
/**
+ * Construct an absolute filesystem path relative to the server
+ * document root.
+ *
+ * @instance
+ * @memberof LuCI
+ *
+ * @param {...string} [parts]
+ * An array of parts to join into a path.
+ *
+ * @return {string}
+ * Return the joined path.
+ */
+ fspath: function(/* ... */) {
+ var path = this.env.documentroot;
+
+ for (var i = 0; i < arguments.length; i++)
+ path += '/' + arguments[i];
+
+ var p = path.replace(/\/+$/, '').replace(/\/+/g, '/').split(/\//),
+ res = [];
+
+ for (var i = 0; i < p.length; i++)
+ if (p[i] == '..')
+ res.pop();
+ else if (p[i] != '.')
+ res.push(p[i]);
+
+ return res.join('/');
+ },
+
+ /**
* Construct a relative URL path from the given prefix and parts.
* The resulting URL is guaranteed to only contain the characters
* `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well