49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
// Copyright (c) 2026 Duplicati Inc. All rights reserved.
|
|
|
|
using Duplicati.Library.Common.IO;
|
|
using Duplicati.Library.Interface;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
|
|
|
|
internal class KeepSourceEntry(SourceProvider provider, string parentPath, string userId)
|
|
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, "Keep")), null, null)
|
|
{
|
|
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
|
|
{
|
|
var service = provider.ApiHelper.GetKeepService(userId);
|
|
var request = service.Notes.List();
|
|
|
|
string? nextPageToken = null;
|
|
do
|
|
{
|
|
if (cancellationToken.IsCancellationRequested) yield break;
|
|
request.PageToken = nextPageToken;
|
|
var notes = await request.ExecuteAsync(cancellationToken);
|
|
|
|
if (notes.Notes != null)
|
|
{
|
|
foreach (var note in notes.Notes)
|
|
{
|
|
if (cancellationToken.IsCancellationRequested) yield break;
|
|
yield return new KeepNoteSourceEntry(provider, this.Path, userId, note);
|
|
}
|
|
}
|
|
nextPageToken = notes.NextPageToken;
|
|
} while (!string.IsNullOrEmpty(nextPageToken));
|
|
}
|
|
|
|
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
|
|
{
|
|
return Task.FromResult(new Dictionary<string, string?>
|
|
{
|
|
{ "gsuite:v", "1" },
|
|
{ "gsuite:Type", SourceItemType.UserKeep.ToString() },
|
|
{ "gsuite:Name", "Keep" },
|
|
{ "gsuite:Id", "Keep" }
|
|
}
|
|
.Where(kv => !string.IsNullOrEmpty(kv.Value))
|
|
.ToDictionary(kv => kv.Key, kv => kv.Value));
|
|
}
|
|
}
|