-
Notifications
You must be signed in to change notification settings - Fork 659
Expand file tree
/
Copy pathFlatContainerPackagePathProvider.cs
More file actions
75 lines (60 loc) · 2.24 KB
/
FlatContainerPackagePathProvider.cs
File metadata and controls
75 lines (60 loc) · 2.24 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using NuGet.Services.Metadata.Catalog.Helpers;
namespace NuGet.Services.Metadata.Catalog
{
public class FlatContainerPackagePathProvider
{
private readonly string _container;
public FlatContainerPackagePathProvider(string container)
{
_container = container;
}
public string GetPackagePath(string id, string version)
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}
if (version == null)
{
throw new ArgumentNullException(nameof(version));
}
Utils.AssertValidPackageId(id);
Utils.AssertValidPackageVersion(version);
var idLowerCase = id.ToLowerInvariant();
var versionLowerCase = NuGetVersionUtility.NormalizeVersion(version).ToLowerInvariant();
var packageFileName = PackageUtility.GetPackageFileName(idLowerCase, versionLowerCase);
return $"{_container}/{idLowerCase}/{versionLowerCase}/{packageFileName}";
}
public string GetIconPath(string id, string version)
{
return GetIconPath(id, version, normalize: true);
}
public string GetIconPath(string id, string version, bool normalize)
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}
if (version == null)
{
throw new ArgumentNullException(nameof(version));
}
Utils.AssertValidPackageId(id);
Utils.AssertValidPackageVersion(version);
var idLowerCase = id.ToLowerInvariant();
string versionLowerCase;
if (normalize)
{
versionLowerCase = NuGetVersionUtility.NormalizeVersion(version).ToLowerInvariant();
}
else
{
versionLowerCase = version.ToLowerInvariant();
}
return $"{_container}/{idLowerCase}/{versionLowerCase}/icon";
}
}
}