This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<string> CreateFolder(string folderName, string[] parentIds, UserCredential credential) | |
| { | |
| try | |
| { | |
| var service = GetDriveService(credential); | |
| var fileMetadata = new Google.Apis.Drive.v3.Data.File() | |
| { | |
| Name = folderName, | |
| MimeType = "application/vnd.google-apps.folder", // folder MIME type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.ComponentModel; | |
| namespace CloudBackup.Enums | |
| { | |
| public enum MimeType | |
| { | |
| [Description("")] | |
| Unknown, | |
| [Description("audio")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using CloudBackup.Enums; | |
| using Google.Apis.Drive.v3.Data; | |
| namespace CloudBackup.Dtos | |
| { | |
| public class CreateRequest | |
| { | |
| public string Name { get; set; } | |
| public MimeType MimeType { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<List<Google.Apis.Drive.v3.Data.File>> GetAllList(UserCredential credential) | |
| { | |
| var service = GetDriveService(credential); | |
| var allFiles = new List<Google.Apis.Drive.v3.Data.File>(); | |
| string pageToken = null; | |
| do | |
| { | |
| var listRequest = service.Files.List(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<List<Google.Apis.Drive.v3.Data.File>> GetAllList(UserCredential credential) | |
| { | |
| var service = GetDriveService(credential); | |
| //建立 file list request | |
| var listRequest = service.Files.List(); | |
| //列出需要取回的檔案屬性 | |
| listRequest.Fields = "files(id,name,parents,mimeType,size,capabilities,modifiedTime,webViewLink,webContentLink)"; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private DriveService GetDriveService(IConfigurableHttpClientInitializer credential) | |
| { | |
| return new DriveService(new BaseClientService.Initializer | |
| { | |
| HttpClientInitializer = credential, | |
| // 這個應用程式名稱可隨意取名,用途是區分GCP日誌記錄中的相關資訊。 | |
| ApplicationName = "Drive API" | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public UserCredential GetGoogleCredential(TokenResponse res) | |
| { | |
| var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer | |
| { | |
| ClientSecrets = new ClientSecrets | |
| { | |
| ClientId = AppSettings.Value.GoogleDrive.ClientId, | |
| ClientSecret = AppSettings.Value.GoogleDrive.ClientSecret | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UpdateCredentialResponse | |
| { | |
| public string access_token {get; set;} | |
| public int expires_in {get; set;} | |
| public string scope {get; set;} | |
| public string token_type {get; set;} | |
| public string id_token {get; set;} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RefreshAccessTokenRequest | |
| { | |
| public string AccessToken { get; set; } | |
| public string RefreshToken { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Logging": { | |
| "LogLevel": { | |
| "Default": "Information", | |
| "Microsoft.AspNetCore": "Warning" | |
| } | |
| }, | |
| "AppSettings": { | |
| "GoogleDrive": { | |
| "ClientId":"{用戶端憑證 ID}", |