@@ -614,46 +614,64 @@ private static void Reference(HttpContext context)
614
614
615
615
var jss = new JavaScriptSerializer ( ) ;
616
616
var body = jss . Deserialize < Dictionary < string , object > > ( fileData ) ;
617
- var referenceData = jss . Deserialize < Dictionary < string , object > > ( jss . Serialize ( body [ "referenceData" ] ) ) ;
617
+ var referenceData = jss . Deserialize < Dictionary < string , object > > ( jss . Serialize ( body [ "referenceData" ] ) ) ;
618
618
var instanceId = ( string ) referenceData [ "instanceId" ] ;
619
619
var fileKey = ( string ) referenceData [ "fileKey" ] ;
620
+ var fileName = "" ;
621
+ var userAddress = "" ;
620
622
621
- try
623
+ if ( instanceId == _Default . GetServerUrl ( false ) )
622
624
{
623
625
var fileKeyObj = jss . Deserialize < Dictionary < string , object > > ( fileKey ) ;
624
- var fileName = ( string ) fileKeyObj [ "fileName" ] ;
625
- var userAddress = ( string ) fileKeyObj [ "userAddress" ] ;
626
-
627
- var data = new Dictionary < string , object > ( ) {
628
- { "fileType" , ( Path . GetExtension ( fileName ) ?? "" ) . ToLower ( ) } ,
629
- { "url" , DocEditor . getDownloadUrl ( fileName ) } ,
630
- { "directUrl" , DocEditor . getDownloadUrl ( fileName ) } ,
631
- { "referenceData" , new Dictionary < string , string > ( )
632
- {
633
- { "fileKey" , jss . Serialize ( new Dictionary < string , object > {
634
- { "fileName" , fileName } ,
635
- { "userAddress" , HttpUtility . UrlEncode ( _Default . CurUserHostAddress ( HttpContext . Current . Request . UserHostAddress ) ) }
636
- } )
637
- } ,
638
- { "instanceId" , _Default . GetServerUrl ( false ) }
639
- } ,
640
- { "path" , fileName }
626
+ userAddress = ( string ) fileKeyObj [ "userAddress" ] ;
627
+ if ( userAddress == HttpUtility . UrlEncode ( _Default . CurUserHostAddress ( HttpContext . Current . Request . UserHostAddress ) ) )
628
+ {
629
+ fileName = ( string ) fileKeyObj [ "fileName" ] ;
641
630
}
642
- } ;
631
+ }
643
632
644
- if ( JwtManager . Enabled )
633
+ if ( fileName == "" && userAddress != "" )
634
+ {
635
+ var path = ( string ) body [ "path" ] ;
636
+ path = Path . GetFileName ( path ) ;
637
+ if ( File . Exists ( _Default . StoragePath ( path , userAddress ) ) )
645
638
{
646
- var token = JwtManager . Encode ( data ) ;
647
- data . Add ( "token" , token ) ;
639
+ fileName = path ;
648
640
}
649
-
650
- context . Response . Write ( jss . Serialize ( data ) . Replace ( @"\u0026" , "&" ) ) ;
651
641
}
652
- catch ( Exception e )
642
+
643
+ if ( fileName == "" )
653
644
{
654
645
context . Response . Write ( "{ \" error\" : \" File not found!\" }" ) ;
646
+ return ;
655
647
}
656
648
649
+ var data = new Dictionary < string , object > ( ) {
650
+ { "fileType" , ( Path . GetExtension ( fileName ) ?? "" ) . ToLower ( ) } ,
651
+ { "url" , DocEditor . getDownloadUrl ( fileName ) } ,
652
+ { "directUrl" , DocEditor . getDownloadUrl ( fileName ) } ,
653
+ { "referenceData" , new Dictionary < string , string > ( )
654
+ {
655
+ { "fileKey" , jss . Serialize ( new Dictionary < string , object > {
656
+ { "fileName" , fileName } ,
657
+ { "userAddress" , HttpUtility . UrlEncode ( _Default . CurUserHostAddress ( HttpContext . Current . Request . UserHostAddress ) ) }
658
+ } )
659
+ } ,
660
+ { "instanceId" , _Default . GetServerUrl ( false ) }
661
+ }
662
+ } ,
663
+ { "path" , fileName }
664
+ } ;
665
+
666
+ if ( JwtManager . Enabled )
667
+ {
668
+ var token = JwtManager . Encode ( data ) ;
669
+ data . Add ( "token" , token ) ;
670
+ }
671
+
672
+ context . Response . Write ( jss . Serialize ( data ) . Replace ( @"\u0026" , "&" ) ) ;
657
673
}
674
+
675
+ }
658
676
}
659
677
}
0 commit comments