| 883 | } |
| 884 | |
| 885 | void CrossPointWebServer::handleMove() const { |
| 886 | if (!server->hasArg("path") || !server->hasArg("dest")) { |
| 887 | server->send(400, "text/plain", "Missing path or destination"); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | String itemPath = normalizeWebPath(server->arg("path")); |
| 892 | String destPath = normalizeWebPath(server->arg("dest")); |
| 893 | |
| 894 | if (itemPath.isEmpty() || itemPath == "/") { |
| 895 | server->send(400, "text/plain", "Invalid path"); |
| 896 | return; |
| 897 | } |
| 898 | if (destPath.isEmpty()) { |
| 899 | server->send(400, "text/plain", "Invalid destination"); |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | const String itemName = itemPath.substring(itemPath.lastIndexOf('/') + 1); |
| 904 | if (isProtectedItemName(itemName)) { |
| 905 | server->send(403, "text/plain", "Cannot move protected item"); |
| 906 | return; |
| 907 | } |
| 908 | if (destPath != "/") { |
| 909 | const String destName = destPath.substring(destPath.lastIndexOf('/') + 1); |
| 910 | if (isProtectedItemName(destName)) { |
| 911 | server->send(403, "text/plain", "Cannot move into protected folder"); |
| 912 | return; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | if (!Storage.exists(itemPath.c_str())) { |
| 917 | server->send(404, "text/plain", "Item not found"); |
| 918 | return; |
| 919 | } |
| 920 | |
| 921 | HalFile file = Storage.open(itemPath.c_str()); |
| 922 | if (!file) { |
| 923 | server->send(500, "text/plain", "Failed to open file"); |
| 924 | return; |
| 925 | } |
| 926 | if (file.isDirectory()) { |
| 927 | file.close(); |
| 928 | server->send(400, "text/plain", "Only files can be moved"); |
| 929 | return; |
| 930 | } |
| 931 | |
| 932 | if (!Storage.exists(destPath.c_str())) { |
| 933 | file.close(); |
| 934 | server->send(404, "text/plain", "Destination not found"); |
| 935 | return; |
| 936 | } |
| 937 | HalFile destDir = Storage.open(destPath.c_str()); |
| 938 | if (!destDir || !destDir.isDirectory()) { |
| 939 | if (destDir) { |
| 940 | destDir.close(); |
| 941 | } |
| 942 | file.close(); |
nothing calls this directly
no test coverage detected