refactor: DownloadBlobRequest -> generic HTTPRequest

This commit is contained in:
Anton Strogonoff 2021-11-30 21:53:33 +01:00
parent 14be6d8b78
commit 17b2eb8706
2 changed files with 25 additions and 13 deletions

View file

@ -1,22 +1,11 @@
import path from 'path';
import fsp from 'fs/promises';
import { HttpClient } from 'isomorphic-git/http/node';
import { bodyToBuffer, isWriteable } from './util';
import { Pointer } from './pointers';
import { HTTPRequest } from './types';
interface DownloadBlobRequest {
http: HttpClient;
headers?: Record<string, any>;
/** Repository URL. */
url: string;
/** Auth data for basic HTTP auth. */
auth?: { username: string, password: string }
}
interface LFSInfoResponse {
objects: {
actions: {
@ -37,7 +26,7 @@ function isValidLFSInfoResponseData(val: Record<string, any>): val is LFSInfoRes
* Downloads, caches and returns a blob corresponding to given LFS pointer.
*/
export default async function downloadBlobFromPointer(
{ http: { request }, headers = {}, url, auth }: DownloadBlobRequest,
{ http: { request }, headers = {}, url, auth }: HTTPRequest,
{ info, objectPath }: Pointer,
): Promise<Buffer> {

23
src/types.ts Normal file
View file

@ -0,0 +1,23 @@
import { HttpClient, ProgressCallback } from 'isomorphic-git/http/node';
export interface BasicAuth {
username: string
password: string
}
// TODO: Restructure HTTPRequest to reuse Isomorphic Gits GitHttpRequest?
export interface HTTPRequest {
http: HttpClient;
headers?: Record<string, any>;
/** Repository URL. */
url: string;
/** Auth data for basic HTTP auth. */
auth?: BasicAuth
onProgress?: ProgressCallback
}