Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

  1. #include <FactoryResetService.h>
  2. using namespace std::placeholders;
  3. FactoryResetService::FactoryResetService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : fs(fs) {
  4. server->on(FACTORY_RESET_SERVICE_PATH,
  5. HTTP_POST,
  6. securityManager->wrapRequest(std::bind(&FactoryResetService::handleRequest, this, _1),
  7. AuthenticationPredicates::IS_ADMIN));
  8. }
  9. void FactoryResetService::handleRequest(AsyncWebServerRequest* request) {
  10. request->onDisconnect(std::bind(&FactoryResetService::factoryReset, this));
  11. request->send(200);
  12. }
  13. /**
  14. * Delete function assumes that all files are stored flat, within the config directory
  15. */
  16. void FactoryResetService::factoryReset() {
  17. #ifdef ESP32
  18. File root = fs->open(FS_CONFIG_DIRECTORY);
  19. File file;
  20. while (file = root.openNextFile()) {
  21. fs->remove(file.name());
  22. }
  23. #elif defined(ESP8266)
  24. Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
  25. while (configDirectory.next()) {
  26. fs->remove(configDirectory.fileName());
  27. }
  28. #endif
  29. ESP.restart();
  30. }