File tree Expand file tree Collapse file tree
.idea/.idea.LinkRouter/.idea Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using LinkRouter . App . Configuration ;
1+ using System . Text . Json ;
2+ using System . IO ;
3+ using LinkRouter . App . Configuration ;
24using Microsoft . AspNetCore . Mvc ;
35using MoonCore . Services ;
46
57namespace LinkRouter . App . Http . Controllers ;
68
79[ ApiController ]
8- [ Route ( "[controller]" ) ]
910public class RedirectController : Controller
1011{
1112
@@ -19,14 +20,23 @@ public RedirectController(ConfigService<Config> configService)
1920 [ HttpGet ( "/{*path}" ) ]
2021 public IActionResult RedirectToExternalUrl ( string path )
2122 {
22- path = "/" + path . Trim ( '/' ) ;
23+ var configPath = Path . Combine ( "data" , "config.json" ) ;
24+
25+ if ( ! System . IO . File . Exists ( configPath ) || string . IsNullOrEmpty ( System . IO . File . ReadAllText ( configPath ) ) )
26+ {
27+ return NotFound ( ) ;
28+ }
29+
30+ var config = JsonSerializer . Deserialize < Config > ( System . IO . File . ReadAllText ( configPath ) ) ;
2331
24- var redirectRoute = ConfigService . Get ( ) . Routes . FirstOrDefault ( x => x . Route == path || x . Route == path + "/" ) ;
32+ if ( config == null )
33+ return NotFound ( ) ;
34+
35+ var redirectRoute = config . Routes . FirstOrDefault ( x => x . Route == path || x . Route == path + "/" ) ;
2536
2637 if ( redirectRoute == null )
27- {
2838 return NotFound ( ) ;
29- }
39+
3040
3141 return Redirect ( redirectRoute . RedirectUrl ) ;
3242 }
Original file line number Diff line number Diff line change @@ -15,15 +15,6 @@ public static void Main(string[] args)
1515 // Add services to the container.
1616
1717 Directory . CreateDirectory ( PathBuilder . Dir ( "data" ) ) ;
18-
19- var configFilePath = PathBuilder . File ( "data" , "config.json" ) ;
20-
21- if ( ! File . Exists ( configFilePath ) )
22- File . WriteAllText ( configFilePath , "{}" ) ;
23-
24- ConfigService < Config > configService = new ( configFilePath ) ;
25-
26- builder . Services . AddSingleton ( configService ) ;
2718
2819 builder . Services . AddControllers ( ) ;
2920
You can’t perform that action at this time.
0 commit comments