Files
duplicati/proprietary/GoogleWorkspace/SourceItems/ContactSourceEntry.cs
T
Kenneth Skovhede da246874ec 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.
2026-02-04 15:44:23 +01:00

45 lines
1.9 KiB
C#

// Copyright (c) 2026 Duplicati Inc. All rights reserved.
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Google.Apis.PeopleService.v1.Data;
using System.Runtime.CompilerServices;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
internal class ContactSourceEntry(string parentPath, Person person)
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, person.Names?.FirstOrDefault()?.DisplayName ?? person.ResourceName)), null, null)
{
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new ContactFileSourceEntry(this.Path, person);
if (person.Photos != null)
{
foreach (var photo in person.Photos)
{
// Skip if it's the default placeholder (if we can detect it)
// Usually default photos have a specific URL pattern or metadata.
// For now, let's just include all photos.
if (cancellationToken.IsCancellationRequested) yield break;
yield return new ContactPhotoSourceEntry(this.Path, photo);
}
}
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "gsuite:v", "1" },
{ "gsuite:Type", SourceItemType.Contact.ToString() },
{ "gsuite:Name", person.Names?.FirstOrDefault()?.DisplayName ?? person.ResourceName },
{ "gsuite:id", person.ResourceName },
{ "gsuite:Etag", person.ETag }
}
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value));
}
}