Files
duplicati/proprietary/GoogleWorkspace/SourceItems/ChatMessageSourceEntry.cs
T
Kenneth Skovhede 910c56b3c4 Reworked the use of scopes.
Instead of requesting all scopes up front, each sub-section of the backup/restore will request the permissions that are relevant for the operation.

The effect is that it is not required to grant all permissions to get a backup running. If permissions are failing, that part of the backup will generate warnings for items that are excluded.
2026-02-15 22:03:57 +01:00

51 lines
2.0 KiB
C#

// Copyright (c) 2026 Duplicati Inc. All rights reserved.
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Google.Apis.HangoutsChat.v1.Data;
using Google.Apis.HangoutsChat.v1;
using Google.Apis.Drive.v3;
using System.Runtime.CompilerServices;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
internal class ChatMessageSourceEntry(string parentPath, Message message, HangoutsChatService chatService, DriveService driveService)
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, message.Name.Split('/').Last())),
message.CreateTimeDateTimeOffset.HasValue ? message.CreateTimeDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch,
DateTime.UnixEpoch)
{
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new ChatMessageFileSourceEntry(this.Path, message);
if (message.Attachment != null)
{
foreach (var attachment in message.Attachment)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new ChatAttachmentSourceEntry(this.Path, attachment, chatService, driveService);
}
}
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "gsuite:v", "1" },
{ "gsuite:Type", SourceItemType.ChatMessage.ToString() },
{ "gsuite:Name", CapMessage(message.ArgumentText ?? message.Name) },
{ "gsuite:Id", message.Name }
}
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value));
}
private static string CapMessage(string input)
{
if (string.IsNullOrEmpty(input)) return input;
return input.Length <= 50 ? input : input[..47] + "...";
}
}