mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-18 08:46:35 +00:00
Fix CI/CD and update binary assets
This commit is contained in:
parent
95d50ff971
commit
43e0ff9270
666
data/edit.htm
666
data/edit.htm
@ -1,665 +1 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
|
||||
<script type="module" src="/static/main.js?COMMIT_HASH"></script>
|
||||
<!-- script src="/static/ace.js?v=1.9.6"></script -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.0/ace.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.0/theme-monokai.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.0/mode-html.js"></script>
|
||||
|
||||
<title>openHASP</title>
|
||||
<link rel="stylesheet" href="/static/vars.css?COMMIT_HASH"/>
|
||||
<link rel="stylesheet" href="/static/style.css?COMMIT_HASH"/>
|
||||
<link rel="icon" href="/static/logo.svg?COMMIT_HASH" type="image/svg+xml">
|
||||
|
||||
<link href="https://fonts.cdnfonts.com/css/jetbrains-mono" rel="stylesheet">
|
||||
<link href="https://fonts.cdnfonts.com/css/source-code-pro" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body v-cloak v-scope @vue:mounted="mounted" onLoad="prepare()">
|
||||
|
||||
<div class="container__editor" onmousedown="hidectx()">
|
||||
<div class="container__left">
|
||||
<div id=tree>
|
||||
<div class="sub_div">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="resizer" id="dragMe"></div>
|
||||
<div class="container__right">
|
||||
<div class="toolbar">
|
||||
<input type="file" id="upload" name="upload" multiple hidden onChange="doUpload()">
|
||||
<span class="left"><button id="home">Home</button><button onClick="_('upload').click()">Upload</button><button id="save">Save</button></span>
|
||||
<div class="right">
|
||||
<input id="page" type="number" min="1" max="12" class="number">
|
||||
<button id="load">Reload Pages</button>
|
||||
<button id="init">Clear Pages</button>
|
||||
</div>
|
||||
<span class="left"><button id="cut">Cut</button><button id="copy">Copy</button><button id="paste">Paste</button></span>
|
||||
<span id="name">config.jsonl</span>
|
||||
<span class="left"><button id="undo">Undo</button><button id="redo">Redo</button></span>
|
||||
<span class="left"><select id="font">
|
||||
<option>JetBrains Mono</option>
|
||||
<option selected>Source Code Pro</option>
|
||||
<input id="fontsize" type="number" step="any" min="9" max="40" value="12"></input></span>
|
||||
</div>
|
||||
<div id="editor" class="container__bottom"></div>
|
||||
<div id="preview" class="container__bottom"><img id="pic" src="/static/logo.svg?COMMIT_HASH"/></div>
|
||||
<iframe id=download-frame></iframe>
|
||||
</div>
|
||||
<div id="ctx" onmousedown="event.stopPropagation()">
|
||||
<ul>
|
||||
<li><span class="icon file"></span>New File</li>
|
||||
<li><span class="icon edit"></span>Edit</li>
|
||||
<li><span class="icon eye"></span>Preview</li>
|
||||
<li><span class="icon download"></span>Download</li>
|
||||
<li><span class="icon trash"></span>Delete</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function _(id) { return document.getElementById(id) }
|
||||
function hidectx() { _("ctx").style.display = "none"; }
|
||||
|
||||
// https://www.kirupa.com/html5/detect_whether_font_is_installed.htm
|
||||
function doesFontExist(fontName) {
|
||||
// creating our in-memory Canvas element where the magic happens
|
||||
var canvas = document.createElement("canvas");
|
||||
var context = canvas.getContext("2d");
|
||||
|
||||
// the text whose final pixel size I want to measure
|
||||
var text = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
// specifying the baseline font
|
||||
context.font = "72px monospace";
|
||||
|
||||
// checking the size of the baseline text
|
||||
var baselineSize = context.measureText(text).width;
|
||||
|
||||
// specifying the font whose existence we want to check
|
||||
context.font = "72px '" + fontName + "', monospace";
|
||||
|
||||
// checking the size of the font we want to check
|
||||
var newSize = context.measureText(text).width;
|
||||
|
||||
// removing the Canvas element we created
|
||||
canvas = null;
|
||||
|
||||
//
|
||||
// If the size of the two text instances is the same, the font does not exist because it is being rendered
|
||||
// using the default sans-serif font
|
||||
//
|
||||
if (newSize == baselineSize) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function createEditor(id, path, lang, theme, mime) {
|
||||
function texttype(file) {
|
||||
let mode = "plain_text",
|
||||
ext = /(?:\.([^.]+))?$/.exec(file)[1];
|
||||
if (undefined !== typeof ext) {
|
||||
switch (ext) {
|
||||
// case "txt":
|
||||
//
|
||||
// return "plain";
|
||||
case "htm":
|
||||
case "html":
|
||||
return "html";
|
||||
case "js":
|
||||
return "javascript";
|
||||
case "cmd":
|
||||
case "json":
|
||||
case "jsonl":
|
||||
return "json";
|
||||
// case "c":
|
||||
// case "cpp":
|
||||
// return "c_cpp";
|
||||
case "css":
|
||||
case "svg":
|
||||
case "xml":
|
||||
// case "scss":
|
||||
// case "php":
|
||||
return ext;
|
||||
}
|
||||
}
|
||||
return mode
|
||||
}
|
||||
undefined === path && (path = "/"), undefined === lang && (lang = texttype(path)), undefined === mime && (mime = "text/" + lang);
|
||||
|
||||
/* Load optional modules from the CDN */
|
||||
const paths = ["basePath","modePath","themePath"];
|
||||
paths.forEach((p) => {
|
||||
ace.config.set(p, "https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.0");
|
||||
});
|
||||
|
||||
var editor = ace.edit(id, {
|
||||
useWorker: false,
|
||||
wrap: true,
|
||||
indentedSoftWrap: false,
|
||||
showPrintMargin: false,
|
||||
highlightGutterLine: true,
|
||||
setUseSoftTabs: true,
|
||||
tabSize: 2
|
||||
});
|
||||
editor.setFontSize(parseFloat(getComputedStyle(document.documentElement).fontSize));
|
||||
editor.on("focus", function() { _("ctx").style.display = "none" });
|
||||
|
||||
if (undefined === theme) theme = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? "monokai" : "textmate";
|
||||
|
||||
function j() {
|
||||
4 == req.readyState && 200 != req.status && alert("ERROR[" + req.status + "]: " + req.responseText)
|
||||
}
|
||||
|
||||
var saveBtn = _("save"),
|
||||
undoBtn = _("undo"),
|
||||
redoBtn = _("redo"),
|
||||
cutBtn = _("cut"),
|
||||
copyBtn = _("copy"),
|
||||
pasteBtn= _("paste"),
|
||||
fontSel = _("font"),
|
||||
// themeSel = _("theme"),
|
||||
sizeSel = _("fontsize"),
|
||||
isShown = _(id).display !== "none";
|
||||
sizeSel.value = parseFloat(editor.getFontSize()).toFixed(1);
|
||||
|
||||
function addFont(item, index) {
|
||||
if (doesFontExist(item)) {
|
||||
var option = document.createElement("option");
|
||||
option.text = item;
|
||||
fontSel.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
fontSel.onchange = function() { editor.setOption("fontFamily", "'" + fontSel.value + "',monospace") }
|
||||
// themeSel.onchange = function() { editor.setTheme("ace/theme/" + themeSel.value) }
|
||||
sizeSel.onchange = function () {
|
||||
var size = parseFloat(sizeSel.value);
|
||||
if (!isNaN(size) && size >= 9 && size <= 40) {
|
||||
editor.setFontSize(size);
|
||||
}
|
||||
sizeSel.value = parseFloat(editor.getFontSize()).toFixed(1);
|
||||
}
|
||||
|
||||
const monofonts = ["Courier New","Monaco","Lucida Console","Monospace","ui-monospace","Roboto Mono","Inconsolata","IBM Plex Mono","Space Mono","PT Mono","Ubuntu Mono","Nanum Gothic Coding",
|
||||
"Cousine","Fira Mono","Share Tech Mono","Courier Prime","Anonymous Pro","Cutive Mono","Overpass Mono","Fira Code","VT323","DM Mono","Oxygen Mono",
|
||||
"Nova Mono","B612 Mono","Spline Sans Mono","Noto Sans Mono","Major Mono Display","Azeret Mono","Red Hat Mono","Syne Mono","Xanh Mono"];
|
||||
monofonts.sort().forEach(addFont);
|
||||
|
||||
function updateCutCopy() {
|
||||
let state = !isShown || editor.session.getSelection().isEmpty();
|
||||
cutBtn.disabled = state;
|
||||
copyBtn.disabled = state;
|
||||
}
|
||||
function updateToolbar() {
|
||||
let undo = editor.session.getUndoManager();
|
||||
saveBtn.disabled = !isShown || undo.isClean();
|
||||
undoBtn.disabled = !isShown || !undo.hasUndo();
|
||||
redoBtn.disabled = !isShown || !undo.hasRedo();
|
||||
//updateCutCopy();
|
||||
}
|
||||
saveBtn !== null && undoBtn !== null && redoBtn !== null && editor.on("input", updateToolbar);
|
||||
editor.session.selection.on("changeCursor", updateCutCopy);
|
||||
|
||||
function getData(edtr) {
|
||||
var data = edtr.getValue();
|
||||
try {
|
||||
var json = JSON.parse(data);
|
||||
return JSON.stringify(json)
|
||||
} catch (error) {
|
||||
return data + ""
|
||||
}
|
||||
}
|
||||
|
||||
function save() {
|
||||
const d = getData(editor);
|
||||
const data = new FormData;
|
||||
data.append("data", new Blob([d], {
|
||||
type: mime
|
||||
}), path);
|
||||
|
||||
fetch('/edit', {
|
||||
method: "POST",
|
||||
body: data
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.text().then(text => { console.log('Save OK /edit ' + text); })
|
||||
}
|
||||
return response.text().then(text => { console.log('Save FAIL /edit'); throw new Error(text) })
|
||||
})
|
||||
.then((data) => {
|
||||
console.log(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn(error.name === "AbortError" ? "Promise Aborted" : "Promise Rejected");
|
||||
alert(error);
|
||||
})
|
||||
.finally(() => {
|
||||
updateToolbar();
|
||||
});
|
||||
}
|
||||
function paste() {
|
||||
try {
|
||||
navigator.clipboard.readText()
|
||||
.then((text) => {
|
||||
editor.execCommand("paste", text)
|
||||
})
|
||||
.catch((error) => {
|
||||
pasteBtn.disabled = true;
|
||||
})
|
||||
}
|
||||
catch {
|
||||
pasteBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
function copyToClipboard() {
|
||||
var text = editor.getCopyText();
|
||||
if (window.clipboardData && window.clipboardData.setData) {
|
||||
// Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
|
||||
return window.clipboardData.setData("Text", text);
|
||||
}
|
||||
else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
|
||||
editor.focus();
|
||||
try {
|
||||
return document.execCommand("copy"); // Security exception may be thrown by some browsers.
|
||||
}
|
||||
catch (ex) {
|
||||
console.warn("Copy to clipboard failed.", ex);
|
||||
return prompt("Copy to clipboard: Ctrl+C, Enter", text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveBtn.onclick = save;
|
||||
undoBtn.onclick = (e)=>{editor.undo() && editor.focus()}
|
||||
redoBtn.onclick = (e)=>{editor.redo() && editor.focus()}
|
||||
cutBtn.onclick = (e)=>{copyToClipboard() && editor.execCommand("cut")};
|
||||
copyBtn.onclick = (e)=>{copyToClipboard() && editor.execCommand("copy")};
|
||||
pasteBtn.onclick = paste;
|
||||
|
||||
function openfile(filename) {
|
||||
_("name").innerHTML = filename;
|
||||
res = fetch(filename)
|
||||
.then((response) => {
|
||||
if (response.ok) { console.log('OK '+filename); return response.text() }
|
||||
return response.text().then(text => { console.log('ERROR '+url); throw new Error(text) })
|
||||
})
|
||||
.then((data) => {
|
||||
try {
|
||||
var json = JSON.parse(data);
|
||||
editor.setValue(JSON.stringify(json, null, 4));
|
||||
console.log('parse json OK');
|
||||
} catch (error) {
|
||||
editor.setValue(data)
|
||||
console.log('parse json FAIL');
|
||||
}
|
||||
if (_("preview") !== null) _("preview").style.display = "none";
|
||||
if (_("editor") !== null) _("editor").style.display = "block";
|
||||
isShown = true;
|
||||
editor.resize();
|
||||
updateToolbar();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
alert(error);
|
||||
})
|
||||
.finally(() => {
|
||||
editor.resize(true),
|
||||
editor.scrollToLine(1, true, true, function() {}),
|
||||
editor.gotoLine(1, 0, true),
|
||||
editor.clearSelection(),
|
||||
editor.getSession().setUndoManager(new ace.UndoManager())
|
||||
});
|
||||
}
|
||||
editor.loadUrl = function(dirname,filename) {
|
||||
lang = texttype(path = dirname + filename),
|
||||
mime = "text/" + lang,
|
||||
"plain" !== lang && editor.getSession().setMode("ace/mode/" + lang),
|
||||
openfile(dirname+filename)
|
||||
}
|
||||
|
||||
return "plain" !== lang && editor.getSession().setMode("ace/mode/" + lang), editor.setTheme("ace/theme/" + theme), editor.$blockScrolling = 1 / 0,
|
||||
editor.commands.addCommand({
|
||||
name: "save",
|
||||
bindKey: {
|
||||
win: "Ctrl-S",
|
||||
mac: "Command-S"
|
||||
},
|
||||
exec: save,
|
||||
readOnly: false
|
||||
}), editor.commands.addCommand({
|
||||
name: "undo",
|
||||
bindKey: {
|
||||
win: "Ctrl-Z",
|
||||
mac: "Command-Z"
|
||||
},
|
||||
exec: function() { editor.undo() }
|
||||
}), editor.commands.addCommand({
|
||||
name: "redo",
|
||||
bindKey: {
|
||||
win: "Ctrl-Y",
|
||||
mac: "Command-Y"
|
||||
},
|
||||
exec: function() { editor.redo() }
|
||||
}), undefined !== path && openfile(path),
|
||||
editor.resize(),
|
||||
editor
|
||||
}
|
||||
h=createEditor("editor",undefined,undefined,undefined);
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Query the element
|
||||
const resizer = document.getElementById('dragMe');
|
||||
const leftSide = resizer.previousElementSibling;
|
||||
const rightSide = resizer.nextElementSibling;
|
||||
|
||||
// The current position of mouse
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let leftWidth = 0;
|
||||
|
||||
// Handle the mousedown event
|
||||
// that's triggered when user drags the resizer
|
||||
const mouseDownHandler = function (e) {
|
||||
// Get the current mouse position
|
||||
x = e.clientX;
|
||||
y = e.clientY;
|
||||
leftWidth = leftSide.getBoundingClientRect().width;
|
||||
// Attach the listeners to `document`
|
||||
document.addEventListener('mousemove', mouseMoveHandler);
|
||||
document.addEventListener('mouseup', mouseUpHandler);
|
||||
};
|
||||
|
||||
const mouseMoveHandler = function (e) {
|
||||
// How far the mouse has been moved
|
||||
const dx = e.clientX - x;
|
||||
const dy = e.clientY - y;
|
||||
|
||||
const newLeftWidth = ((leftWidth + dx) * 100) / resizer.parentNode.getBoundingClientRect().width;
|
||||
leftSide.style.width = `${newLeftWidth}%`;
|
||||
leftSide.style.right = leftSide.style.width;
|
||||
|
||||
resizer.style.cursor = 'col-resize';
|
||||
document.body.style.cursor = 'col-resize';
|
||||
|
||||
leftSide.style.userSelect = 'none';
|
||||
leftSide.style.pointerEvents = 'none';
|
||||
|
||||
rightSide.style.userSelect = 'none';
|
||||
rightSide.style.pointerEvents = 'none';
|
||||
|
||||
ace.edit("editor").resize();
|
||||
};
|
||||
|
||||
const mouseUpHandler = function () {
|
||||
resizer.style.removeProperty('cursor');
|
||||
document.body.style.removeProperty('cursor');
|
||||
|
||||
leftSide.style.removeProperty('user-select');
|
||||
leftSide.style.removeProperty('pointer-events');
|
||||
|
||||
rightSide.style.removeProperty('user-select');
|
||||
rightSide.style.removeProperty('pointer-events');
|
||||
|
||||
// Remove the handlers of `mousemove` and `mouseup`
|
||||
document.removeEventListener('mousemove', mouseMoveHandler);
|
||||
document.removeEventListener('mouseup', mouseUpHandler);
|
||||
};
|
||||
|
||||
// Attach the handler
|
||||
resizer.addEventListener('mousedown', mouseDownHandler);
|
||||
resizer.addEventListener('dblclick', () => {
|
||||
var show = leftSide.style.visibility = leftSide.style.visibility === 'hidden';
|
||||
leftSide.style.visibility = show ? 'unset' : 'hidden';
|
||||
leftSide.style.position = show ? 'unset' : 'absolute';
|
||||
ace.edit("editor").resize();
|
||||
})
|
||||
});
|
||||
|
||||
document.addEventListener('blur', function () { hidectx() });
|
||||
|
||||
var uploader;
|
||||
function checkUpload() {
|
||||
4 == uploader.readyState && (200 != uploader.status ? alert("ERROR[" + uploader.status + "]: " + uploader.responseText) : showEditor())
|
||||
}
|
||||
function doUpload() {
|
||||
const q = _('upload');
|
||||
if (0 !== q.files.length) {
|
||||
(uploader = new XMLHttpRequest).onreadystatechange = checkUpload;
|
||||
var data = new FormData;
|
||||
for (let i = 0; i < q.files.length; i++) {
|
||||
data.append("data", q.files[i], q.files[i].name)
|
||||
}
|
||||
uploader.open("POST", "/edit"), uploader.send(data)
|
||||
}
|
||||
}
|
||||
|
||||
function isFolder(model) {
|
||||
return model.children && model.children.length
|
||||
}
|
||||
function isText(model) {
|
||||
var a = /(?:\.([^.]+))?$/.exec(model.name)[1];
|
||||
if (void 0 !== typeof a) {
|
||||
switch (a) {
|
||||
case "txt": case "cmd": case "json": case "jsonl": case "htm": case "html": case "js": case "c": case "cpp": case "css": case "svg": case "xml": return !0
|
||||
}
|
||||
}
|
||||
return !1
|
||||
}
|
||||
function isImage(model) {
|
||||
var a = /(?:\.([^.]+))?$/.exec(model.name)[1];
|
||||
if (void 0 !== typeof a) {
|
||||
switch (a) {
|
||||
case "bmp": case "png": case "jpg": case "gif": case "svg": return !0
|
||||
}
|
||||
}
|
||||
return !1
|
||||
}
|
||||
function icon(model) {
|
||||
if (isFolder(model)) { return 'dir'}
|
||||
var a = /(?:\.([^.]+))?$/.exec(model.name)[1];
|
||||
if (void 0 !== typeof a) {
|
||||
switch (a) {
|
||||
case "cmd": case "css": case "json": case "jsonl": case "html": case "zip": case "txt": return a;
|
||||
case "gz": return 'zip';
|
||||
case "htm": return 'html';
|
||||
case "js": case "c": case "cpp": case "xml": return 'file';
|
||||
case "bmp": case "png": case "svg": case "jpg": case "gif": return 'image';
|
||||
}
|
||||
}
|
||||
return 'file';
|
||||
}
|
||||
function preview(model,path) {
|
||||
if (isImage(model)) {
|
||||
const pr = _("preview");
|
||||
const ed = _("editor");
|
||||
pr.innerHTML = '<img src="'+path+model.name+'?a='+Date.now()+'"/>';
|
||||
pr.style.display = "block";
|
||||
ed.style.display = "none"
|
||||
}
|
||||
}
|
||||
function edit(model,path) {
|
||||
if (isText(model)) {
|
||||
const pr = _("preview");
|
||||
const ed = _("editor");
|
||||
ed.style.display = "block";
|
||||
pr.style.display = "none";
|
||||
ace.edit("editor").loadUrl(path, model.name)
|
||||
}
|
||||
}
|
||||
function url(model,path) {
|
||||
console.log('click ' + path + model.name);
|
||||
if (isImage(model)) {
|
||||
preview(model,path);
|
||||
} else if (isText(model)) {
|
||||
edit(model,path);
|
||||
}
|
||||
}
|
||||
function fetchData(uri,method,data) {
|
||||
fetch(uri, { method: method, body: data })
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
console.log(method+' OK '+uri);
|
||||
return response.text()
|
||||
}
|
||||
return response.text().then(text => { console.log(method+' FAIL '+uri); throw new Error(text) })
|
||||
})
|
||||
.then((data) => {
|
||||
console.log(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn(error.name === "AbortError" ? "Promise Aborted" : "Promise Rejected");
|
||||
alert(error);
|
||||
})
|
||||
.finally(() => {
|
||||
});
|
||||
}
|
||||
function download(model,path) {
|
||||
console.log('download ' + path + model.name);
|
||||
document.getElementById("download-frame").src = path + model.name + "?download=true"
|
||||
}
|
||||
function remove(model,path,li) {
|
||||
console.log('remove ' + path + model.name);
|
||||
const data = new FormData;
|
||||
data.append("path", path + model.name);
|
||||
fetchData('/edit','DELETE', data);
|
||||
li.remove();
|
||||
}
|
||||
function create(path) {
|
||||
var name = window.prompt("Create File in "+path,"");
|
||||
if (name == null || name == "" || name.includes('/')) return;
|
||||
|
||||
const data = new FormData;
|
||||
data.append("path", path + name);
|
||||
this.fetchData('/edit','PUT', data);
|
||||
|
||||
fetch('/api/files/')
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
console.log(data)
|
||||
})
|
||||
}
|
||||
function ctx(e,model,path,li) {
|
||||
console.log('ctx ' + path + model+name);
|
||||
var c = _("ctx");
|
||||
c.style.display = "block";
|
||||
|
||||
let el;
|
||||
c.getElementsByTagName("li")[0].onclick = function() { hidectx(); create(path) };
|
||||
|
||||
el = c.getElementsByTagName("li")[1];
|
||||
el.onclick = function() { edit(model,path);hidectx() };
|
||||
el.style.display = isText(model) ? "block" : "none";
|
||||
|
||||
el = c.getElementsByTagName("li")[2];
|
||||
el.onclick = function() { preview(model,path);hidectx() };
|
||||
el.style.display = isImage(model) ? "block" : "none";
|
||||
|
||||
c.getElementsByTagName("li")[3].onclick = function() { download(model,path);hidectx() };
|
||||
c.getElementsByTagName("li")[4].onclick = function() { remove(model,path,li);hidectx() };
|
||||
|
||||
var dy = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
|
||||
var dx = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
|
||||
var x = e.clientX + dx +10;
|
||||
var y = e.clientY + dy -20;
|
||||
var ofw = c.offsetWidth;
|
||||
var ofh = c.offsetHeight;
|
||||
var doch = document.documentElement.clientHeight;
|
||||
if(y+ofh>doch) { y = doch-ofh-20}
|
||||
c.style.left = x + "px";
|
||||
c.style.top = y + "px";
|
||||
|
||||
console.log(e);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
function prepare() {
|
||||
listFiles(document.getElementsByClassName('sub_div')[0],null,'/');
|
||||
_("load").onclick = function(e) {
|
||||
const data = new FormData;
|
||||
data.append("load", "");
|
||||
fetchData('/edit','PUT', data);
|
||||
}
|
||||
_("init").onclick = function(e) {
|
||||
const data = new FormData;
|
||||
data.append("init", "");
|
||||
fetchData('/edit','PUT', data);
|
||||
}
|
||||
_("home").onclick = function(e) {
|
||||
window.location.href = "/"
|
||||
}
|
||||
_("page").onchange = function(e) {
|
||||
const data = new FormData;
|
||||
data.append("page", _('page').value);
|
||||
fetchData('/edit','PUT', data);
|
||||
}
|
||||
}
|
||||
|
||||
function listFiles(sd,div,p) {
|
||||
console.log('listFiles');
|
||||
fetch('/api/files/?dir='+p)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
// sd.removeChild(sd.firstElementChild);
|
||||
const ul = document.createElement("ul");
|
||||
sd.appendChild(ul);
|
||||
|
||||
div && (div.onclick = function(e) {
|
||||
ul.remove();
|
||||
div.onclick = function(e) {
|
||||
listFiles(sd,div,p);
|
||||
};
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
for (var i in data) {
|
||||
const obj = data[i];
|
||||
const name = obj.name;
|
||||
const path = p;
|
||||
const li = document.createElement("li");
|
||||
ul.appendChild(li);
|
||||
const div = document.createElement("div");
|
||||
li.appendChild(div);
|
||||
div.innerHTML = '<span class="fi fa-'+icon(data[i])+'" title="'+name+'"></span><span class="fn">'+name+'</span>';
|
||||
|
||||
if (isFolder(obj)) {
|
||||
div.classList.add("bold");
|
||||
div.onclick = function(e) {
|
||||
console.log(obj);
|
||||
listFiles(li,div,path+obj.name+'/');
|
||||
};
|
||||
continue;
|
||||
}
|
||||
|
||||
div.onclick = function(e) {
|
||||
console.log(obj);
|
||||
url(obj,path);
|
||||
};
|
||||
div.oncontextmenu = function(e) {
|
||||
console.log(obj);
|
||||
ctx(e,obj,path,li);
|
||||
};
|
||||
}
|
||||
ul.scrollIntoView()
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.2/ace.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.2/theme-monokai.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.2/mode-html.js"></script><script type="module" src="/static/main.js?COMMIT_HASH"></script><script src="/static/script.js?COMMIT_HASH"></script><title>openHASP File Editor</title><link rel="stylesheet" href="/static/vars.css?COMMIT_HASH"><link rel="stylesheet" href="/static/style.css?COMMIT_HASH"><link rel="icon" href="/static/logo.svg?COMMIT_HASH" type="image/svg+xml"><link href="https://fonts.cdnfonts.com/css/jetbrains-mono" rel="stylesheet"><link href="https://fonts.cdnfonts.com/css/source-code-pro" rel="stylesheet"><style>ul{list-style-type:none;padding-left:20px}ul>li{white-space:nowrap}.inact:hover{cursor:default}.item:hover{cursor:pointer;background-color:#dadaff}.item>span:nth-child(2):hover{text-decoration:underline}.selitem>div{background-color:#ccf}.selitem>div:hover{background-color:#ccf}</style></head><body v-cloak v-scope @vue:mounted="mounted"><div class="container__editor" onmousedown="hidectx()"><div class="container__left"><div id="tree"><div class="item bold"><span class="fi fa-flash" title="/"></span><span>L:</span></div></div></div><div class="resizer" id="dragMe"></div><div class="container__right"><div class="toolbar"><input type="file" id="upload" name="upload" multiple="multiple" hidden><span class="left"><button id="home">Home</button><button onclick='upload(_("tree"),"/")'>Upload</button><button id="save" disabled="disabled">Save</button></span><div class="right"><input id="page" type="number" min="1" max="12" class="number"><button id="load">Reload Pages</button><button id="init">Clear Pages</button></div><span class="left"><button id="cut" disabled="disabled">Cut</button><button id="copy" disabled="disabled">Copy</button><button id="paste" disabled="disabled">Paste</button></span><span id="name"></span><span class="left"><button id="undo" disabled="disabled">Undo</button><button id="redo" disabled="disabled">Redo</button></span><span class="left"><select id="font"><option>JetBrains Mono</option><option selected="selected">Source Code Pro</option><input id="fontsize" type="number" step="any" min="9" max="40" value="12"></span></div><div id="editor" class="container__bottom"></div><div id="preview" class="container__bottom"></div><iframe id="download-frame"></iframe></div><div id="ctx" onmousedown="event.stopPropagation()"><ul><li><span class="icon file"></span>New File</li><li><span class="icon upload"></span>Upload Files</li><li><span class="icon edit"></span>Edit</li><li><span class="icon eye"></span>Preview</li><li><span class="icon download"></span>Download</li><li><span class="icon trash"></span>Delete</li></ul></div></div><div id="toast"></div></body></html>
|
File diff suppressed because one or more lines are too long
134
data/script.js
134
data/script.js
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -9,6 +9,8 @@
|
||||
--star: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -6 16 16"><line y1="-3" y2="3" stroke="red" transform="rotate(15)"></line><line y1="-3" y2="3" stroke="red" transform="rotate(75)"></line><line y1="-3" y2="3" stroke="red" transform="rotate(-45)"></line></svg>');
|
||||
--trash: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-trash-can-outline" width="24" height="24" viewBox="0 0 24 24"><path d="M9,3V4H4V6H5V19A2,2 0 0,0 7,21H17A2,2 0 0,0 19,19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z" /></svg>');
|
||||
--download: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-download" width="24" height="24" viewBox="0 0 24 24"><path d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z" /></svg>');
|
||||
--upload: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-file-upload-outline" viewBox="0 0 24 24"><path d="M14,2L20,8V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2H14M18,20V9H13V4H6V20H18M12,12L16,16H13.5V19H10.5V16H8L12,12Z" /></svg>');
|
||||
--flash: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-chip" viewBox="0 0 24 24"><path d="M6,4H18V5H21V7H18V9H21V11H18V13H21V15H18V17H21V19H18V20H6V19H3V17H6V15H3V13H6V11H3V9H6V7H3V5H6V4M11,15V18H12V15H11M13,15V18H14V15H13M15,15V18H16V15H15Z" /></svg>');
|
||||
--file: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-file-outline" viewBox="0 0 24 24"><path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" /></svg>');
|
||||
--dir: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-folder-outline" viewBox="0 0 24 24"><path d="M20,18H4V8H20M20,6H12L10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6Z" /></svg>');
|
||||
--diropen: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-folder-open-outline" viewBox="0 0 24 24"><path d="M6.1,10L4,18V8H21A2,2 0 0,0 19,6H12L10,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H19C19.9,20 20.7,19.4 20.9,18.5L23.2,10H6.1M19,18H6L7.6,12H20.6L19,18Z" /></svg>');
|
||||
@ -17,8 +19,10 @@
|
||||
--zip: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-file-cabinet" viewBox="0 0 24 24"><path d="M14,8H10V6H14V8M20,4V20C20,21.11 19.11,22 18,22H6C4.89,22 4,21.11 4,20V4A2,2 0 0,1 6,2H18C19.11,2 20,2.9 20,4M18,13H6V20H18V13M18,4H6V11H18V4M14,15H10V17H14V15Z" /></svg>');
|
||||
--cmd: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-application-outline" viewBox="0 0 24 24"><path d="M21 2H3C1.9 2 1 2.9 1 4V20C1 21.1 1.9 22 3 22H21C22.1 22 23 21.1 23 20V4C23 2.9 22.1 2 21 2M21 20H3V6H21V20Z" /></svg>');
|
||||
--css: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-script-outline" viewBox="0 0 24 24"><path d="M15,20A1,1 0 0,0 16,19V4H8A1,1 0 0,0 7,5V16H5V5A3,3 0 0,1 8,2H19A3,3 0 0,1 22,5V6H20V5A1,1 0 0,0 19,4A1,1 0 0,0 18,5V9L18,19A3,3 0 0,1 15,22H5A3,3 0 0,1 2,19V18H13A2,2 0 0,0 15,20Z" /></svg>');
|
||||
--ttf: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-format-text" viewBox="0 0 24 24"><path d="M18.5,4L19.66,8.35L18.7,8.61C18.25,7.74 17.79,6.87 17.26,6.43C16.73,6 16.11,6 15.5,6H13V16.5C13,17 13,17.5 13.33,17.75C13.67,18 14.33,18 15,18V19H9V18C9.67,18 10.33,18 10.67,17.75C11,17.5 11,17 11,16.5V6H8.5C7.89,6 7.27,6 6.74,6.43C6.21,6.87 5.75,7.74 5.3,8.61L4.34,8.35L5.5,4H18.5Z" /></svg>');
|
||||
--eye: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-eye-outline" viewBox="0 0 24 24"><path d="M12,9A3,3 0 0,1 15,12A3,3 0 0,1 12,15A3,3 0 0,1 9,12A3,3 0 0,1 12,9M12,4.5C17,4.5 21.27,7.61 23,12C21.27,16.39 17,19.5 12,19.5C7,19.5 2.73,16.39 1,12C2.73,7.61 7,4.5 12,4.5M3.18,12C4.83,15.36 8.24,17.5 12,17.5C15.76,17.5 19.17,15.36 20.82,12C19.17,8.64 15.76,6.5 12,6.5C8.24,6.5 4.83,8.64 3.18,12Z" /></svg>');
|
||||
--json: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-code-braces" viewBox="0 0 24 24"><path d="M8,3A2,2 0 0,0 6,5V9A2,2 0 0,1 4,11H3V13H4A2,2 0 0,1 6,15V19A2,2 0 0,0 8,21H10V19H8V14A2,2 0 0,0 6,12A2,2 0 0,0 8,10V5H10V3M16,3A2,2 0 0,1 18,5V9A2,2 0 0,0 20,11H21V13H20A2,2 0 0,0 18,15V19A2,2 0 0,1 16,21H14V19H16V14A2,2 0 0,1 18,12A2,2 0 0,1 16,10V5H14V3H16Z" /></svg>');
|
||||
--audio: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" id="mdi-file-music-outline" viewBox="0 0 24 24"><path d="M14,2L20,8V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2H14M18,20V9H13V4H6V20H18M13,10V12H11V17A2,2 0 0,1 9,19A2,2 0 0,1 7,17A2,2 0 0,1 9,15C9.4,15 9.7,15.1 10,15.3V10H13Z" /></svg>');
|
||||
}
|
||||
|
||||
.fn:hover {
|
||||
@ -57,12 +61,14 @@
|
||||
.fa-browse { mask-image: var(--browse); -webkit-mask-image: var(--browse)}
|
||||
.fa-cog { mask-image: var(--cog); -webkit-mask-image: var(--cog)}
|
||||
.fa-download{ mask-image: var(--download); -webkit-mask-image: var(--download)}
|
||||
.fa-upload { mask-image: var(--upload); -webkit-mask-image: var(--upload)}
|
||||
.fa-home { mask-image: var(--home); -webkit-mask-image: var(--home)}
|
||||
.fa-info { mask-image: var(--info); -webkit-mask-image: var(--info)}
|
||||
.fa-ota { mask-image: var(--ota); -webkit-mask-image: var(--ota)}
|
||||
.fa-shot { mask-image: var(--shot); -webkit-mask-image: var(--shot)}
|
||||
.fa-star { mask-image: var(--star); -webkit-mask-image: var(--star)}
|
||||
.fa-trash { mask-image: var(--trash); -webkit-mask-image: var(--trask)}
|
||||
.fa-flash { mask-image: var(--flash); -webkit-mask-image: var(--flash)}
|
||||
.fa-file { mask-image: var(--file); -webkit-mask-image: var(--file)}
|
||||
.fa-dir { mask-image: var(--dir); -webkit-mask-image: var(--dir)}
|
||||
.fa-diropen { mask-image: var(--diropen); -webkit-mask-image: var(--diropen)}
|
||||
@ -73,7 +79,9 @@
|
||||
.fa-json { mask-image: var(--json); -webkit-mask-image: var(--json)}
|
||||
.fa-jsonl { mask-image: var(--json); -webkit-mask-image: var(--json)}
|
||||
.fa-image { mask-image: var(--image); -webkit-mask-image: var(--image)}
|
||||
.fa-audio { mask-image: var(--audio); -webkit-mask-image: var(--audio)}
|
||||
.fa-html { mask-image: var(--html); -webkit-mask-image: var(--html)}
|
||||
.fa-ttf { mask-image: var(--ttf); -webkit-mask-image: var(--ttf)}
|
||||
|
||||
.nav-list {
|
||||
font-size: var(--fs-nav);
|
||||
@ -455,6 +463,7 @@ a.foot:visited {
|
||||
justify-content: left;
|
||||
overflow-x: clip;
|
||||
overflow-y: scroll;
|
||||
background-color: var(--treebg);
|
||||
|
||||
/* Popout */
|
||||
top: 0;
|
||||
@ -479,8 +488,7 @@ a.foot:visited {
|
||||
/* Misc */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
background-color: var(--grpbg)
|
||||
background-color: #888;
|
||||
}
|
||||
.toolbar {
|
||||
text-align: center;
|
||||
@ -519,9 +527,7 @@ a.foot:visited {
|
||||
#ctx > ul {
|
||||
padding-left: 0px;
|
||||
}
|
||||
#ctx > ul > li,
|
||||
.sub_div > ul > li {
|
||||
cursor: pointer;
|
||||
#ctx > ul > li {
|
||||
white-space: nowrap
|
||||
}
|
||||
#ctx > ul > li:hover {
|
||||
@ -531,8 +537,7 @@ a.foot:visited {
|
||||
width: 3rem
|
||||
}
|
||||
#preview {
|
||||
background-color: #888;
|
||||
padding: 5px;
|
||||
padding: 0.3rem;
|
||||
overflow: scroll;
|
||||
}
|
||||
#preview > img {
|
||||
@ -550,10 +555,11 @@ a.foot:visited {
|
||||
width: 100%;
|
||||
line-height: 1.3rem;
|
||||
font-size: 0.95rem;
|
||||
background-color: var(--treebg)
|
||||
}
|
||||
.download{background-image: var(--download)}
|
||||
.upload{background-image: var(--upload)}
|
||||
.eye{background-image: var(--eye)}
|
||||
.flash{background-image: var(--flash)}
|
||||
.file{background-image: var(--file)}
|
||||
.zip{background-image: var(--zip)}
|
||||
.css{background-image: var(--css)}
|
||||
@ -561,6 +567,41 @@ a.foot:visited {
|
||||
.json{background-image: var(--json)}
|
||||
.jsonl{background-image: var(--json)}
|
||||
.image{background-image: var(--image)}
|
||||
.audio{background-image: var(--audio)}
|
||||
.html{background-image: var(--html)}
|
||||
.dir{background-image: var(--dir)}
|
||||
.diropen{background-image: var(--diropen)}
|
||||
|
||||
|
||||
#toast {
|
||||
position: fixed;
|
||||
bottom: 1rem;
|
||||
right: 1.5rem;
|
||||
display: grid;
|
||||
align-items: end;
|
||||
align-content: end;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.toast {
|
||||
font-size: 1rem;
|
||||
margin: 0;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
padding: 0.5em 1em;
|
||||
background-color: lightblue;
|
||||
animation: toastIt 3000ms cubic-bezier(0.785, 0.135, 0.15, 0.86) forwards;
|
||||
}
|
||||
|
||||
@keyframes toastIt {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(150%);
|
||||
opacity: 0;
|
||||
}
|
||||
10%,
|
||||
90% {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
@ -80,16 +80,16 @@ extern const uint8_t SCRIPT_JS_GZ_START[] asm("_binary_data_static_script_js_gz_
|
||||
extern const uint8_t SCRIPT_JS_GZ_END[] asm("_binary_data_static_script_js_gz_end");
|
||||
extern const uint8_t LOGO_SVG_GZ_START[] asm("_binary_data_static_logo_svg_gz_start");
|
||||
extern const uint8_t LOGO_SVG_GZ_END[] asm("_binary_data_static_logo_svg_gz_end");
|
||||
extern const uint8_t ACE_JS_GZ_START[] asm("_binary_data_static_ace_1_9_6_min_js_gz_start");
|
||||
extern const uint8_t ACE_JS_GZ_END[] asm("_binary_data_static_ace_1_9_6_min_js_gz_end");
|
||||
extern const uint8_t PETITE_VUE_HASP_JS_GZ_START[] asm("_binary_data_static_petite_vue_hasp_js_gz_start");
|
||||
extern const uint8_t PETITE_VUE_HASP_JS_GZ_END[] asm("_binary_data_static_petite_vue_hasp_js_gz_end");
|
||||
extern const uint8_t MAIN_JS_GZ_START[] asm("_binary_data_static_main_js_gz_start");
|
||||
extern const uint8_t MAIN_JS_GZ_END[] asm("_binary_data_static_main_js_gz_end");
|
||||
extern const uint8_t EN_JSON_GZ_START[] asm("_binary_data_static_en_json_gz_start");
|
||||
extern const uint8_t EN_JSON_GZ_END[] asm("_binary_data_static_en_json_gz_end");
|
||||
extern const uint8_t HASP_HTM_GZ_START[] asm("_binary_data_static_hasp_htm_gz_start");
|
||||
extern const uint8_t HASP_HTM_GZ_END[] asm("_binary_data_static_hasp_htm_gz_end");
|
||||
// extern const uint8_t HASP_HTM_GZ_START[] asm("_binary_data_static_hasp_htm_gz_start");
|
||||
// extern const uint8_t HASP_HTM_GZ_END[] asm("_binary_data_static_hasp_htm_gz_end");
|
||||
// extern const uint8_t ACE_JS_GZ_START[] asm("_binary_data_static_ace_1_9_6_min_js_gz_start");
|
||||
// extern const uint8_t ACE_JS_GZ_END[] asm("_binary_data_static_ace_1_9_6_min_js_gz_end");
|
||||
|
||||
#endif // CONFIG_IDF_TARGET_ESP32
|
||||
|
||||
@ -1218,22 +1218,31 @@ static void handleFileDelete()
|
||||
{
|
||||
if(!http_is_authenticated(F("filedelete"))) return;
|
||||
|
||||
char mimetype[16];
|
||||
snprintf_P(mimetype, sizeof(mimetype), PSTR("text/plain"));
|
||||
const char mimetype[] = "text/plain";
|
||||
|
||||
if(webServer.args() == 0) {
|
||||
return webServer.send_P(500, mimetype, PSTR("BAD ARGS"));
|
||||
if(!webServer.hasArg("path")) {
|
||||
return webServer.send(500, mimetype, "BAD ARGS");
|
||||
}
|
||||
String path = webServer.arg(0);
|
||||
String path = webServer.arg("path");
|
||||
LOG_TRACE(TAG_HTTP, F("handleFileDelete: %s"), path.c_str());
|
||||
if(path == "/") {
|
||||
return webServer.send_P(500, mimetype, PSTR("BAD PATH"));
|
||||
return webServer.send(500, mimetype, "BAD PATH");
|
||||
}
|
||||
if(!HASP_FS.exists(path)) {
|
||||
return webServer.send_P(404, mimetype, PSTR("FileNotFound"));
|
||||
return webServer.send(404, mimetype, "FileNotFound");
|
||||
}
|
||||
bool result;
|
||||
if(path.endsWith("/")) {
|
||||
path.remove(path.length() - 1);
|
||||
result = HASP_FS.rmdir(path);
|
||||
} else {
|
||||
result = HASP_FS.remove(path);
|
||||
}
|
||||
if(result) {
|
||||
webServer.send(200, mimetype, String(""));
|
||||
} else {
|
||||
webServer.send(405, mimetype, "RemoveFailed");
|
||||
}
|
||||
HASP_FS.remove(path);
|
||||
webServer.send(200, mimetype, String(""));
|
||||
}
|
||||
|
||||
static void handleFileCreate()
|
||||
@ -2275,16 +2284,16 @@ static inline int handleFirmwareFile(String path)
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
if(path == F("/edit.htm")) {
|
||||
return http_send_static_gzip_file(EDIT_HTM_GZ_START, EDIT_HTM_GZ_END, contentType);
|
||||
} else if(path == F("/hasp.htm")) { // 39 kB
|
||||
return http_send_static_gzip_file(HASP_HTM_GZ_START, HASP_HTM_GZ_END, contentType);
|
||||
// } else if(path == F("/hasp.htm")) { // 39 kB
|
||||
// return http_send_static_gzip_file(HASP_HTM_GZ_START, HASP_HTM_GZ_END, contentType);
|
||||
} else if(path == F("/logo.svg")) { // 300 bytes
|
||||
return http_send_static_gzip_file(LOGO_SVG_GZ_START, LOGO_SVG_GZ_END, contentType);
|
||||
} else if(path == F("/style.css")) { // 11 kB
|
||||
return http_send_static_gzip_file(STYLE_CSS_GZ_START, STYLE_CSS_GZ_END, contentType);
|
||||
} else if(path == F("/vars.css")) {
|
||||
return http_send_static_file(HTTP_VARS_CSS, HTTP_VARS_CSS + sizeof(HTTP_VARS_CSS) - 1, contentType);
|
||||
// } else if(path == F("/script.js")) { // 3 kB
|
||||
// return http_send_static_gzip_file(SCRIPT_JS_GZ_START, SCRIPT_JS_GZ_END, contentType);
|
||||
} else if(path == F("/script.js")) { // 3 kB
|
||||
return http_send_static_gzip_file(SCRIPT_JS_GZ_START, SCRIPT_JS_GZ_END, contentType);
|
||||
} else if(path == F("/en.json")) { // 2 kB
|
||||
return http_send_static_gzip_file(EN_JSON_GZ_START, EN_JSON_GZ_END, contentType);
|
||||
} else if(path == F("/main.js")) { // 9 kB
|
||||
@ -2292,8 +2301,8 @@ static inline int handleFirmwareFile(String path)
|
||||
} else if(path == F("/petite-vue.hasp.js")) { // 9 kB
|
||||
return http_send_static_gzip_file(PETITE_VUE_HASP_JS_GZ_START, PETITE_VUE_HASP_JS_GZ_END, contentType);
|
||||
#if ESP_FLASH_SIZE > 4
|
||||
} else if(path == F("/ace.js")) { // 96 kB
|
||||
return http_send_static_gzip_file(ACE_JS_GZ_START, ACE_JS_GZ_END, contentType);
|
||||
// } else if(path == F("/ace.js")) { // 96 kB
|
||||
// return http_send_static_gzip_file(ACE_JS_GZ_START, ACE_JS_GZ_END, contentType);
|
||||
#endif
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
@ -48,3 +48,21 @@ with open("data/main.js", "r", encoding="utf-8") as f:
|
||||
html = html.replace("COMMIT_HASH", commit_hash)
|
||||
with gzip.open('data/static/main.js.gz', 'wb') as f:
|
||||
f.write(html.encode('utf-8'))
|
||||
|
||||
with open("data/script.js", "r", encoding="utf-8") as f:
|
||||
html=f.read()
|
||||
html = html.replace("COMMIT_HASH", commit_hash)
|
||||
with gzip.open('data/static/script.js.gz', 'wb') as f:
|
||||
f.write(html.encode('utf-8'))
|
||||
|
||||
with open("data/en.json", "r", encoding="utf-8") as f:
|
||||
html=f.read()
|
||||
html = html.replace("COMMIT_HASH", commit_hash)
|
||||
with gzip.open('data/static/en.json.gz', 'wb') as f:
|
||||
f.write(html.encode('utf-8'))
|
||||
|
||||
with open("data/style.css", "r", encoding="utf-8") as f:
|
||||
html=f.read()
|
||||
html = html.replace("COMMIT_HASH", commit_hash)
|
||||
with gzip.open('data/static/style.css.gz', 'wb') as f:
|
||||
f.write(html.encode('utf-8'))
|
||||
|
@ -58,10 +58,11 @@ def copy_merge_bins(source, target, env):
|
||||
|
||||
mcu = board.get("build.mcu", "esp32")
|
||||
bootloader = "{}tools{}sdk{}{}{}bin{}bootloader_{}_{}.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, mcu, os.path.sep, os.path.sep, flash_mode, flash_freq)
|
||||
# # if not os.path.isfile(bootloader):
|
||||
# # bootloader = "{}tools{}sdk{}bin{}bootloader_dio_40m.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep, os.path.sep, os.path.sep)
|
||||
# if not os.path.isfile(bootloader):
|
||||
# bootloader = "{}tools{}sdk{}bin{}bootloader_dio_40m.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep, os.path.sep, os.path.sep)
|
||||
if not os.path.isfile(bootloader):
|
||||
bootloader = "{}tools{}sdk{}{}{}bin{}bootloader_{}_{}.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, mcu, os.path.sep, os.path.sep, flash_mode, flash_freq)
|
||||
# bootloader = "{}tools{}sdk{}{}{}bin{}bootloader_{}_{}.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, mcu, os.path.sep, os.path.sep, flash_mode, flash_freq)
|
||||
bootloader = str(target[0]).replace('firmware.bin','bootloader.bin')
|
||||
bootloader_location = '0x1000'
|
||||
if (mcu == 'esp32s3'):
|
||||
bootloader_location = '0x0000'
|
||||
@ -94,7 +95,10 @@ def copy_merge_bins(source, target, env):
|
||||
print(f_flash)
|
||||
print(flash_mode)
|
||||
|
||||
process = subprocess.Popen(['python', 'tools/esptool_with_merge_bin.py', '--chip', mcu, 'merge_bin', '--output', firmware_dst, '--flash_mode', 'dio', '--flash_size', flash_size, '--flash_freq', flash_freq, bootloader_location, bootloader, '0x8000', partitions, '0xe000', boot_app0, '0x10000', firmware_src],
|
||||
# esptool = 'tools/esptool_with_merge_bin.py'
|
||||
esptool = '{}{}esptool.py'.format(platform.get_package_dir("tool-esptoolpy"),os.path.sep)
|
||||
print(esptool)
|
||||
process = subprocess.Popen(['python', esptool, '--chip', mcu, 'merge_bin', '--output', firmware_dst, '--flash_mode', 'dio', '--flash_size', flash_size, '--flash_freq', flash_freq, bootloader_location, bootloader, '0x8000', partitions, '0xe000', boot_app0, '0x10000', firmware_src],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
|
69
tools/minifiy.py
Normal file
69
tools/minifiy.py
Normal file
@ -0,0 +1,69 @@
|
||||
import gzip, minify_html
|
||||
|
||||
# options = {
|
||||
# "do_not_minify_doctype": True,
|
||||
# "ensure_spec_compliant_unquoted_attribute_values": False,
|
||||
# "keep_closing_tags": True,
|
||||
# "keep_html_and_head_opening_tags": True,
|
||||
# "keep_spaces_between_attributes": True,
|
||||
# "keep_comments": True,
|
||||
# "minify_css": True,
|
||||
# "minify_js": True,
|
||||
# "remove_bangs": False,
|
||||
# "remove_processing_instructions": False
|
||||
# }
|
||||
|
||||
# with open("data/script.js", "r") as f:
|
||||
# html=f.read()
|
||||
# minified = minify_html.minify(html, options)
|
||||
# with gzip.open('data/static/script.js.gz', 'wb') as f:
|
||||
# f.write(minified.encode('utf-8'))
|
||||
|
||||
# with open("data/editor.htm", "r") as f:
|
||||
# html=f.read()
|
||||
# # minified = minify_html.minify(html, options)
|
||||
# with gzip.open('data/static/edit.htm.gz', 'wb') as f:
|
||||
# f.write(html.encode('utf-8'))
|
||||
# with open('data/edit.htm', 'wb') as f:
|
||||
# f.write(html.encode('utf-8'))
|
||||
|
||||
|
||||
# with open("data/style.css", "r") as f:
|
||||
# html=f.read()
|
||||
# with gzip.open('data/static/style.css.gz', 'wb') as f:
|
||||
# f.write(html.encode('utf-8'))
|
||||
# minified = minify_html.minify(html, options).replace('"id=mdi-','" id=mdi-')
|
||||
# with open('data/style.min.css', 'wb') as f:
|
||||
# f.write(minified.encode('utf-8'))
|
||||
|
||||
|
||||
# with open("data/hasp.htm", "r") as f:
|
||||
# html=f.read()
|
||||
# minified = minify_html.minify(html, options)
|
||||
# with gzip.open('data/static/hasp.htm.gz', 'wb') as f:
|
||||
# f.write(minified.encode('utf-8'))
|
||||
|
||||
|
||||
|
||||
# with open("data/en.json", "r") as f:
|
||||
# html=f.read()
|
||||
# minified = minify_html.minify(html, options)
|
||||
# with gzip.open('data/static/en.json.gz', 'wb') as f:
|
||||
# f.write(minified.encode('utf-8'))
|
||||
|
||||
# with open("data/nl.json", "r") as f:
|
||||
# html=f.read()
|
||||
# minified = minify_html.minify(html, options)
|
||||
# with gzip.open('data/static/nl.json.gz', 'wb') as f:
|
||||
# f.write(minified.encode('utf-8'))
|
||||
|
||||
# with open("data/fr.json", "r") as f:
|
||||
# html=f.read()
|
||||
# minified = minify_html.minify(html, options)
|
||||
# with gzip.open('data/static/fr.json.gz', 'wb') as f:
|
||||
# f.write(minified.encode('utf-8'))
|
||||
|
||||
# with open("data/main.js", "r") as f:
|
||||
# html=f.read()
|
||||
# with gzip.open('data/static/main.js.gz', 'wb') as f:
|
||||
# f.write(html.encode('utf-8'))
|
@ -23,11 +23,11 @@ board_build.embed_files =
|
||||
data/cert/x509_crt_bundle.bin
|
||||
; -- new dynamic website files -------------------
|
||||
data/static/logo.svg.gz
|
||||
data/static/ace.1.9.6.min.js.gz
|
||||
; data/static/ace.1.9.6.min.js.gz
|
||||
data/static/petite-vue.hasp.js.gz
|
||||
data/static/main.js.gz
|
||||
data/static/en.json.gz
|
||||
data/static/hasp.htm.gz
|
||||
; data/static/hasp.htm.gz
|
||||
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
|
Loading…
x
Reference in New Issue
Block a user