Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/extensionManagement/common/extensionGalleryManifestService.ts
5283 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Event } from '../../../base/common/event.js';
7
import { Disposable } from '../../../base/common/lifecycle.js';
8
import { IProductService } from '../../product/common/productService.js';
9
import { ExtensionGalleryResourceType, Flag, IExtensionGalleryManifest, IExtensionGalleryManifestService, ExtensionGalleryManifestStatus } from './extensionGalleryManifest.js';
10
import { FilterType, SortBy } from './extensionManagement.js';
11
12
type ExtensionGalleryConfig = {
13
readonly serviceUrl: string;
14
readonly itemUrl: string;
15
readonly publisherUrl: string;
16
readonly resourceUrlTemplate: string;
17
readonly extensionUrlTemplate: string;
18
readonly controlUrl: string;
19
readonly nlsBaseUrl: string;
20
};
21
22
export class ExtensionGalleryManifestService extends Disposable implements IExtensionGalleryManifestService {
23
24
readonly _serviceBrand: undefined;
25
readonly onDidChangeExtensionGalleryManifest = Event.None;
26
readonly onDidChangeExtensionGalleryManifestStatus = Event.None;
27
28
get extensionGalleryManifestStatus(): ExtensionGalleryManifestStatus {
29
return !!this.productService.extensionsGallery?.serviceUrl ? ExtensionGalleryManifestStatus.Available : ExtensionGalleryManifestStatus.Unavailable;
30
}
31
32
constructor(
33
@IProductService protected readonly productService: IProductService,
34
) {
35
super();
36
}
37
38
async getExtensionGalleryManifest(): Promise<IExtensionGalleryManifest | null> {
39
const extensionsGallery = this.productService.extensionsGallery as ExtensionGalleryConfig | undefined;
40
if (!extensionsGallery?.serviceUrl) {
41
return null;
42
}
43
44
const resources = [
45
{
46
id: `${extensionsGallery.serviceUrl}/extensionquery`,
47
type: ExtensionGalleryResourceType.ExtensionQueryService
48
},
49
{
50
id: `${extensionsGallery.serviceUrl}/vscode/{publisher}/{name}/latest`,
51
type: ExtensionGalleryResourceType.ExtensionLatestVersionUri
52
},
53
{
54
id: `${extensionsGallery.serviceUrl}/publishers/{publisher}/extensions/{name}/{version}/stats?statType={statTypeName}`,
55
type: ExtensionGalleryResourceType.ExtensionStatisticsUri
56
},
57
];
58
59
if (extensionsGallery.publisherUrl) {
60
resources.push({
61
id: `${extensionsGallery.publisherUrl}/{publisher}`,
62
type: ExtensionGalleryResourceType.PublisherViewUri
63
});
64
}
65
66
if (extensionsGallery.itemUrl) {
67
resources.push({
68
id: `${extensionsGallery.itemUrl}?itemName={publisher}.{name}`,
69
type: ExtensionGalleryResourceType.ExtensionDetailsViewUri
70
});
71
resources.push({
72
id: `${extensionsGallery.itemUrl}?itemName={publisher}.{name}&ssr=false#review-details`,
73
type: ExtensionGalleryResourceType.ExtensionRatingViewUri
74
});
75
}
76
77
if (extensionsGallery.resourceUrlTemplate) {
78
resources.push({
79
id: extensionsGallery.resourceUrlTemplate,
80
type: ExtensionGalleryResourceType.ExtensionResourceUri
81
});
82
}
83
84
const filtering = [
85
{
86
name: FilterType.Tag,
87
value: 1,
88
},
89
{
90
name: FilterType.ExtensionId,
91
value: 4,
92
},
93
{
94
name: FilterType.Category,
95
value: 5,
96
},
97
{
98
name: FilterType.ExtensionName,
99
value: 7,
100
},
101
{
102
name: FilterType.Target,
103
value: 8,
104
},
105
{
106
name: FilterType.Featured,
107
value: 9,
108
},
109
{
110
name: FilterType.SearchText,
111
value: 10,
112
},
113
{
114
name: FilterType.ExcludeWithFlags,
115
value: 12,
116
},
117
];
118
119
const sorting = [
120
{
121
name: SortBy.NoneOrRelevance,
122
value: 0,
123
},
124
{
125
name: SortBy.LastUpdatedDate,
126
value: 1,
127
},
128
{
129
name: SortBy.Title,
130
value: 2,
131
},
132
{
133
name: SortBy.PublisherName,
134
value: 3,
135
},
136
{
137
name: SortBy.InstallCount,
138
value: 4,
139
},
140
{
141
name: SortBy.AverageRating,
142
value: 6,
143
},
144
{
145
name: SortBy.PublishedDate,
146
value: 10,
147
},
148
{
149
name: SortBy.WeightedRating,
150
value: 12,
151
},
152
];
153
154
const flags = [
155
{
156
name: Flag.None,
157
value: 0x0,
158
},
159
{
160
name: Flag.IncludeVersions,
161
value: 0x1,
162
},
163
{
164
name: Flag.IncludeFiles,
165
value: 0x2,
166
},
167
{
168
name: Flag.IncludeCategoryAndTags,
169
value: 0x4,
170
},
171
{
172
name: Flag.IncludeSharedAccounts,
173
value: 0x8,
174
},
175
{
176
name: Flag.IncludeVersionProperties,
177
value: 0x10,
178
},
179
{
180
name: Flag.ExcludeNonValidated,
181
value: 0x20,
182
},
183
{
184
name: Flag.IncludeInstallationTargets,
185
value: 0x40,
186
},
187
{
188
name: Flag.IncludeAssetUri,
189
value: 0x80,
190
},
191
{
192
name: Flag.IncludeStatistics,
193
value: 0x100,
194
},
195
{
196
name: Flag.IncludeLatestVersionOnly,
197
value: 0x200,
198
},
199
{
200
name: Flag.Unpublished,
201
value: 0x1000,
202
},
203
{
204
name: Flag.IncludeNameConflictInfo,
205
value: 0x8000,
206
},
207
{
208
name: Flag.IncludeLatestPrereleaseAndStableVersionOnly,
209
value: 0x10000,
210
},
211
];
212
213
return {
214
version: '',
215
resources,
216
capabilities: {
217
extensionQuery: {
218
filtering,
219
sorting,
220
flags,
221
},
222
signing: {
223
allPublicRepositorySigned: true,
224
}
225
}
226
};
227
}
228
}
229
230