@@ -717,7 +717,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
717717
718718 /* Close file upon upload completion */
719719 fclose (fd);
720- ESP_LOGI (TAG, " File reception complete" );
720+ LogFile.WriteToFile (ESP_LOG_DEBUG, TAG, " File saved: " + string (filename));
721+ ESP_LOGI (TAG, " File reception completed" );
721722
722723 std::string directory = std::string (filepath);
723724 size_t zw = directory.find (" /" );
@@ -736,21 +737,27 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
736737// ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str());
737738
738739 /* Redirect onto root to see the updated file list */
739- httpd_resp_set_status (req, " 303 See Other" );
740- httpd_resp_set_hdr (req, " Location" , directory.c_str ());
740+ if (strcmp (filename, " /config/config.ini" ) == 0 ||
741+ strcmp (filename, " /config/ref0.jpg" ) == 0 ||
742+ strcmp (filename, " /config/ref0_org.jpg" ) == 0 ||
743+ strcmp (filename, " /config/ref1.jpg" ) == 0 ||
744+ strcmp (filename, " /config/ref1_org.jpg" ) == 0 ||
745+ strcmp (filename, " /config/reference.jpg" ) == 0 ||
746+ strcmp (filename, " /img_tmp/ref0.jpg" ) == 0 ||
747+ strcmp (filename, " /img_tmp/ref0_org.jpg" ) == 0 ||
748+ strcmp (filename, " /img_tmp/ref1.jpg" ) == 0 ||
749+ strcmp (filename, " /img_tmp/ref1_org.jpg" ) == 0 ||
750+ strcmp (filename, " /img_tmp/reference.jpg" ) == 0 )
751+ {
752+ httpd_resp_set_status (req, HTTPD_200); // Avoid reloading of folder content
753+ }
754+ else {
755+ httpd_resp_set_status (req, " 303 See Other" ); // Reload folder content after upload
756+ }
741757
742- /* Redirect onto root to see the updated file list */
743- httpd_resp_set_status (req, " 303 See Other" );
744758 httpd_resp_set_hdr (req, " Location" , directory.c_str ());
745759 httpd_resp_sendstr (req, " File uploaded successfully" );
746760
747- /*
748- if (strcmp(filepath, CONFIG_FILE) == 0) {
749- ESP_LOGD(TAG, "New config found. Reload handler.");
750- gpio_handler_deinit();
751- MQTTdestroy();
752- }
753- */
754761
755762 return ESP_OK;
756763}
@@ -837,16 +844,15 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
837844 return ESP_FAIL;
838845 }
839846
840- if (stat (filepath, &file_stat) == -1 ) {
841- LogFile.WriteToFile (ESP_LOG_ERROR, TAG, " File does not exist: " + string (filename));
842- /* Respond with 400 Bad Request */
843- httpd_resp_send_err (req, HTTPD_400_BAD_REQUEST, " File does not exist" );
844- return ESP_FAIL;
847+ if (stat (filepath, &file_stat) == -1 ) { // File does not exist
848+ /* This is ok, we would delete it anyway */
849+ LogFile.WriteToFile (ESP_LOG_INFO, TAG, " File does not exist: " + string (filename));
845850 }
846851
847- LogFile.WriteToFile (ESP_LOG_INFO, TAG, " Deleting file: " + string (filename));
848852 /* Delete file */
849853 unlink (filepath);
854+ LogFile.WriteToFile (ESP_LOG_DEBUG, TAG, " File deleted: " + string (filename));
855+ ESP_LOGI (TAG, " File deletion completed" );
850856
851857 directory = std::string (filepath);
852858 size_t zw = directory.find (" /" );
@@ -863,16 +869,30 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
863869 directory = directory.substr (start_fn, found - start_fn + 1 );
864870 directory = " /fileserver" + directory;
865871 ESP_LOGD (TAG, " Directory danach 4: %s" , directory.c_str ());
866- }
867872
873+ // ////////////////////////////////////////////////////////////
868874
875+ /* Redirect onto root to see the updated file list */
876+ if (strcmp (filename, " /config/config.ini" ) == 0 ||
877+ strcmp (filename, " /config/ref0.jpg" ) == 0 ||
878+ strcmp (filename, " /config/ref0_org.jpg" ) == 0 ||
879+ strcmp (filename, " /config/ref1.jpg" ) == 0 ||
880+ strcmp (filename, " /config/ref1_org.jpg" ) == 0 ||
881+ strcmp (filename, " /config/reference.jpg" ) == 0 ||
882+ strcmp (filename, " /img_tmp/ref0.jpg" ) == 0 ||
883+ strcmp (filename, " /img_tmp/ref0_org.jpg" ) == 0 ||
884+ strcmp (filename, " /img_tmp/ref1.jpg" ) == 0 ||
885+ strcmp (filename, " /img_tmp/ref1_org.jpg" ) == 0 ||
886+ strcmp (filename, " /img_tmp/reference.jpg" ) == 0 )
887+ {
888+ httpd_resp_set_status (req, HTTPD_200); // Avoid reloading of folder content
889+ }
890+ else {
891+ httpd_resp_set_status (req, " 303 See Other" ); // Reload folder content after upload
892+ }
893+ }
869894
870895
871-
872- // ////////////////////////////////////////////////////////////
873-
874- /* Redirect onto root to see the updated file list */
875- httpd_resp_set_status (req, " 303 See Other" );
876896 httpd_resp_set_hdr (req, " Location" , directory.c_str ());
877897 httpd_resp_sendstr (req, " File successfully deleted" );
878898 return ESP_OK;
@@ -929,7 +949,7 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
929949
930950 // Get and print information about each file in the archive.
931951 int numberoffiles = (int )mz_zip_reader_get_num_files (&zip_archive);
932- LogFile.WriteToFile (ESP_LOG_INFO, TAG, " Numbers of files to be extracted: " + to_string (numberoffiles));
952+ LogFile.WriteToFile (ESP_LOG_INFO, TAG, " Files to be extracted: " + to_string (numberoffiles));
933953
934954 sort_iter = 0 ;
935955 {
@@ -993,7 +1013,7 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
9931013
9941014 string filename_zw = zw + SUFFIX_ZW;
9951015
996- ESP_LOGI (TAG, " Filename to extract: %s, Zwischenfilename : %s" , zw.c_str (), filename_zw.c_str ());
1016+ ESP_LOGI (TAG, " File to extract: %s, Temp. Filename : %s" , zw.c_str (), filename_zw.c_str ());
9971017
9981018 std::string folder = filename_zw.substr (0 , filename_zw.find_last_of (' /' ));
9991019 MakeDir (folder);
@@ -1097,7 +1117,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
10971117 // Save to File.
10981118 zw = std::string (archive_filename);
10991119 zw = _target_directory + zw;
1100- ESP_LOGD (TAG, " Filename to extract: %s" , zw.c_str ());
1120+ ESP_LOGD (TAG, " File to extract: %s" , zw.c_str ());
11011121 FILE* fpTargetFile = fopen (zw.c_str (), " wb" );
11021122 fwrite (p, 1 , (uint)uncomp_size, fpTargetFile);
11031123 fclose (fpTargetFile);
0 commit comments