@@ -614,46 +614,72 @@ 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
+ try
645
636
{
646
- var token = JwtManager . Encode ( data ) ;
647
- data . Add ( "token" , token ) ;
637
+ var path = ( string ) body [ "path" ] ;
638
+ path = Path . GetFileName ( path ) ;
639
+ if ( File . Exists ( _Default . StoragePath ( path , userAddress ) ) )
640
+ {
641
+ fileName = path ;
642
+ }
643
+ }
644
+ catch
645
+ {
646
+ context . Response . Write ( "{ \" error\" : \" Path not found!\" }" ) ;
647
+ return ;
648
648
}
649
-
650
- context . Response . Write ( jss . Serialize ( data ) . Replace ( @"\u0026" , "&" ) ) ;
651
649
}
652
- catch ( Exception e )
650
+
651
+ if ( fileName == "" )
653
652
{
654
653
context . Response . Write ( "{ \" error\" : \" File not found!\" }" ) ;
654
+ return ;
655
655
}
656
656
657
+ var data = new Dictionary < string , object > ( ) {
658
+ { "fileType" , ( Path . GetExtension ( fileName ) ?? "" ) . ToLower ( ) } ,
659
+ { "url" , DocEditor . getDownloadUrl ( fileName ) } ,
660
+ { "directUrl" , DocEditor . getDownloadUrl ( fileName ) } ,
661
+ { "referenceData" , new Dictionary < string , string > ( )
662
+ {
663
+ { "fileKey" , jss . Serialize ( new Dictionary < string , object > {
664
+ { "fileName" , fileName } ,
665
+ { "userAddress" , HttpUtility . UrlEncode ( _Default . CurUserHostAddress ( HttpContext . Current . Request . UserHostAddress ) ) }
666
+ } )
667
+ } ,
668
+ { "instanceId" , _Default . GetServerUrl ( false ) }
669
+ }
670
+ } ,
671
+ { "path" , fileName }
672
+ } ;
673
+
674
+ if ( JwtManager . Enabled )
675
+ {
676
+ var token = JwtManager . Encode ( data ) ;
677
+ data . Add ( "token" , token ) ;
678
+ }
679
+
680
+ context . Response . Write ( jss . Serialize ( data ) . Replace ( @"\u0026" , "&" ) ) ;
657
681
}
682
+
683
+ }
658
684
}
659
685
}
0 commit comments