Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/extensionManagement/common/extensionGalleryManifestService.ts
3296 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
id: `${extensionsGallery.serviceUrl}/itemName/{publisher}.{name}/version/{version}/statType/{statTypeValue}/vscodewebextension`,
59
type: ExtensionGalleryResourceType.WebExtensionStatisticsUri
60
},
61
];
62
63
if (extensionsGallery.publisherUrl) {
64
resources.push({
65
id: `${extensionsGallery.publisherUrl}/{publisher}`,
66
type: ExtensionGalleryResourceType.PublisherViewUri
67
});
68
}
69
70
if (extensionsGallery.itemUrl) {
71
resources.push({
72
id: `${extensionsGallery.itemUrl}?itemName={publisher}.{name}`,
73
type: ExtensionGalleryResourceType.ExtensionDetailsViewUri
74
});
75
resources.push({
76
id: `${extensionsGallery.itemUrl}?itemName={publisher}.{name}&ssr=false#review-details`,
77
type: ExtensionGalleryResourceType.ExtensionRatingViewUri
78
});
79
}
80
81
if (extensionsGallery.resourceUrlTemplate) {
82
resources.push({
83
id: extensionsGallery.resourceUrlTemplate,
84
type: ExtensionGalleryResourceType.ExtensionResourceUri
85
});
86
}
87
88
const filtering = [
89
{
90
name: FilterType.Tag,
91
value: 1,
92
},
93
{
94
name: FilterType.ExtensionId,
95
value: 4,
96
},
97
{
98
name: FilterType.Category,
99
value: 5,
100
},
101
{
102
name: FilterType.ExtensionName,
103
value: 7,
104
},
105
{
106
name: FilterType.Target,
107
value: 8,
108
},
109
{
110
name: FilterType.Featured,
111
value: 9,
112
},
113
{
114
name: FilterType.SearchText,
115
value: 10,
116
},
117
{
118
name: FilterType.ExcludeWithFlags,
119
value: 12,
120
},
121
];
122
123
const sorting = [
124
{
125
name: SortBy.NoneOrRelevance,
126
value: 0,
127
},
128
{
129
name: SortBy.LastUpdatedDate,
130
value: 1,
131
},
132
{
133
name: SortBy.Title,
134
value: 2,
135
},
136
{
137
name: SortBy.PublisherName,
138
value: 3,
139
},
140
{
141
name: SortBy.InstallCount,
142
value: 4,
143
},
144
{
145
name: SortBy.AverageRating,
146
value: 6,
147
},
148
{
149
name: SortBy.PublishedDate,
150
value: 10,
151
},
152
{
153
name: SortBy.WeightedRating,
154
value: 12,
155
},
156
];
157
158
const flags = [
159
{
160
name: Flag.None,
161
value: 0x0,
162
},
163
{
164
name: Flag.IncludeVersions,
165
value: 0x1,
166
},
167
{
168
name: Flag.IncludeFiles,
169
value: 0x2,
170
},
171
{
172
name: Flag.IncludeCategoryAndTags,
173
value: 0x4,
174
},
175
{
176
name: Flag.IncludeSharedAccounts,
177
value: 0x8,
178
},
179
{
180
name: Flag.IncludeVersionProperties,
181
value: 0x10,
182
},
183
{
184
name: Flag.ExcludeNonValidated,
185
value: 0x20,
186
},
187
{
188
name: Flag.IncludeInstallationTargets,
189
value: 0x40,
190
},
191
{
192
name: Flag.IncludeAssetUri,
193
value: 0x80,
194
},
195
{
196
name: Flag.IncludeStatistics,
197
value: 0x100,
198
},
199
{
200
name: Flag.IncludeLatestVersionOnly,
201
value: 0x200,
202
},
203
{
204
name: Flag.Unpublished,
205
value: 0x1000,
206
},
207
{
208
name: Flag.IncludeNameConflictInfo,
209
value: 0x8000,
210
},
211
{
212
name: Flag.IncludeLatestPrereleaseAndStableVersionOnly,
213
value: 0x10000,
214
},
215
];
216
217
return {
218
version: '',
219
resources,
220
capabilities: {
221
extensionQuery: {
222
filtering,
223
sorting,
224
flags,
225
},
226
signing: {
227
allPublicRepositorySigned: true,
228
}
229
}
230
};
231
}
232
}
233
234