提交 d21757ae 编写于 作者: J Joao Moreno

cleanup gallery service

上级 9c55870f
......@@ -33,14 +33,23 @@ export interface IGalleryExtension {
publisher: { displayName: string, publisherId: string, publisherName: string; };
versions: IGalleryExtensionVersion[];
galleryApiUrl: string;
statistics: IGalleryExtensionStatistic[];
statistics: IGalleryExtensionStatistics[];
}
export interface IGalleryExtensionStatistic {
export interface IGalleryExtensionStatistics {
statisticName: string;
value: number;
}
function getInstallCount(statistics: IGalleryExtensionStatistics[]): number {
if (!statistics) {
return 0;
}
const result = statistics.filter(s => s.statisticName === 'install')[0];
return result ? result.value : 0;
}
export class GalleryService implements IGalleryService {
public serviceId = IGalleryService;
......@@ -59,32 +68,10 @@ export class GalleryService implements IGalleryService {
return `${ this.extensionsGalleryUrl }${ path }`;
}
/**
* Extracts install count statistic.
*/
private extractInstalls(statistics: IGalleryExtensionStatistic[]): number {
// Sometimes there are no statistics.
if (!statistics) {
return 0;
}
var result = 0;
statistics.forEach(stat => {
if (stat.statisticName === 'install') {
result = stat.value;
}
})
return result;
}
public isEnabled(): boolean {
return !!this.extensionsGalleryUrl;
}
/**
* Queries VS Code Extension marketplace for extensions.
*
* Sorts by install count.
*/
public query(): TPromise<IExtension[]> {
if (!this.extensionsGalleryUrl) {
return TPromise.wrapError(new Error('No extension gallery service configured.'));
......@@ -126,7 +113,7 @@ export class GalleryService implements IGalleryService {
downloadUrl: `${ extension.versions[0].assetUri }/Microsoft.VisualStudio.Services.VSIXPackage?install=true`,
publisherId: extension.publisher.publisherId,
publisherDisplayName: extension.publisher.displayName,
installCount: this.extractInstalls(extension.statistics),
installCount: getInstallCount(extension.statistics),
date: extension.versions[0].lastUpdated,
}
}));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册