Version 1.1.0 - Ajout de la compatibilité des images
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
This commit is contained in:
parent
460f47683c
commit
0ffcafdf3f
11
bin/files.js
11
bin/files.js
@ -163,8 +163,15 @@ module.exports.getFile = function(root) {
|
|||||||
if(fs.existsSync(root)) {
|
if(fs.existsSync(root)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return fs.readFileSync(root, "utf-8")
|
// Check if the file is an image and if it is return the base64
|
||||||
|
if(mime.lookup(root).includes("image")) {
|
||||||
|
return "data:" + mime.lookup(root) + ";base64," + fs.readFileSync(root, "base64")
|
||||||
|
} else {
|
||||||
|
return fs.readFileSync(root, "utf-8")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
return "NOT_PERMITTED"
|
return "NOT_PERMITTED"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "neutral",
|
"name": "neutral",
|
||||||
"version": "1.0.3",
|
"version": "1.1.0",
|
||||||
"description": "Panel d'administration de Raphix",
|
"description": "Panel d'administration de Raphix",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -590,6 +590,7 @@ explorer.createWindow(() => {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Make Download using result
|
// Make Download using result
|
||||||
|
|
||||||
const element = document.createElement('a');
|
const element = document.createElement('a');
|
||||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(result));
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(result));
|
||||||
element.setAttribute('download', file.name);
|
element.setAttribute('download', file.name);
|
||||||
@ -597,7 +598,6 @@ explorer.createWindow(() => {
|
|||||||
document.body.appendChild(element);
|
document.body.appendChild(element);
|
||||||
element.click();
|
element.click();
|
||||||
document.body.removeChild(element);
|
document.body.removeChild(element);
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -614,7 +614,15 @@ explorer.createWindow(() => {
|
|||||||
|
|
||||||
function editFile() {
|
function editFile() {
|
||||||
const reqFiles = post("FX_GETFILE", file.fileDirectory)
|
const reqFiles = post("FX_GETFILE", file.fileDirectory)
|
||||||
|
//Create a popup for the loading
|
||||||
|
|
||||||
|
View.createPopup({
|
||||||
|
title: `<i class='fa-solid fa-file-pen'></i> Editeur`,
|
||||||
|
content: `<p><i class='fa-solid fa-rotate fa-spin'></i> Chargement en cours ...</p>`
|
||||||
|
})
|
||||||
|
|
||||||
reqFiles.then((result) => {
|
reqFiles.then((result) => {
|
||||||
|
View.destroyPopup(`<i class='fa-solid fa-file-pen'></i> Editeur}`)
|
||||||
if(result == "NOT_PERMITTED") {
|
if(result == "NOT_PERMITTED") {
|
||||||
View.createPopup({
|
View.createPopup({
|
||||||
title: `<i class='fa fa-warning'></i> Erreur`,
|
title: `<i class='fa fa-warning'></i> Erreur`,
|
||||||
@ -624,58 +632,65 @@ explorer.createWindow(() => {
|
|||||||
const editor = new ViewWindow({
|
const editor = new ViewWindow({
|
||||||
title: `<i class="fa-solid fa-file-pen"></i> Editeur - ${file.fileDirectory}`,
|
title: `<i class="fa-solid fa-file-pen"></i> Editeur - ${file.fileDirectory}`,
|
||||||
width: "1000px",
|
width: "1000px",
|
||||||
height: "600px"
|
height: "650px"
|
||||||
})
|
})
|
||||||
|
|
||||||
editor.setContent(`
|
|
||||||
|
if(file.type == "image/png" | file.type == "image/jpeg") {
|
||||||
|
editor.setContent(`
|
||||||
|
<div style='width: 100%; text-align: center;'>
|
||||||
|
<img style='width: 500px;' src='${result}'/>
|
||||||
|
</div>`)
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
editor.setContent(`
|
||||||
|
|
||||||
<div class='fx-bar'>
|
<div class='fx-bar'>
|
||||||
<span id='${editor.getViewTitle()}_save' class='btn-cover'><i class='fa fa-save'></i></span>
|
<span id='${editor.getViewTitle()}_save' class='btn-cover'><i class='fa fa-save'></i></span>
|
||||||
</div>
|
</div>
|
||||||
<textarea id='${editor.getViewTitle()}_editorContent' class='fx-editor-content'>${result}</textarea>
|
<textarea id='${editor.getViewTitle()}_editorContent' class='fx-editor-content'>${result}</textarea>
|
||||||
|
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
const editorSave = getID(editor.getViewTitle() + "_save")
|
||||||
const editorSave = getID(editor.getViewTitle() + "_save")
|
const editorContent = getID(editor.getViewTitle() + "_editorContent")
|
||||||
const editorContent = getID(editor.getViewTitle() + "_editorContent")
|
|
||||||
|
|
||||||
// Sauvegarder le fichier en l'envoyant
|
// Sauvegarder le fichier en l'envoyant
|
||||||
|
|
||||||
editorSave.addEventListener("click", () => {
|
editorSave.addEventListener("click", () => {
|
||||||
|
|
||||||
const reqFiles = post("FX_SAVEFILE", {root: files.root, name: file.name, content: editorContent.value})
|
const reqFiles = post("FX_SAVEFILE", {root: files.root, name: file.name, content: editorContent.value})
|
||||||
reqFiles.then((result) => {
|
reqFiles.then((result) => {
|
||||||
if(result == "OK") {
|
if(result == "OK") {
|
||||||
editor.destroy()
|
editor.destroy()
|
||||||
const reqFiles = post("FX_GET", files.root)
|
const reqFiles = post("FX_GET", files.root)
|
||||||
reqFiles.then((result) => {
|
reqFiles.then((result) => {
|
||||||
loadFiles(result)
|
loadFiles(result)
|
||||||
})
|
})
|
||||||
} else if(result == "NOT_PERMITTED") {
|
} else if(result == "NOT_PERMITTED") {
|
||||||
editor.createPopup({
|
editor.createPopup({
|
||||||
title: `<i class='fa fa-warning'></i> Erreur`,
|
title: `<i class='fa fa-warning'></i> Erreur`,
|
||||||
content: `<p class='yellow'>Vous n'avez pas les permissions pour éditer ce fichier.</p>`
|
content: `<p class='yellow'>Vous n'avez pas les permissions pour éditer ce fichier.</p>`
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
editor.createPopup({
|
editor.createPopup({
|
||||||
title: `<i class='fa fa-warning'></i> Erreur`,
|
title: `<i class='fa fa-warning'></i> Erreur`,
|
||||||
content: `<p class='yellow'>Une erreur est survenue.</p>`
|
content: `<p class='yellow'>Une erreur est survenue.</p>`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//forbid textarea resize
|
//forbid textarea resize
|
||||||
editorContent.style.resize = "none"
|
editorContent.style.resize = "none"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user