1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 17:42:49 -05:00
Files
bitwarden/src/Api/Vault/Models/Response/AttachmentResponseModel.cs

51 lines
1.5 KiB
C#

using Bit.Core.Models.Api;
using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bit.Core.Vault.Entities;
using Bit.Core.Vault.Models.Data;
namespace Bit.Api.Vault.Models.Response;
public class AttachmentResponseModel : ResponseModel
{
public AttachmentResponseModel(AttachmentResponseData data) : base("attachment")
{
Id = data.Id;
Url = data.Url;
FileName = data.Data.FileName;
Key = data.Data.Key;
Size = data.Data.Size.ToString();
SizeName = CoreHelpers.ReadableBytesSize(data.Data.Size);
}
public AttachmentResponseModel(string id, CipherAttachment.MetaData data, Cipher cipher,
IGlobalSettings globalSettings)
: base("attachment")
{
Id = id;
Url = $"{globalSettings.Attachment.BaseUrl}/{cipher.Id}/{id}";
FileName = data.FileName;
Key = data.Key;
Size = data.Size.ToString();
SizeName = CoreHelpers.ReadableBytesSize(data.Size);
}
public string Id { get; set; }
public string Url { get; set; }
public string FileName { get; set; }
public string Key { get; set; }
public string Size { get; set; }
public string SizeName { get; set; }
public static IEnumerable<AttachmentResponseModel> FromCipher(Cipher cipher, IGlobalSettings globalSettings)
{
var attachments = cipher.GetAttachments();
if (attachments == null)
{
return null;
}
return attachments.Select(a => new AttachmentResponseModel(a.Key, a.Value, cipher, globalSettings));
}
}