Merge pull request #234 from rado0x54/bugfix/fix-no-itemname

Fix empty [R] name on certain webdav servers.
This commit is contained in:
JK 2024-08-06 05:26:20 -04:00 committed by GitHub
commit e1634556ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 3 deletions

View File

@ -38,7 +38,7 @@ INCLUDES := inc inc/ui inc/fs inc/gfx
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK
APP_VERSION := 07.10.2023
APP_VERSION := 07.25.2024
ROMFS := romfs
ICON := icon.jpg

View File

@ -8,8 +8,8 @@
#include "gfx.h"
#define BLD_MON 07
#define BLD_DAY 10
#define BLD_YEAR 2023
#define BLD_DAY 25
#define BLD_YEAR 2024
namespace data
{

View File

@ -48,5 +48,6 @@ namespace rfs {
std::string getDirID(const std::string& dirName, const std::string& parentId);
std::vector<RfsItem> getListWithParent(const std::string& _parent);
std::string getDisplayNameFromURL(const std::string &url);
};
}

View File

@ -281,6 +281,9 @@ std::vector<rfs::RfsItem> rfs::WebDav::parseXMLResponse(const std::string& xml)
tinyxml2::XMLElement* displaynameElem = propElem->FirstChildElement((nsPrefix + "displayname").c_str());
if (displaynameElem) {
item.name = displaynameElem->GetText();
} else {
// Fallback to name from href
item.name = getDisplayNameFromURL(item.id);
}
tinyxml2::XMLElement* resourcetypeElem = propElem->FirstChildElement((nsPrefix + "resourcetype").c_str());
@ -311,3 +314,26 @@ std::vector<rfs::RfsItem> rfs::WebDav::parseXMLResponse(const std::string& xml)
return items;
}
// Function to extract and URL decode the filename from the URL
std::string rfs::WebDav::getDisplayNameFromURL(const std::string &url) {
// Find the position of the last '/'
size_t pos = url.find_last_of('/');
if (pos == std::string::npos) {
// If '/' is not found, return the whole URL as it is
return url;
}
// Extract the filename from the URL
std::string encodedFilename = url.substr(pos + 1);
// URL decode the filename
int outlength;
char *decodedFilename = curl_easy_unescape(curl, encodedFilename.c_str(), encodedFilename.length(), &outlength);
std::string result(decodedFilename, outlength);
// Free the memory allocated by curl_easy_unescape
curl_free(decodedFilename);
return result;
}