feat(download): saner basic auth support (fix #1)
This commit is contained in:
parent
3a18eb4ca3
commit
11ac99e29f
1 changed files with 17 additions and 2 deletions
|
@ -12,6 +12,9 @@ interface DownloadBlobRequset {
|
||||||
|
|
||||||
/** Repository URL. */
|
/** Repository URL. */
|
||||||
url: string;
|
url: string;
|
||||||
|
|
||||||
|
/** Auth data for basic HTTP auth. */
|
||||||
|
auth?: { username: string, password: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LFSInfoResponse {
|
interface LFSInfoResponse {
|
||||||
|
@ -35,10 +38,17 @@ function isValidLFSInfoResponseData(val: Record<string, any>): val is LFSInfoRes
|
||||||
* Currently, the authorization header is responsibility of the caller.
|
* Currently, the authorization header is responsibility of the caller.
|
||||||
*/
|
*/
|
||||||
export default async function downloadBlobFromPointer(
|
export default async function downloadBlobFromPointer(
|
||||||
{ http: { request }, headers = {}, url }: DownloadBlobRequset,
|
{ http: { request }, headers = {}, url, auth }: DownloadBlobRequset,
|
||||||
{ info, objectPath }: Pointer,
|
{ info, objectPath }: Pointer,
|
||||||
): Promise<Buffer> {
|
): Promise<Buffer> {
|
||||||
|
|
||||||
|
const authHeaders: Record<string, string> = auth
|
||||||
|
? {
|
||||||
|
'Authorization':
|
||||||
|
`Basic ${Buffer.from(`${auth.username}:${auth.password}`).toString('base64')}`,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
// Request LFS metadata
|
// Request LFS metadata
|
||||||
|
|
||||||
const lfsInfoRequestData = {
|
const lfsInfoRequestData = {
|
||||||
|
@ -54,6 +64,7 @@ export default async function downloadBlobFromPointer(
|
||||||
// Github LFS doesn’t seem to accept this UA :(
|
// Github LFS doesn’t seem to accept this UA :(
|
||||||
// 'User-Agent': `git/isomorphic-git@${git.version()}`,
|
// 'User-Agent': `git/isomorphic-git@${git.version()}`,
|
||||||
...headers,
|
...headers,
|
||||||
|
...authHeaders,
|
||||||
'Accept': 'application/vnd.git-lfs+json',
|
'Accept': 'application/vnd.git-lfs+json',
|
||||||
'Content-Type': 'application/vnd.git-lfs+json',
|
'Content-Type': 'application/vnd.git-lfs+json',
|
||||||
},
|
},
|
||||||
|
@ -76,7 +87,11 @@ export default async function downloadBlobFromPointer(
|
||||||
const lfsObjectDownloadURL = downloadAction.href;
|
const lfsObjectDownloadURL = downloadAction.href;
|
||||||
const lfsObjectDownloadHeaders = downloadAction.header ?? {};
|
const lfsObjectDownloadHeaders = downloadAction.header ?? {};
|
||||||
|
|
||||||
const dlHeaders = { ...headers, ...lfsObjectDownloadHeaders };
|
const dlHeaders = {
|
||||||
|
...headers,
|
||||||
|
...authHeaders,
|
||||||
|
...lfsObjectDownloadHeaders,
|
||||||
|
};
|
||||||
|
|
||||||
const { body: lfsObjectBody } = await request({
|
const { body: lfsObjectBody } = await request({
|
||||||
url: lfsObjectDownloadURL,
|
url: lfsObjectDownloadURL,
|
||||||
|
|
Loading…
Reference in a new issue