document.addEventListener("contextmenu", (e) => { e.preventDefault() }) function generateFileExplorer() { const View = new ViewWindow({ title: ` Gestionnaire de fichiers`, width: "1000px", height: "600px" }) goHomePath() function goHomePath() { const rFiles = post("FX_GET", "homepath") rFiles.then((result) => { loadFiles(result) }) } View.setContent(`
`) const rootInput = getID(View.getViewTitle() + '_rootInput') const explorer = getID(View.getViewTitle() + '_explorer') rootInput.addEventListener("change", () => { const reqFiles = post("FX_GET", rootInput.value) reqFiles.then((result) => { loadFiles(result) }) }) function loadFiles(files) { rootInput.value = files.root var fileElements = new Array() if(files.content == "NOT_PERMITTED") { fileElements.unshift(`

Revenir au dossier parent

`) fileElements.push("

Vous n'avez pas les permissions pour accéder à ce dossier.

") } else if(files.content == "NOT_EXIST") { fileElements.unshift(`

Revenir au dossier parent

`) explorer.innerHTML = "

Ce dossier n'existe pas.

" } else { fileElements.unshift(`

Revenir au dossier parent

`) for(const file of files.content) { // Convert all file.size to a human readable format with units file.size = bytesToSize(file.size) //Tell if the file is a directory or not if(file.directory) { file.size = "Dossier" } fileElements.push(`
${getIcon(file)}

${file.name}

Taille : ${file.size}

Date de modification : ${getFormattedDate(file.lastedition)}

`) } } explorer.innerHTML = fileElements.join("") const parent = document.getElementById("fx-parent") const home = document.getElementById("fx-home") home.addEventListener("click", () => { goHomePath() }) parent.addEventListener("click", () => { const reqFiles = post("FX_GET", files.parent) reqFiles.then((result) => { loadFiles(result) }) }) if(files.content != "NOT_PERMITTED" && files.content != "NOT_EXIST") { // If it's a directory, get the file directory and make the request to get the files in it and loadIt for(const file of files.content) { if(file.directory) { const element = document.getElementById(file.id) element.addEventListener("click", () => { const reqFiles = post("FX_GET", file.fileDirectory) reqFiles.then((result) => { loadFiles(result) }) }) } } } } } function createFileMenu(idCreated) { const dropMenu = new DroppableMenu({ "id": idCreated }) dropMenu.add("rename", " Renommer") dropMenu.add("share", " Partager") dropMenu.add("delete", " Supprimer") dropMenu.show() } function getIcon(file) { if(file.type == "application/json") { return '' } if(file.type == "application/msword" | file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { return '' } if(file.type == "application/vnd.ms-powerpoint") { return '' } if(file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | file.type == "application/vnd.ms-excel") { return '' } if(file.type == "application/java-archive") { return '' } if(file.type == "application/x-sh") { return '' } if(file.type == "application/x-msdos-program" | file.type == "application/x-msdownload") { return'' } if(file.type == "application/javascript") { return '' } if(file.type == "image/png" | file.type == "image/jpeg") { return '' } if(file.type == "text/html") { return '' } if(file.type == "text/css") { return '' } if(file.type == "application/zip") { return '' } if(file.type == "audio/mpeg") { return '' } if(file.type == "application/pdf") { return '' } if(file.directory) { return '' } else { return '' } } function bytesToSize(bytes) { var sizes = ['o', 'Ko', 'Mo', 'Go', 'To']; if (bytes == 0) return '0 o'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; }