Giter Club home page Giter Club logo

ace-on-esp-local's Introduction

ace-on-esp-local

ace files without cdn

ace.js embeded to edit.html.gz and renamed long theme name to duru


Different browsers response are not same for listing directories. Mac -> chrome and firefox are ok but safari may delay or not show dir list. If dir list is empty you can use Show Directory button.


You may need reload page 3-4 times to finish caching.

http://192.168.4.1/edit

orginal code from here https://github.com/me-no-dev/ESPAsyncWebServer

if you dont want to edit json files ignore json plugin files...

you can serve edit.html.gz file and use with ;



class SPIFFSEditor: public AsyncWebHandler {
  private:
    String _username = httpAuth.wwwUsername.c_str();
    String _password = httpAuth.wwwPassword.c_str();
    bool _authenticated;
    uint32_t _startTime;
  public:
    bool bak;
    SPIFFSEditor(String username = String(), String password = String()): _username(username), _password(password), _authenticated(false), _startTime(0) {}
    bool canHandle(AsyncWebServerRequest *request) {
      if (request->method() == HTTP_GET && request->url() == "/edit")
        return true;
      else if (request->method() == HTTP_GET && request->url() == "/list")
        return true;
      else if (request->method() == HTTP_GET && !(request->url().endsWith("/")) && request->hasParam("download"))
        return true;
      else if (request->method() == HTTP_POST && request->url() == "/edit")
        return true;
      else if (request->method() == HTTP_DELETE && request->url() == "/edit")
        return true;
      else if (request->method() == HTTP_PUT && request->url() == "/edit")
        return true;

      return false;
    }


    void handleRequest(AsyncWebServerRequest *request) {

      if (_username.length() && _password.length() && !request->authenticate(_username.c_str(), _password.c_str()))
        return request->requestAuthentication();
      if (request->method() == HTTP_GET && request->url() == "/list") {
        if (request->hasParam("dir")) {
          String path = request->getParam("dir")->value();
          Dir dir = SPIFFS.openDir(path);
          path = String();
          String output = "[";
          while (dir.next()) {
            fs::File entry = dir.openFile("r");
            if (output != "[") output += ',';
            bool isDir = false;
            output += "{\"type\":\"";
            output += (isDir) ? "dir" : "file";
            output += "\",\"name\":\"";
            output += String(entry.name()).substring(1);
            output += "\"}";
            entry.close();
          }
          output += "]";
          request->send(200, "text/json", output);
          output = String();
        }

      }
      else  if (request->method() == HTTP_GET && request->url() == "/edit") {


        request->send(SPIFFS, "/edit.html");

      }
      else if (request->method() == HTTP_GET) {
        request->send(SPIFFS, request->url(), String(), true);
      } else if (request->method() == HTTP_DELETE) {
        if (request->hasParam("path", true)) {
          SPIFFS.remove(request->getParam("path", true)->value());
          request->send(200, "", "DELETE: " + request->getParam("path", true)->value());
        } else
          request->send(404);
      } else if (request->method() == HTTP_POST) {
        if (request->hasParam("data", true, true) && SPIFFS.exists(request->getParam("data", true, true)->value()))
          request->send(200, "", "UPLOADED: " + request->getParam("data", true, true)->value());
        else
          request->send(500);
      } else if (request->method() == HTTP_PUT) {
        if (request->hasParam("path", true)) {
          String filename = request->getParam("path", true)->value();
          if (SPIFFS.exists(filename)) {
            request->send(200);
          } else {
            fs::File f = SPIFFS.open(filename, "w");
            if (f) {
              f.write((uint8_t)0x00);
              f.close();
              request->send(200, "", "CREATE: " + filename);
            } else {
              request->send(500);
            }
          }
        } else
          request->send(400);
      }
    }

    void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
      if (!index) {
        if (!_username.length() || request->authenticate(_username.c_str(), _password.c_str())) {
          _authenticated = true;
          request->_tempFile = SPIFFS.open(filename, "w");
          _startTime = millis();
        }
      }
      if (_authenticated && request->_tempFile) {
        if (len) {
          request->_tempFile.write(data, len);
        }
        if (final) {
          request->_tempFile.close();
          uint32_t uploadTime = millis() - _startTime;
          os_printf("upload: %s, %u B, %u ms\n", filename.c_str(), index + len, uploadTime);
          String yuklendi = "Dosya yüklendi: " + filename + ", " + (index + len) / 1000 + " KB, " + uploadTime / 1000 + " saniye";
          ws.textAll(yuklendi);

        }
      }
    }


};

ace-on-esp-local's People

Contributors

kiralikbeyin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.