refactor: DownloadBlobRequest -> generic HTTPRequest
This commit is contained in:
parent
14be6d8b78
commit
17b2eb8706
2 changed files with 25 additions and 13 deletions
|
@ -1,22 +1,11 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fsp from 'fs/promises';
|
import fsp from 'fs/promises';
|
||||||
import { HttpClient } from 'isomorphic-git/http/node';
|
|
||||||
|
|
||||||
import { bodyToBuffer, isWriteable } from './util';
|
import { bodyToBuffer, isWriteable } from './util';
|
||||||
import { Pointer } from './pointers';
|
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 {
|
interface LFSInfoResponse {
|
||||||
objects: {
|
objects: {
|
||||||
actions: {
|
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.
|
* Downloads, caches and returns a blob corresponding to given LFS pointer.
|
||||||
*/
|
*/
|
||||||
export default async function downloadBlobFromPointer(
|
export default async function downloadBlobFromPointer(
|
||||||
{ http: { request }, headers = {}, url, auth }: DownloadBlobRequest,
|
{ http: { request }, headers = {}, url, auth }: HTTPRequest,
|
||||||
{ info, objectPath }: Pointer,
|
{ info, objectPath }: Pointer,
|
||||||
): Promise<Buffer> {
|
): Promise<Buffer> {
|
||||||
|
|
||||||
|
|
23
src/types.ts
Normal file
23
src/types.ts
Normal 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 Git’s GitHttpRequest?
|
||||||
|
|
||||||
|
export interface HTTPRequest {
|
||||||
|
http: HttpClient;
|
||||||
|
headers?: Record<string, any>;
|
||||||
|
|
||||||
|
/** Repository URL. */
|
||||||
|
url: string;
|
||||||
|
|
||||||
|
/** Auth data for basic HTTP auth. */
|
||||||
|
auth?: BasicAuth
|
||||||
|
|
||||||
|
onProgress?: ProgressCallback
|
||||||
|
}
|
Loading…
Reference in a new issue