class WebFS{ /** * @param {string} path * @returns {boolean} */ static async CreateDirectory(path){ if (path == undefined){ WebDesktopEnvironment.Alert("Path is undefined") return false } const params = new URLSearchParams({ path: `${path}/New Directory` }) const response = await fetch(`/system/fs/createDir?` + params) if (response.status != 200){ WebDesktopEnvironment.Alert("DIRCTORY CREATION ERROR") //TODO return false } return true } /** * @param {string} path * @returns {boolean} */ static async DeleteFile(path){ const params = new URLSearchParams({ path: path }) const response = await fetch(`/system/fs/delete?` + params) if (response.status != 200){ WebDesktopEnvironment.Alert("DELETE ERROR") //TODO return false } return true } /** * @param {string} path * @returns {boolean} */ static async MoveFile(sourcePath, targetPath){ const params = new URLSearchParams({ sourcePath: sourcePath, targetPath: targetPath }) const response = await fetch(`/system/fs/move?` + params) if (response.status != 200){ // WebDesktopEnvironment.Alert("Move ERROR") //TODO return false } return true } /** * @param {string} linkPath * @returns {string} */ static async ReadObjectLink(linkPath){ const params = new URLSearchParams({ linkPath: linkPath, }) const response = await fetch(`/system/fs/readObjectLink?` + params) if (response.status != 200){ WebDesktopEnvironment.Alert("TODO") //TODO return "" } const path = await response.text() //TODO Validate return path } /** * @param {string} sourcePath * @param {string} linkPath * @returns {string} */ static async CreatePathLink(sourcePath, linkPath){ const params = new URLSearchParams({ sourcePath: sourcePath, linkPath: linkPath, }) const response = await fetch(`/system/fs/createPathLink?` + params) return response.status == 200 } /** * @param {string} linkPath * @returns {string} */ static async ReadPathLink(linkPath){ const params = new URLSearchParams({ linkPath: linkPath, }) const response = await fetch(`/system/fs/readPathLink?` + params) if (response.status != 200){ WebDesktopEnvironment.Alert("TODO") //TODO return "" } // console.log(response) const file = await response.json() //TODO Validate return file } /** * @param {File} file * @param {string} parentPath * @returns {boolean} */ static async UploadFile(file, parentPath){ console.log('here') let formData = new FormData() formData.append("file", file) //FIXME Conn reset const params = new URLSearchParams({ parentPath: parentPath, }) const response = await fetch(`/system/fs/upload?` + params, { method: "POST", //TODO Change to PUT? body: formData }) console.log(response.status) if (response.status != 201){ const error = await response.json() WebDesktopEnvironment.Alert(error.message) return false } return true } }