@@ -533,7 +533,7 @@ struct oaicompat_parser_options {
533533 bool allow_audio;
534534 bool enable_thinking = true ;
535535 size_t local_media_max_size_mb;
536- std::string allowed_local_media_path;
536+ std::filesystem::path allowed_local_media_path;
537537};
538538
539539// used by /chat/completions endpoint
@@ -643,18 +643,14 @@ static json oaicompat_chat_params_parse(
643643 }
644644
645645 } else if (string_starts_with (url, " file://" )) {
646- // Strip off the leading "file://"
647- const std::string fname = url.substr (7 );
648- if (opt.allowed_local_media_path == " " ) {
646+ if (opt.allowed_local_media_path .empty ()) {
649647 throw std::runtime_error (" Local media paths are not enabled" );
650648 }
651- const std::filesystem::path allowed_local_media_path = std::filesystem::canonical (std::filesystem::path (opt.allowed_local_media_path ));
649+ // Strip off the leading "file://"
650+ const std::string fname = url.substr (7 );
652651 const std::filesystem::path input_path = std::filesystem::canonical (std::filesystem::path (fname));
653- if (!std::filesystem::is_directory (allowed_local_media_path)) {
654- throw std::runtime_error (" Invalid local media path: " + opt.allowed_local_media_path );
655- }
656- auto [allowed_end, nothing] = std::mismatch (allowed_local_media_path.begin (), allowed_local_media_path.end (), input_path.begin ());
657- if (allowed_end != allowed_local_media_path.end ()) {
652+ auto [allowed_end, nothing] = std::mismatch (opt.allowed_local_media_path .begin (), opt.allowed_local_media_path .end (), input_path.begin ());
653+ if (allowed_end != opt.allowed_local_media_path .end ()) {
658654 throw std::runtime_error (" Local media file path not allowed: " + fname);
659655 }
660656 if (!std::filesystem::is_regular_file (input_path)) {
0 commit comments