mirror of
https://github.com/bitwarden/server
synced 2026-02-14 15:33:35 +00:00
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Bit.Core.Models.Data;
|
|
using Bit.Core.Models.Table;
|
|
using Newtonsoft.Json;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Bit.Core.Models.Api
|
|
{
|
|
public class AttachmentResponseModel : ResponseModel
|
|
{
|
|
public AttachmentResponseModel(string id, CipherAttachment.MetaData data, Cipher cipher, GlobalSettings globalSettings)
|
|
: base("attachment")
|
|
{
|
|
Id = id;
|
|
Url = $"{globalSettings.Attachment.BaseUrl}/{cipher.Id}/{id}";
|
|
FileName = data.FileName;
|
|
Size = data.SizeString;
|
|
SizeName = Utilities.CoreHelpers.ReadableBytesSize(data.Size);
|
|
}
|
|
|
|
public string Id { get; set; }
|
|
public string Url { get; set; }
|
|
public string FileName { get; set; }
|
|
public string Size { get; set; }
|
|
public string SizeName { get; set; }
|
|
|
|
public static IEnumerable<AttachmentResponseModel> FromCipher(Cipher cipher, GlobalSettings globalSettings)
|
|
{
|
|
var attachments = cipher.GetAttachments();
|
|
if(attachments == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return attachments.Select(a => new AttachmentResponseModel(a.Key, a.Value, cipher, globalSettings));
|
|
}
|
|
}
|
|
}
|