@@ -20,44 +20,33 @@ public void Configure(IWebHostBuilder builder) => builder
20
20
services . AddSingleton ( AppData . Instance ) ;
21
21
services . AddSingleton < AppUserQuotas > ( ) ;
22
22
23
+ context . Configuration . GetSection ( nameof ( AppConfig ) ) . Bind ( AppConfig . Instance ) ;
24
+ services . AddSingleton ( AppConfig . Instance ) ;
25
+ var appConfig = AppConfig . Instance ;
26
+
23
27
var baseUrl = Environment . GetEnvironmentVariable ( "VIRTUAL_HOST" ) ;
24
28
baseUrl = ! string . IsNullOrEmpty ( baseUrl )
25
29
? $ "https://{ baseUrl } "
26
30
: LocalBaseUrl ;
27
-
28
31
var apiUrl = Environment . GetEnvironmentVariable ( "DEPLOY_API" ) ;
29
32
apiUrl = ! string . IsNullOrEmpty ( apiUrl )
30
33
? $ "https://{ apiUrl } "
31
34
: null ;
32
-
33
- var aiServerUrl = "https://ai-server-cdn.diffusion.works" ;
34
- #if DEBUG
35
- aiServerUrl = "https://localhost:5005" ;
36
- #endif
37
-
38
- // set in launchSettings.json
35
+ appConfig . BaseUrl = baseUrl ;
36
+ appConfig . ApiBaseUrl = apiUrl ?? baseUrl ;
37
+ var aiServerApiKey = Environment . GetEnvironmentVariable ( "AI_SERVER_APIKEY" ) ;
38
+ if ( aiServerApiKey != null )
39
+ appConfig . AiServerApiKey = aiServerApiKey ;
40
+
41
+ var r2AccountId = Environment . GetEnvironmentVariable ( "R2_ACCOUNT_ID" ) ;
42
+ if ( r2AccountId != null )
43
+ appConfig . R2Account = r2AccountId ;
39
44
var r2AccessId = Environment . GetEnvironmentVariable ( "R2_ACCESS_KEY_ID" ) ;
45
+ if ( r2AccessId != null )
46
+ appConfig . R2AccessId = r2AccessId ;
40
47
var r2AccessKey = Environment . GetEnvironmentVariable ( "R2_SECRET_ACCESS_KEY" ) ;
41
-
42
- var appConfig = AppConfig . Set ( new AppConfig
43
- {
44
- BaseUrl = baseUrl ,
45
- ApiBaseUrl = apiUrl ?? baseUrl ,
46
- AiServerUrl = aiServerUrl ,
47
- WwwBaseUrl = baseUrl ,
48
- CdnBaseUrl = baseUrl ,
49
- R2Account = "b95f38ca3a6ac31ea582cd624e6eb385" ,
50
- R2AccessId = r2AccessId ,
51
- R2AccessKey = r2AccessKey ,
52
- ArtifactBucket = "diffusion" ,
53
- CdnBucket = "diffusion-client" ,
54
- AssetsBasePath = r2AccessId != null
55
- ? "https://cdn.diffusion.works"
56
- : "/uploads" ,
57
- FallbackAssetsBasePath = r2AccessId != null ? "https://pub-97bba6b94a944260b10a6e7d4bf98053.r2.dev" : "/uploads" ,
58
- SyncTasksInterval = TimeSpan . FromMinutes ( 10 ) ,
59
- } ) ;
60
- services . AddSingleton ( appConfig ) ;
48
+ if ( r2AccessKey != null )
49
+ appConfig . R2AccessKey = r2AccessKey ;
61
50
62
51
var s3Client = new AmazonS3Client ( appConfig . R2AccessId , appConfig . R2AccessKey , new AmazonS3Config
63
52
{
@@ -66,16 +55,16 @@ public void Configure(IWebHostBuilder builder) => builder
66
55
services . AddSingleton ( s3Client ) ;
67
56
68
57
services . AddPlugin ( new CorsFeature ( allowedHeaders : "Content-Type,Authorization" ,
69
- allowOriginWhitelist : new [ ] {
58
+ allowOriginWhitelist : [
70
59
"https://localhost:5002" ,
71
60
"http://localhost:5000" ,
72
61
"http://localhost:8080" ,
73
62
"https://diffusion.works" ,
74
63
appConfig . BaseUrl ,
75
64
"https://blazordiffusion.com" ,
76
65
"https://www.blazordiffusion.com" ,
77
- "https://pub-e17dff5b2d09437a97efdbb7f6ee3701.r2.dev" , // CDN diffusion-client public bucket
78
- } , allowCredentials : true ) ) ;
66
+ "https://pub-e17dff5b2d09437a97efdbb7f6ee3701.r2.dev" // CDN diffusion-client public bucket
67
+ ] , allowCredentials : true ) ) ;
79
68
80
69
var hasR2 = ! string . IsNullOrEmpty ( appConfig . R2AccessId ) ;
81
70
if ( ! hasR2 )
@@ -103,26 +92,17 @@ public void Configure(IWebHostBuilder builder) => builder
103
92
transformFile : ImageUtils . TransformAvatarAsync )
104
93
) ) ;
105
94
106
- #if DEBUG
107
- var aiServerClient = new JsonApiClient ( "https://localhost:5005/" ) ;
108
- #else
109
- var aiServerClient = new JsonApiClient ( "https://openai.servicestack.net/" ) ;
110
- #endif
111
- // If development, ignore SSL
95
+ var aiServerClient = new JsonApiClient ( appConfig . AiServerBaseUrl ) ;
112
96
if ( context . HostingEnvironment . IsDevelopment ( ) )
113
97
{
114
- aiServerClient = new JsonApiClient ( "https://localhost:5005/" ) ;
115
- HttpClientHandler ? clientHandler = new HttpClientHandler
116
- {
98
+ // If development, Ignore local SSL Errors
99
+ var clientHandler = new HttpClientHandler {
117
100
ServerCertificateCustomValidationCallback = ( message , certificate2 , arg3 , arg4 ) => true
118
101
} ;
119
102
HttpUtils . CreateClient = ( ) => new HttpClient ( clientHandler ) ;
120
- // Ignore local SSL Errors
121
103
aiServerClient = IgnoreSslValidation ( aiServerClient ) ;
122
104
}
123
-
124
- if ( ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "AI_SERVER_APIKEY" ) ) )
125
- aiServerClient . AddHeader ( "Authorization" , "Bearer " + Environment . GetEnvironmentVariable ( "AI_SERVER_APIKEY" ) ) ;
105
+ aiServerClient . AddHeader ( "Authorization" , "Bearer " + appConfig . AiServerApiKey ) ;
126
106
127
107
services . AddSingleton < IStableDiffusionClient > ( x => new AiServerClient
128
108
{
0 commit comments