@@ -844,7 +844,7 @@ var require_common = __commonJS((exports2, module2) => {
844844 }
845845 namespaces = split [ i ] . replace ( / \* / g, ".*?" ) ;
846846 if ( namespaces [ 0 ] === "-" ) {
847- createDebug . skips . push ( new RegExp ( "^" + namespaces . substr ( 1 ) + "$" ) ) ;
847+ createDebug . skips . push ( new RegExp ( "^" + namespaces . slice ( 1 ) + "$" ) ) ;
848848 } else {
849849 createDebug . names . push ( new RegExp ( "^" + namespaces + "$" ) ) ;
850850 }
@@ -1304,56 +1304,56 @@ var require_follow_redirects = __commonJS((exports2, module2) => {
13041304 } ) ;
13051305 }
13061306 var location = response . headers . location ;
1307- if ( location && this . _options . followRedirects !== false && statusCode >= 300 && statusCode < 400 ) {
1308- abortRequest ( this . _currentRequest ) ;
1309- response . destroy ( ) ;
1310- if ( ++ this . _redirectCount > this . _options . maxRedirects ) {
1311- this . emit ( "error" , new TooManyRedirectsError ( ) ) ;
1312- return ;
1313- }
1314- if ( ( statusCode === 301 || statusCode === 302 ) && this . _options . method === "POST" || statusCode === 303 && ! / ^ (?: G E T | H E A D ) $ / . test ( this . _options . method ) ) {
1315- this . _options . method = "GET" ;
1316- this . _requestBodyBuffers = [ ] ;
1317- removeMatchingHeaders ( / ^ c o n t e n t - / i, this . _options . headers ) ;
1318- }
1319- var currentHostHeader = removeMatchingHeaders ( / ^ h o s t $ / i, this . _options . headers ) ;
1320- var currentUrlParts = url . parse ( this . _currentUrl ) ;
1321- var currentHost = currentHostHeader || currentUrlParts . host ;
1322- var currentUrl = / ^ \w + : / . test ( location ) ? this . _currentUrl : url . format ( Object . assign ( currentUrlParts , { host : currentHost } ) ) ;
1323- var redirectUrl ;
1324- try {
1325- redirectUrl = url . resolve ( currentUrl , location ) ;
1326- } catch ( cause ) {
1327- this . emit ( "error" , new RedirectionError ( cause ) ) ;
1328- return ;
1329- }
1330- debug ( "redirecting to" , redirectUrl ) ;
1331- this . _isRedirect = true ;
1332- var redirectUrlParts = url . parse ( redirectUrl ) ;
1333- Object . assign ( this . _options , redirectUrlParts ) ;
1334- if ( ! ( redirectUrlParts . host === currentHost || isSubdomainOf ( redirectUrlParts . host , currentHost ) ) ) {
1335- removeMatchingHeaders ( / ^ a u t h o r i z a t i o n $ / i, this . _options . headers ) ;
1336- }
1337- if ( typeof this . _options . beforeRedirect === "function" ) {
1338- var responseDetails = { headers : response . headers } ;
1339- try {
1340- this . _options . beforeRedirect . call ( null , this . _options , responseDetails ) ;
1341- } catch ( err ) {
1342- this . emit ( "error" , err ) ;
1343- return ;
1344- }
1345- this . _sanitizeOptions ( this . _options ) ;
1346- }
1347- try {
1348- this . _performRequest ( ) ;
1349- } catch ( cause ) {
1350- this . emit ( "error" , new RedirectionError ( cause ) ) ;
1351- }
1352- } else {
1307+ if ( ! location || this . _options . followRedirects === false || statusCode < 300 || statusCode >= 400 ) {
13531308 response . responseUrl = this . _currentUrl ;
13541309 response . redirects = this . _redirects ;
13551310 this . emit ( "response" , response ) ;
13561311 this . _requestBodyBuffers = [ ] ;
1312+ return ;
1313+ }
1314+ abortRequest ( this . _currentRequest ) ;
1315+ response . destroy ( ) ;
1316+ if ( ++ this . _redirectCount > this . _options . maxRedirects ) {
1317+ this . emit ( "error" , new TooManyRedirectsError ( ) ) ;
1318+ return ;
1319+ }
1320+ if ( ( statusCode === 301 || statusCode === 302 ) && this . _options . method === "POST" || statusCode === 303 && ! / ^ (?: G E T | H E A D ) $ / . test ( this . _options . method ) ) {
1321+ this . _options . method = "GET" ;
1322+ this . _requestBodyBuffers = [ ] ;
1323+ removeMatchingHeaders ( / ^ c o n t e n t - / i, this . _options . headers ) ;
1324+ }
1325+ var currentHostHeader = removeMatchingHeaders ( / ^ h o s t $ / i, this . _options . headers ) ;
1326+ var currentUrlParts = url . parse ( this . _currentUrl ) ;
1327+ var currentHost = currentHostHeader || currentUrlParts . host ;
1328+ var currentUrl = / ^ \w + : / . test ( location ) ? this . _currentUrl : url . format ( Object . assign ( currentUrlParts , { host : currentHost } ) ) ;
1329+ var redirectUrl ;
1330+ try {
1331+ redirectUrl = url . resolve ( currentUrl , location ) ;
1332+ } catch ( cause ) {
1333+ this . emit ( "error" , new RedirectionError ( cause ) ) ;
1334+ return ;
1335+ }
1336+ debug ( "redirecting to" , redirectUrl ) ;
1337+ this . _isRedirect = true ;
1338+ var redirectUrlParts = url . parse ( redirectUrl ) ;
1339+ Object . assign ( this . _options , redirectUrlParts ) ;
1340+ if ( redirectUrlParts . protocol !== currentUrlParts . protocol && redirectUrlParts . protocol !== "https:" || redirectUrlParts . host !== currentHost && ! isSubdomain ( redirectUrlParts . host , currentHost ) ) {
1341+ removeMatchingHeaders ( / ^ (?: a u t h o r i z a t i o n | c o o k i e ) $ / i, this . _options . headers ) ;
1342+ }
1343+ if ( typeof this . _options . beforeRedirect === "function" ) {
1344+ var responseDetails = { headers : response . headers } ;
1345+ try {
1346+ this . _options . beforeRedirect . call ( null , this . _options , responseDetails ) ;
1347+ } catch ( err ) {
1348+ this . emit ( "error" , err ) ;
1349+ return ;
1350+ }
1351+ this . _sanitizeOptions ( this . _options ) ;
1352+ }
1353+ try {
1354+ this . _performRequest ( ) ;
1355+ } catch ( cause ) {
1356+ this . emit ( "error" , new RedirectionError ( cause ) ) ;
13571357 }
13581358 } ;
13591359 function wrap ( protocols ) {
@@ -1427,11 +1427,11 @@ var require_follow_redirects = __commonJS((exports2, module2) => {
14271427 var lastValue ;
14281428 for ( var header in headers ) {
14291429 if ( regex . test ( header ) ) {
1430- lastValue = headers [ header ] . toString ( ) . trim ( ) ;
1430+ lastValue = headers [ header ] ;
14311431 delete headers [ header ] ;
14321432 }
14331433 }
1434- return lastValue ;
1434+ return lastValue === null || typeof lastValue === "undefined" ? void 0 : String ( lastValue ) . trim ( ) ;
14351435 }
14361436 function createErrorType ( code , defaultMessage ) {
14371437 function CustomError ( cause ) {
@@ -1456,7 +1456,7 @@ var require_follow_redirects = __commonJS((exports2, module2) => {
14561456 request . on ( "error" , noop ) ;
14571457 request . abort ( ) ;
14581458 }
1459- function isSubdomainOf ( subdomain , domain ) {
1459+ function isSubdomain ( subdomain , domain ) {
14601460 const dot = subdomain . length - domain . length - 1 ;
14611461 return dot > 0 && subdomain [ dot ] === "." && subdomain . endsWith ( domain ) ;
14621462 }
@@ -2653,41 +2653,42 @@ var CloudinaryUploader = class extends import_obsidian2.Plugin {
26532653 setupPasteHandler ( ) {
26542654 this . registerEvent ( this . app . workspace . on ( "editor-paste" , async ( evt , editor ) => {
26552655 const { files} = evt . clipboardData ;
2656- if ( files . length == 0 && ! files [ 0 ] . type . startsWith ( "text" ) ) {
2657- editor . replaceSelection ( "Clipboard data is not an image\n" ) ;
2658- } else if ( this . settings . cloudName && this . settings . uploadPreset && files [ 0 ] . type . startsWith ( "image" ) ) {
2659- for ( let file of files ) {
2656+ if ( files . length > 0 ) {
2657+ if ( this . settings . cloudName && this . settings . uploadPreset && files [ 0 ] . type . startsWith ( "image" ) ) {
26602658 evt . preventDefault ( ) ;
2661- const randomString = ( Math . random ( ) * 10086 ) . toString ( 36 ) . substr ( 0 , 8 ) ;
2662- const pastePlaceText = `
2659+ for ( let file of files ) {
2660+ const randomString = ( Math . random ( ) * 10086 ) . toString ( 36 ) . substr ( 0 , 8 ) ;
2661+ const pastePlaceText = `
26632662` ;
2664- editor . replaceSelection ( pastePlaceText ) ;
2665- const formData = new FormData ( ) ;
2666- formData . append ( "file" , file ) ;
2667- formData . append ( "upload_preset" , this . settings . uploadPreset ) ;
2668- formData . append ( "folder" , this . settings . folder ) ;
2669- ( 0 , import_axios . default ) ( {
2670- url : `https://api.cloudinary.com/v1_1/${ this . settings . cloudName } /upload` ,
2671- method : "POST" ,
2672- data : formData
2673- } ) . then ( ( res ) => {
2674- const url = import_object_path . default . get ( res . data , "secure_url" ) ;
2675- const imgMarkdownText = `` ;
2676- this . replaceText ( editor , pastePlaceText , imgMarkdownText ) ;
2677- } , ( err ) => {
2678- new import_obsidian2 . Notice ( err , 5e3 ) ;
2679- console . log ( err ) ;
2680- } ) ;
2663+ editor . replaceSelection ( pastePlaceText ) ;
2664+ const formData = new FormData ( ) ;
2665+ formData . append ( "file" , file ) ;
2666+ formData . append ( "upload_preset" , this . settings . uploadPreset ) ;
2667+ formData . append ( "folder" , this . settings . folder ) ;
2668+ ( 0 , import_axios . default ) ( {
2669+ url : `https://api.cloudinary.com/v1_1/${ this . settings . cloudName } /auto/upload` ,
2670+ method : "POST" ,
2671+ data : formData
2672+ } ) . then ( ( res ) => {
2673+ console . log ( res ) ;
2674+ const url = import_object_path . default . get ( res . data , "secure_url" ) ;
2675+ const imgMarkdownText = `` ;
2676+ this . replaceText ( editor , pastePlaceText , imgMarkdownText ) ;
2677+ } , ( err ) => {
2678+ new import_obsidian2 . Notice ( err , 5e3 ) ;
2679+ console . log ( err ) ;
2680+ } ) ;
2681+ }
26812682 }
2682- } else {
2683- new import_obsidian2 . Notice ( "Cloudinary Image Uploader: Please check the image hosting settings." ) ;
2684- editor . replaceSelection ( "Please check settings for upload\n This will also appear if file is not of image type" ) ;
26852683 }
26862684 } ) ) ;
26872685 }
26882686 replaceText ( editor , target , replacement ) {
26892687 target = target . trim ( ) ;
2690- const lines = editor . getValue ( ) . split ( "\n" ) ;
2688+ let lines = [ ] ;
2689+ for ( let i = 0 ; i < editor . lineCount ( ) ; i ++ ) {
2690+ lines . push ( editor . getLine ( i ) ) ;
2691+ }
26912692 for ( let i = 0 ; i < lines . length ; i ++ ) {
26922693 const ch = lines [ i ] . indexOf ( target ) ;
26932694 if ( ch !== - 1 ) {
0 commit comments