diff options
-rw-r--r-- | music.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -204,13 +204,26 @@ void MusicDirectory::render(HTTP::Connection::p req) { std::string base_path = boost::algorithm::join(req->base_path, "/"); + // strip root_directory from the absolute file path + std::string rel_base(path.string().substr(music::root_directory.string().size())); + // set relative base to "/" if we're at the root_directory + if(!rel_base.size()) + rel_base = "/"; + req->send_data(boost::str(boost::format("<h1>%s</h1>") % rel_base)); + + // link to parent directory if we're not at the root_directory + if(rel_base != "/") { + std::string rel_parent(rel_base.substr(0, rel_base.find_last_of('/'))); + req->send_data(boost::str(boost::format("<a href=\"/%s%s/\">..</a><br />") % base_path % rel_parent)); + } + for(PathListings::iterator it = directories.begin(); it != directories.end(); it++) { std::string rel_path = it->string().substr(music::root_directory.string().size()); - req->send_data(boost::str(boost::format("<a href=\"/%s%s\">%s</a><br />") % base_path % rel_path % rel_path)); + req->send_data(boost::str(boost::format("<a href=\"/%s%s/\">%s</a><br />") % base_path % rel_path % it->filename())); } for(PathListings::iterator it = tracks.begin(); it != tracks.end(); it++) { std::string rel_path = it->string().substr(music::root_directory.string().size()); - req->send_data(boost::str(boost::format("<a href=\"/%s%s\">%s</a><br />") % base_path % rel_path % rel_path)); + req->send_data(boost::str(boost::format("<a href=\"/%s%s\">%s</a><br />") % base_path % rel_path % it->filename())); } } |