Initial implementation of Google Workspace backup.
This is a WIP and still needs the restore part implemented. Not all resources are fully tested but basic elements work.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2026 Duplicati Inc. All rights reserved.
|
||||
|
||||
using Duplicati.Library.Common.IO;
|
||||
using Google.Apis.Keep.v1.Data;
|
||||
|
||||
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
|
||||
|
||||
internal class KeepNoteAttachmentSourceEntry(SourceProvider provider, string parentPath, Attachment attachment)
|
||||
: StreamResourceEntryBase(SystemIO.IO_OS.PathCombine(parentPath, attachment.Name.Split('/').Last()), DateTime.UnixEpoch, DateTime.UnixEpoch)
|
||||
{
|
||||
public override long Size => -1;
|
||||
|
||||
public override async Task<Stream> OpenRead(CancellationToken cancellationToken)
|
||||
{
|
||||
// Keep API attachments are downloaded via media URL?
|
||||
// attachment.Name is like "notes/123/attachments/456".
|
||||
// Docs say: GET https://keep.googleapis.com/v1/notes/{noteId}/attachments/{attachmentId}?alt=media
|
||||
|
||||
var service = provider.ApiHelper.GetKeepService();
|
||||
var url = $"https://keep.googleapis.com/v1/{attachment.Name}?alt=media";
|
||||
|
||||
var response = await service.HttpClient.GetAsync(url, cancellationToken);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
await response.Content.CopyToAsync(stream, cancellationToken);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"Cannot download attachment: {response.StatusCode}");
|
||||
}
|
||||
|
||||
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new Dictionary<string, string?>
|
||||
{
|
||||
{ "gsuite:v", "1" },
|
||||
{ "gsuite:Type", SourceItemType.KeepNoteAttachment.ToString() },
|
||||
{ "gsuite:Name", attachment.Name.Split('/').Last() },
|
||||
{ "gsuite:id", attachment.Name },
|
||||
{ "gsuite:MimeType", attachment.MimeType != null ? string.Join(",", attachment.MimeType) : null }
|
||||
}
|
||||
.Where(kv => !string.IsNullOrEmpty(kv.Value))
|
||||
.ToDictionary(kv => kv.Key, kv => kv.Value));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user