Compare commits
	
		
			2 Commits
		
	
	
		
			7383a5cff8
			...
			6b1dda41bc
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6b1dda41bc | |||
| fd1c47196d | 
| @@ -59,6 +59,7 @@ | |||||||
|         <PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3"/> |         <PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3"/> | ||||||
|         <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.3"/> |         <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.3"/> | ||||||
|         <PackageReference Include="System.ServiceModel.Syndication" Version="9.0.7" /> |         <PackageReference Include="System.ServiceModel.Syndication" Version="9.0.7" /> | ||||||
|  |         <PackageReference Include="TencentCloudSDK.Tmt" Version="3.0.1276" /> | ||||||
|     </ItemGroup> |     </ItemGroup> | ||||||
|  |  | ||||||
|     <ItemGroup> |     <ItemGroup> | ||||||
|   | |||||||
							
								
								
									
										1882
									
								
								DysonNetwork.Sphere/Migrations/20250731065135_AddCheckInBackdated.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1882
									
								
								DysonNetwork.Sphere/Migrations/20250731065135_AddCheckInBackdated.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | using Microsoft.EntityFrameworkCore.Migrations; | ||||||
|  |  | ||||||
|  | #nullable disable | ||||||
|  |  | ||||||
|  | namespace DysonNetwork.Sphere.Migrations | ||||||
|  | { | ||||||
|  |     /// <inheritdoc /> | ||||||
|  |     public partial class AddCheckInBackdated : Migration | ||||||
|  |     { | ||||||
|  |         /// <inheritdoc /> | ||||||
|  |         protected override void Up(MigrationBuilder migrationBuilder) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <inheritdoc /> | ||||||
|  |         protected override void Down(MigrationBuilder migrationBuilder) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -24,7 +24,7 @@ namespace DysonNetwork.Sphere.Migrations | |||||||
|         { |         { | ||||||
| #pragma warning disable 612, 618 | #pragma warning disable 612, 618 | ||||||
|             modelBuilder |             modelBuilder | ||||||
|                 .HasAnnotation("ProductVersion", "9.0.3") |                 .HasAnnotation("ProductVersion", "9.0.7") | ||||||
|                 .HasAnnotation("Relational:MaxIdentifierLength", 63); |                 .HasAnnotation("Relational:MaxIdentifierLength", 63); | ||||||
|  |  | ||||||
|             NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); |             NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ using DysonNetwork.Shared.GeoIp; | |||||||
| using DysonNetwork.Sphere.WebReader; | using DysonNetwork.Sphere.WebReader; | ||||||
| using DysonNetwork.Sphere.Developer; | using DysonNetwork.Sphere.Developer; | ||||||
| using DysonNetwork.Sphere.Discovery; | using DysonNetwork.Sphere.Discovery; | ||||||
|  | using DysonNetwork.Sphere.Translation; | ||||||
|  |  | ||||||
| namespace DysonNetwork.Sphere.Startup; | namespace DysonNetwork.Sphere.Startup; | ||||||
|  |  | ||||||
| @@ -166,7 +167,15 @@ public static class ServiceCollectionExtensions | |||||||
|         services.AddScoped<WebFeedService>(); |         services.AddScoped<WebFeedService>(); | ||||||
|         services.AddScoped<DiscoveryService>(); |         services.AddScoped<DiscoveryService>(); | ||||||
|         services.AddScoped<CustomAppService>(); |         services.AddScoped<CustomAppService>(); | ||||||
|          |  | ||||||
|  |         var translationProvider = configuration["Translation:Provider"]?.ToLower(); | ||||||
|  |         switch (translationProvider) | ||||||
|  |         { | ||||||
|  |             case "tencent": | ||||||
|  |                 services.AddScoped<ITranslationProvider, TencentTranslation>(); | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return services; |         return services; | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										6
									
								
								DysonNetwork.Sphere/Translation/ITranslationProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								DysonNetwork.Sphere/Translation/ITranslationProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | namespace DysonNetwork.Sphere.Translation; | ||||||
|  |  | ||||||
|  | public interface ITranslationProvider | ||||||
|  | { | ||||||
|  |     public Task<string> Translate(string text, string targetLanguage); | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								DysonNetwork.Sphere/Translation/TencentTranslation.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								DysonNetwork.Sphere/Translation/TencentTranslation.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | using TencentCloud.Common; | ||||||
|  | using TencentCloud.Tmt.V20180321; | ||||||
|  | using TencentCloud.Tmt.V20180321.Models; | ||||||
|  |  | ||||||
|  | namespace DysonNetwork.Sphere.Translation; | ||||||
|  |  | ||||||
|  | public class TencentTranslation(IConfiguration configuration) : ITranslationProvider | ||||||
|  | { | ||||||
|  |     private readonly string _region = configuration["Translation:Region"]!; | ||||||
|  |     private readonly Credential _apiCredential = new Credential | ||||||
|  |     { | ||||||
|  |         SecretId = configuration["Translation:SecretId"]!, | ||||||
|  |         SecretKey = configuration["Translation:SecretKey"]! | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     public async Task<string> Translate(string text, string targetLanguage) | ||||||
|  |     { | ||||||
|  |         var client = new TmtClient(_apiCredential, _region); | ||||||
|  |         var request = new TextTranslateRequest(); | ||||||
|  |         request.SourceText = text; | ||||||
|  |         request.Source = "auto"; | ||||||
|  |         request.Target = targetLanguage; | ||||||
|  |         var response = await client.TextTranslate(request); | ||||||
|  |         return response.TargetText; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										21
									
								
								DysonNetwork.Sphere/Translation/TranslationController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								DysonNetwork.Sphere/Translation/TranslationController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | |||||||
|  | using DysonNetwork.Pass.Account; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  |  | ||||||
|  | namespace DysonNetwork.Sphere.Translation; | ||||||
|  |  | ||||||
|  | [ApiController] | ||||||
|  | [Route("translate")] | ||||||
|  | public class TranslationController(ITranslationProvider provider) : ControllerBase | ||||||
|  | { | ||||||
|  |     [HttpPost] | ||||||
|  |     [Authorize] | ||||||
|  |     public async Task<ActionResult<string>> Translate([FromBody] string text, [FromQuery] string targetLanguage) | ||||||
|  |     { | ||||||
|  |         if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); | ||||||
|  |         if (currentUser.PerkSubscription is null) | ||||||
|  |             return StatusCode(403, "You need a subscription to use this feature."); | ||||||
|  |  | ||||||
|  |         return await provider.Translate(text, targetLanguage); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -29,6 +29,12 @@ | |||||||
|       "PreferredRegion": "us-east-1" |       "PreferredRegion": "us-east-1" | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|  |   "Translation": { | ||||||
|  |     "Provider": "Tencent", | ||||||
|  |     "Region": "ap-hongkong", | ||||||
|  |     "SecretId": "", | ||||||
|  |     "SecretKey": "" | ||||||
|  |   }, | ||||||
|   "KnownProxies": [ |   "KnownProxies": [ | ||||||
|     "127.0.0.1", |     "127.0.0.1", | ||||||
|     "::1" |     "::1" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user