add resource folder to config for proper folder auto upload

This commit is contained in:
Alex Bezdieniezhnykh
2024-12-24 12:55:36 +02:00
parent 48c9ccbfda
commit 81dcb2a92e
4 changed files with 12 additions and 9 deletions
+1
View File
@@ -5,4 +5,5 @@ public class ApiConfig
public string Url { get; set; } = null!; public string Url { get; set; } = null!;
public int RetryCount {get;set;} public int RetryCount {get;set;}
public double TimeoutSeconds { get; set; } public double TimeoutSeconds { get; set; }
public string ResourcesFolder { get; set; } = "";
} }
@@ -12,26 +12,26 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
{ {
const string JSON_MEDIA = "application/json"; const string JSON_MEDIA = "application/json";
private static ApiConfig _apiConfig = null!;
private string Email { get; set; } = null!; private string Email { get; set; } = null!;
private SecureString Password { get; set; } = new(); private SecureString Password { get; set; } = new();
private string JwtToken { get; set; } = null!; private string JwtToken { get; set; } = null!;
public User User { get; set; } = null!; public User User { get; set; } = null!;
public static AzaionApiClient Create(ApiCredentials credentials) public static AzaionApiClient Create(ApiCredentials credentials)
{ {
ApiConfig apiConfig;
try try
{ {
if (!File.Exists(SecurityConstants.CONFIG_PATH)) if (!File.Exists(SecurityConstants.CONFIG_PATH))
throw new FileNotFoundException(SecurityConstants.CONFIG_PATH); throw new FileNotFoundException(SecurityConstants.CONFIG_PATH);
var configStr = File.ReadAllText(SecurityConstants.CONFIG_PATH); var configStr = File.ReadAllText(SecurityConstants.CONFIG_PATH);
apiConfig = JsonConvert.DeserializeObject<SecureAppConfig>(configStr)!.ApiConfig; _apiConfig = JsonConvert.DeserializeObject<SecureAppConfig>(configStr)!.ApiConfig;
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); Console.WriteLine(e);
apiConfig = new ApiConfig _apiConfig = new ApiConfig
{ {
Url = SecurityConstants.DEFAULT_API_URL, Url = SecurityConstants.DEFAULT_API_URL,
RetryCount = SecurityConstants.DEFAULT_API_RETRY_COUNT , RetryCount = SecurityConstants.DEFAULT_API_RETRY_COUNT ,
@@ -41,8 +41,8 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
var api = new AzaionApiClient(new HttpClient var api = new AzaionApiClient(new HttpClient
{ {
BaseAddress = new Uri(apiConfig.Url), BaseAddress = new Uri(_apiConfig.Url),
Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds) Timeout = TimeSpan.FromSeconds(_apiConfig.TimeoutSeconds)
}); });
api.EnterCredentials(credentials); api.EnterCredentials(credentials);
@@ -60,7 +60,7 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable
public async Task<Stream> GetResource(string fileName, string password, HardwareInfo hardware) public async Task<Stream> GetResource(string fileName, string password, HardwareInfo hardware)
{ {
var response = await Send(httpClient, new HttpRequestMessage(HttpMethod.Post, "/resources/get") var response = await Send(httpClient, new HttpRequestMessage(HttpMethod.Post, $"/resources/get/{_apiConfig.ResourcesFolder}")
{ {
Content = new StringContent(JsonConvert.SerializeObject(new { fileName, password, hardware }), Encoding.UTF8, JSON_MEDIA) Content = new StringContent(JsonConvert.SerializeObject(new { fileName, password, hardware }), Encoding.UTF8, JSON_MEDIA)
}); });
+1
View File
@@ -3,6 +3,7 @@
"Url": "https://api.azaion.com/", "Url": "https://api.azaion.com/",
"RetryCount": 3, "RetryCount": 3,
"TimeoutSeconds": 40.0, "TimeoutSeconds": 40.0,
"ResourcesFolder": "stage",
"TokenFile": "token.txt" "TokenFile": "token.txt"
}, },
"DirectoriesConfig": { "DirectoriesConfig": {
+3 -2
View File
@@ -3,6 +3,7 @@ set CONFIG=%1
@echo off @echo off
set API_URL=https://api.azaion.com set API_URL=https://api.azaion.com
set RESOURCES_FOLDER=stage
set EMAIL=uploader@azaion.com set EMAIL=uploader@azaion.com
set PASSWORD=Az@1on_10Upl0@der set PASSWORD=Az@1on_10Upl0@der
@@ -28,12 +29,12 @@ for /f "tokens=2 delims=:" %%a in ('echo %RESPONSE% ^| findstr /i "token"') do (
echo Uploading files to resources... echo Uploading files to resources...
curl --location %API_URL%/resources ^ curl --location %API_URL%/resources/%RESOURCES_FOLDER% ^
-H "Authorization: Bearer %TOKEN%" ^ -H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: multipart/form-data" ^ -H "Content-Type: multipart/form-data" ^
--form "data=@%FILE1_TO_UPLOAD%" --form "data=@%FILE1_TO_UPLOAD%"
curl --location %API_URL%/resources ^ curl --location %API_URL%/resources/%RESOURCES_FOLDER% ^
-H "Authorization: Bearer %TOKEN%" ^ -H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: multipart/form-data" ^ -H "Content-Type: multipart/form-data" ^
--form "data=@%FILE2_TO_UPLOAD%" --form "data=@%FILE2_TO_UPLOAD%"