Skip to content

Commit

Permalink
Allow to download files from interncache
Browse files Browse the repository at this point in the history
Summary: Added a query param to gate inerncache urls from the existing controller to the newer plugin veresions only

Reviewed By: mweststrate

Differential Revision: D64055855

fbshipit-source-id: 2ad02f688b0eeb1bb1f86673167ac6b0a7cb5e7c
  • Loading branch information
antonk52 authored and facebook-github-bot committed Oct 8, 2024
1 parent 17dd95d commit 20a0920
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions desktop/flipper-common/src/server-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export interface DownloadFileStartOptions {
maxRedirects?: number;
headers?: Record<string, string>;
overwrite?: boolean;
proxy?: {host: string; port: number; protocol?: string};
}

export type DownloadFileUpdate = {
Expand Down
25 changes: 22 additions & 3 deletions desktop/flipper-server/src/FlipperServerImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
Settings,
ClientQuery,
RmOptions,
DownloadFileStartOptions,
} from 'flipper-common';
import {ServerDevice} from './devices/ServerDevice';
import {Base64} from 'js-base64';
Expand All @@ -49,6 +50,7 @@ import {sendScribeLogs} from './fb-stubs/sendScribeLogs';
import {
internGraphGETAPIRequest,
internGraphPOSTAPIRequest,
rewriteInternRequest,
} from './fb-stubs/internRequests';
import {commandNodeApiExec} from './commands/NodeApiExec';
import {commandDownloadFileStartFactory} from './commands/DownloadFile';
Expand Down Expand Up @@ -501,9 +503,26 @@ export class FlipperServerImpl implements FlipperServer {
'node-api-fs-writefile-binary': (path, base64contents) =>
writeFile(path, Base64.toUint8Array(base64contents), 'binary'),
// TODO: Do we need API to cancel an active download?
'download-file-start': commandDownloadFileStartFactory(
this.emit.bind(this),
),
'download-file-start': async (
endpoint: string,
dest: string,
options?: DownloadFileStartOptions,
) => {
const downloadFileStart = commandDownloadFileStartFactory(
this.emit.bind(this),
);

const {url, headers, proxy} = await rewriteInternRequest(
endpoint,
options?.headers ?? {},
);

return downloadFileStart(url, dest, {
...options,
proxy: proxy ?? undefined,
headers: headers as Record<string, string>,
});
},
'get-config': async () => this.config,
'get-changelog': getChangelog,
'device-find': async (deviceSerial) => {
Expand Down
3 changes: 2 additions & 1 deletion desktop/flipper-server/src/commands/DownloadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const commandDownloadFileStartFactory =
async (
url,
dest,
{method = 'GET', timeout, maxRedirects, headers, overwrite} = {},
{method = 'GET', timeout, maxRedirects, headers, overwrite, proxy} = {},
) => {
const destExists = await pathExists(dest);

Expand Down Expand Up @@ -70,6 +70,7 @@ export const commandDownloadFileStartFactory =
timeout,
maxRedirects,
headers,
proxy,
});
let totalSize = parseInt(response.headers['content-length'], 10);
if (Number.isNaN(totalSize)) {
Expand Down
12 changes: 12 additions & 0 deletions desktop/flipper-server/src/fb-stubs/internRequests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @format
*/

import type {AxiosProxyConfig} from 'axios';
import {GraphFileUpload, GraphResponse} from 'flipper-common';

/* eslint-disable @typescript-eslint/no-unused-vars */
Expand Down Expand Up @@ -43,3 +44,14 @@ export async function internGraphGETAPIRequest(
): Promise<GraphResponse> {
throw new Error('Feature not implemented');
}

export async function rewriteInternRequest(
url: string,
headers: Record<string, string>,
): Promise<{
url: string;
headers: Record<string, string>;
proxy: AxiosProxyConfig | null;
}> {
return {url, headers, proxy: null};
}

0 comments on commit 20a0920

Please sign in to comment.