Add download file API
Summary: Changelog: Expose "downloadFile" API to Flipper plugins. Allow them to download files form the web to Flipper Server. Reviewed By: mweststrate Differential Revision: D32950685 fbshipit-source-id: 7b7f666e165ff7bf209230cdc96078272ede3616
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4cb80a452f
commit
92f0ed67f4
@@ -91,6 +91,7 @@ test('Correct top level API exposed', () => {
|
||||
"DevicePluginClient",
|
||||
"DeviceType",
|
||||
"DialogResult",
|
||||
"DownloadFileResponse",
|
||||
"Draft",
|
||||
"ElementAttribute",
|
||||
"ElementData",
|
||||
|
||||
@@ -40,6 +40,7 @@ export {
|
||||
FileDescriptor,
|
||||
FileEncoding,
|
||||
RemoteServerContext,
|
||||
DownloadFileResponse,
|
||||
} from './plugin/FlipperLib';
|
||||
export {
|
||||
MenuEntry,
|
||||
|
||||
@@ -18,6 +18,9 @@ import {
|
||||
ExecOut,
|
||||
BufferEncoding,
|
||||
MkdirOptions,
|
||||
DownloadFileStartOptions,
|
||||
DownloadFileStartResponse,
|
||||
DownloadFileUpdate,
|
||||
} from 'flipper-common';
|
||||
|
||||
export type FileEncoding = 'utf-8' | 'base64';
|
||||
@@ -28,6 +31,13 @@ export interface FileDescriptor {
|
||||
path?: string;
|
||||
}
|
||||
|
||||
export interface DownloadFileResponse extends DownloadFileStartResponse {
|
||||
/**
|
||||
* Indicates whether a download is completed. Resolves with the number of downloaded bytes. Rejects if the download has errors.
|
||||
*/
|
||||
completed: Promise<number>;
|
||||
}
|
||||
|
||||
export type RemoteServerContext = {
|
||||
childProcess: {
|
||||
exec(
|
||||
@@ -49,6 +59,13 @@ export type RemoteServerContext = {
|
||||
): Promise<void>;
|
||||
copyFile(src: string, dest: string, flags?: number): Promise<void>;
|
||||
};
|
||||
downloadFile(
|
||||
url: string,
|
||||
dest: string,
|
||||
options?: DownloadFileStartOptions & {
|
||||
onProgressUpdate?: (progressUpdate: DownloadFileUpdate) => void;
|
||||
},
|
||||
): Promise<DownloadFileResponse>;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -400,6 +400,7 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
|
||||
mkdir: jest.fn(),
|
||||
copyFile: jest.fn(),
|
||||
},
|
||||
downloadFile: jest.fn(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
getFlipperLib,
|
||||
} from '../plugin/FlipperLib';
|
||||
import {fromUint8Array} from 'js-base64';
|
||||
import {assertNever} from '../utils/assertNever';
|
||||
import {assertNever} from 'flipper-common';
|
||||
|
||||
export type FileSelectorProps = {
|
||||
/**
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
export const assertNever: (val: never) => asserts val = (val) => {
|
||||
if (val) {
|
||||
throw new Error(`Assert never failed. Received ${val}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user