Add support private repo images

This commit is contained in:
Sergio Padrino 2023-03-28 09:57:29 +02:00
parent 9120bdf22c
commit 86e79e8ab0

View file

@ -1,9 +1,19 @@
import { EndpointToken } from '../lib/endpoint-token'
import { OrderedWebRequest } from './ordered-webrequest'
function isEnterpriseAvatarPath(pathname: string) {
return pathname.startsWith('/api/v3/enterprise/avatars/')
}
function isGitHubRepoAssetPath(pathname: string) {
// Matches paths like: /repo/owner/assets/userID/guid
return /^\/[^/]+\/[^/]+\/assets\/[^/]+\/[^/]+\/?$/.test(pathname)
}
/**
* Installs a web request filter which adds the Authorization header for
* unauthenticated requests to the GHES/GHAE private avatars API.
* unauthenticated requests to the GHES/GHAE private avatars API, and for private
* repo assets.
*
* Returns a method that can be used to update the list of signed-in accounts
* which is used to resolve which token to use.
@ -17,7 +27,10 @@ export function installAuthenticatedAvatarFilter(
const { origin, pathname } = new URL(details.url)
const token = originTokens.get(origin)
if (token && pathname.startsWith('/api/v3/enterprise/avatars/')) {
if (
token &&
(isEnterpriseAvatarPath(pathname) || isGitHubRepoAssetPath(pathname))
) {
return {
requestHeaders: {
...details.requestHeaders,