-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlobLocationGenerator.cs
35 lines (29 loc) · 1.13 KB
/
BlobLocationGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Fifthweek.Api.FileManagement.Shared
{
using Fifthweek.Api.Channels.Shared;
using Fifthweek.Shared;
public class BlobLocationGenerator : IBlobLocationGenerator
{
public BlobLocation GetBlobLocation(ChannelId channelId, FileId fileId, string filePurpose)
{
fileId.AssertNotNull("fileId");
filePurpose.AssertNotNull("filePurpose");
var purpose = FilePurposes.TryGetFilePurpose(filePurpose);
if (purpose == null)
{
throw new BadRequestException("Unknown file purpose.");
}
if (purpose.IsPublic)
{
return new BlobLocation(Constants.PublicFileBlobContainerName, fileId.Value.EncodeGuid());
}
channelId.AssertNotNull("channelId");
return new BlobLocation(this.GetBlobContainerName(channelId), fileId.Value.EncodeGuid());
}
public string GetBlobContainerName(ChannelId channelId)
{
// https://msdn.microsoft.com/en-us/library/azure/dd135715.aspx
return channelId.Value.ToString("N");
}
}
}