-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Allow use of multiple extension galleries #2620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -343,7 +343,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService { | |||||
|
||||||
declare readonly _serviceBrand: undefined; | ||||||
|
||||||
private extensionsGalleryUrl: string | undefined; | ||||||
private extensionsGalleryUrl: string[] | undefined; | ||||||
private extensionsControlUrl: string | undefined; | ||||||
|
||||||
private readonly commonHeadersPromise: Promise<{ [key: string]: string; }>; | ||||||
|
@@ -363,8 +363,13 @@ export class ExtensionGalleryService implements IExtensionGalleryService { | |||||
this.commonHeadersPromise = resolveMarketplaceHeaders(productService.version, this.environmentService, this.fileService, storageService); | ||||||
} | ||||||
|
||||||
private api(path = ''): string { | ||||||
return `${this.extensionsGalleryUrl}${path}`; | ||||||
private api(path = ''): string[] { | ||||||
if (!!this.extensionsGalleryUrl) { | ||||||
return this.extensionsGalleryUrl?.map( | ||||||
(galleryUrl) => `${galleryUrl}${path}` | ||||||
); | ||||||
} | ||||||
return []; | ||||||
} | ||||||
|
||||||
isEnabled(): boolean { | ||||||
|
@@ -543,43 +548,53 @@ export class ExtensionGalleryService implements IExtensionGalleryService { | |||||
'Content-Length': String(data.length) | ||||||
}; | ||||||
|
||||||
const context = await this.requestService.request({ | ||||||
type: 'POST', | ||||||
url: this.api('/extensionquery'), | ||||||
data, | ||||||
headers | ||||||
}, token); | ||||||
const galleryExtensions: IRawGalleryExtension[] = []; | ||||||
const seenExtensions: Set<String> = new Set(); | ||||||
|
||||||
if (context.res.statusCode && context.res.statusCode >= 400 && context.res.statusCode < 500) { | ||||||
return { galleryExtensions: [], total: 0 }; | ||||||
} | ||||||
for (const url of this.api('/extensionquery')) { | ||||||
const context = await this.requestService.request({ | ||||||
type: 'POST', | ||||||
url: url, | ||||||
data, | ||||||
headers | ||||||
}, token); | ||||||
|
||||||
const result = await asJson<IRawGalleryQueryResult>(context); | ||||||
if (result) { | ||||||
const r = result.results[0]; | ||||||
const galleryExtensions = r.extensions; | ||||||
const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0]; | ||||||
const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0; | ||||||
if (context.res.statusCode && context.res.statusCode >= 400 && context.res.statusCode < 500) { | ||||||
return { galleryExtensions: [], total: 0 }; | ||||||
} | ||||||
|
||||||
return { galleryExtensions, total }; | ||||||
const result = await asJson<IRawGalleryQueryResult>(context); | ||||||
if (result) { | ||||||
const r = result.results[0]; | ||||||
for (const extension of r.extensions) { | ||||||
if (!seenExtensions.has(extension.extensionId)) { | ||||||
galleryExtensions.push(extension); | ||||||
seenExtensions.add(extension.extensionId); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
return { galleryExtensions: [], total: 0 }; | ||||||
return { galleryExtensions, total: galleryExtensions.length }; | ||||||
} | ||||||
|
||||||
async reportStatistic(publisher: string, name: string, version: string, type: StatisticType): Promise<void> { | ||||||
// TODO: investigate further - currently we just send stats everywhere | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know folks have GitLens and tools to know who left a TODO comment but at least this puts your name right there so we don't forget.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 will fix! |
||||||
// this is only used in one place - uninstall tracking - but | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfinished comment? Was there more to this sentence? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, there was! |
||||||
if (!this.isEnabled()) { | ||||||
return undefined; | ||||||
} | ||||||
|
||||||
const commonHeaders = await this.commonHeadersPromise; | ||||||
const headers = { ...commonHeaders, Accept: '*/*;api-version=4.0-preview.1' }; | ||||||
try { | ||||||
await this.requestService.request({ | ||||||
type: 'POST', | ||||||
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`), | ||||||
headers | ||||||
}, CancellationToken.None); | ||||||
} catch (error) { /* Ignore */ } | ||||||
for (const url of this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`)) { | ||||||
try { | ||||||
await this.requestService.request({ | ||||||
type: 'POST', | ||||||
url: url, | ||||||
headers | ||||||
}, CancellationToken.None); | ||||||
} catch (error) { /* Ignore */ } | ||||||
} | ||||||
} | ||||||
|
||||||
async download(extension: IGalleryExtension, location: URI, operation: InstallOperation): Promise<void> { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the double
!
to convert it to a boolean? Does it have a performance advantage over the Boolean function? Only asking/suggesting if it might improve readability - obviously your call :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I should just use
this.isEnabled()
instead - does the same check in practice but is probably ideal since the code already exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking!