MCPcopy Create free account
hub / github.com/SpartanJ/eepp / loadAsyncFromURL

Method loadAsyncFromURL

src/eepp/ui/doc/textdocument.cpp:928–963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

926}
927
928bool TextDocument::loadAsyncFromURL( const std::string& url,
929 const Http::Request::FieldTable& headers,
930 std::function<void( TextDocument*, bool success )> onLoaded,
931 const Http::Request::ProgressCallback& progressCallback ) {
932 mLoading = true;
933 URI uri( url );
934
935 if ( uri.getScheme().empty() || ( uri.getScheme() != "https" && uri.getScheme() != "http" ) ) {
936 mLoading = false;
937 return false;
938 }
939
940 mLoadingAsync = true;
941
942 Http::getAsync(
943 [this, onLoaded = std::move( onLoaded ),
944 uri = std::move( uri )]( const Http&, Http::Request&, Http::Response& response ) {
945 if ( response.getStatus() <= Http::Response::Ok ) {
946 std::string path( URI::getTempPathFromURI( uri ) );
947 FileSystem::fileWrite( path, (const Uint8*)response.getBody().c_str(),
948 response.getBody().size() );
949 if ( loadFromFile( path ) == LoadStatus::Loaded ) {
950 setDeleteOnClose( true );
951 if ( onLoaded )
952 onLoaded( this, true );
953 }
954 } else {
955 onLoaded( this, false );
956 }
957 mLoading = false;
958 notifyDocumentLoaded();
959 mLoadingAsync = false;
960 },
961 uri, Seconds( 10 ), progressCallback, headers, "", true, Http::getEnvProxyURI() );
962 return true;
963}
964
965TextDocument::LoadStatus TextDocument::reload() {
966 TextDocument::LoadStatus ret = LoadStatus::Failed;

Callers 2

loadFileFromPathMethod · 0.45
loadAsyncFileFromPathMethod · 0.45

Calls 6

SecondsFunction · 0.85
c_strMethod · 0.80
emptyMethod · 0.45
getStatusMethod · 0.45
getBodyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected