Skip to content

Commit 9dbba52

Browse files
moved remote data url checks to fileUtils.ts
1 parent d5b5ef0 commit 9dbba52

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/data.preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class DataPreview {
144144
this._extensionPath = extensionPath;
145145
this._uri = uri;
146146
this._dataUrl = uri.toString(true); // skip uri encoding
147-
this._isRemoteData = (this._dataUrl.startsWith('http://') || this._dataUrl.startsWith('https://'));
147+
this._isRemoteData = fileUtils.isRemoteDataUrl(this._dataUrl);
148148
this._dataTable = (table !== undefined) ? table: '';
149149
this._dataViews = (views !== undefined) ? views: {};
150150
this._viewConfig = viewConfig;

src/utils/file.utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function readDataFile(dataFilePath: string, encoding:string = null)
2323
if (!config.supportedDataFiles.test(fileName)) {
2424
window.showErrorMessage(`${dataFilePath} is not a supported data file for Data Preview!`);
2525
}
26-
else if (dataFilePath.startsWith('http://') || dataFilePath.startsWith('https://')) {
26+
else if (isRemoteDataUrl(dataFilePath)) {
2727
data = await readRemoteData(dataFilePath, encoding);
2828
}
2929
else if (fs.existsSync(fileUri.fsPath)) {
@@ -44,6 +44,15 @@ export async function readDataFile(dataFilePath: string, encoding:string = null)
4444
return data;
4545
}
4646

47+
/**
48+
* Checks if the requested data url is a remote data source; http(s) only for now.
49+
* @param dataUrl The data url to check.
50+
* @returns True if the specified data url is a remote data source. false otherwise.
51+
*/
52+
export function isRemoteDataUrl(dataUrl: string): boolean {
53+
return dataUrl.startsWith('http://') || dataUrl.startsWith('https://');
54+
}
55+
4756
/**
4857
* Gets local data file size for status display.
4958
* @param dataFilePath Data file path to get size stats for.

0 commit comments

Comments
 (0)