WIP: Resolve all code issues

This commit is contained in:
Michał Zieliski
2024-06-18 18:39:02 +02:00
parent f93bb9cd42
commit c2a98e0386
10 changed files with 363 additions and 441 deletions

View File

@@ -2,38 +2,35 @@
using Google.Apis.Drive.v3;
using Google.Apis.Services;
namespace WebAPI
namespace WebAPI;
public class GoogleDriveHelper
{
public class GoogleDriveHelper
public DriveService? Service { get; set; }
private const string ApplicationName = "Diuna";
private static readonly string[] Scopes = { DriveService.Scope.Drive };
public GoogleDriveHelper()
{
public DriveService? Service { get; set; }
const string APPLICATION_NAME = "Diuna";
static readonly string[] Scopes = { DriveService.Scope.Drive };
public GoogleDriveHelper()
{
InitializeService();
}
private void InitializeService()
{
var credential = GetCredentialsFromFile();
Service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = APPLICATION_NAME
});
}
private GoogleCredential GetCredentialsFromFile()
{
string fileName = "client_secrets.json";
#if DEBUG
fileName = "client_secrets.Development.json";
#endif
GoogleCredential credential;
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
}
return credential;
}
InitializeService();
}
}
private void InitializeService()
{
var credential = GetCredentialsFromFile();
Service = new DriveService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName
});
}
private static GoogleCredential GetCredentialsFromFile()
{
// ReSharper disable once RedundantAssignment
var fileName = "client_secrets.json";
#if DEBUG
fileName = "client_secrets.Development.json";
#endif
using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
return credential;
}
}