mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-06 22:50:30 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
54
server/FSO.Server.Api.Core/Services/AWSUpdateUploader.cs
Executable file
54
server/FSO.Server.Api.Core/Services/AWSUpdateUploader.cs
Executable file
|
@ -0,0 +1,54 @@
|
|||
using Amazon;
|
||||
using Amazon.Runtime;
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using FSO.Server.Common.Config;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FSO.Server.Api.Core.Services
|
||||
{
|
||||
public class AWSUpdateUploader : IUpdateUploader
|
||||
{
|
||||
private AWSConfig Config;
|
||||
public AWSUpdateUploader(AWSConfig config)
|
||||
{
|
||||
Config = config;
|
||||
}
|
||||
|
||||
public async Task<string> UploadFile(string destPath, string fileName, string groupName)
|
||||
{
|
||||
var region = Config.Region;
|
||||
var bucket = Config.Bucket;
|
||||
var s3config = new AmazonS3Config()
|
||||
{
|
||||
RegionEndpoint = RegionEndpoint.GetBySystemName(region),
|
||||
Timeout = new TimeSpan(1, 0, 0),
|
||||
ReadWriteTimeout = new TimeSpan(1, 0, 0),
|
||||
MaxErrorRetry = 512
|
||||
};
|
||||
|
||||
using (var aws = new AmazonS3Client(new BasicAWSCredentials(Config.AccessKeyID, Config.SecretAccessKey), s3config))
|
||||
{
|
||||
PutObjectRequest request = new PutObjectRequest()
|
||||
{
|
||||
InputStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
|
||||
BucketName = bucket,
|
||||
CannedACL = S3CannedACL.PublicRead,
|
||||
Key = destPath
|
||||
};
|
||||
PutObjectResponse response = await aws.PutObjectAsync(request);
|
||||
|
||||
if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
return $"https://s3.{region}.amazonaws.com/{bucket}/" + destPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Uploading file " + destPath + " failed with code " + response.HttpStatusCode + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue