|
@@ -1,17 +1,15 @@
|
|
/**
|
|
/**
|
|
- * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
|
|
|
+ * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
*
|
|
*
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
|
+ * @author Russell Parker <russell@benchling.com>
|
|
*/
|
|
*/
|
|
|
|
|
|
-/** A File or Blob object or a URL string */
|
|
|
|
-export type FileInput = File | Blob | string
|
|
|
|
-
|
|
|
|
// TODO only support compressed files for which uncompression support is available???
|
|
// TODO only support compressed files for which uncompression support is available???
|
|
// TODO store globally with decompression plugins?
|
|
// TODO store globally with decompression plugins?
|
|
-const compressedExtList = ['gz', 'zip'];
|
|
|
|
|
|
+const COMPRESSED_EXT_LIST = ['gz', 'zip'];
|
|
|
|
|
|
-export interface FileInfo {
|
|
|
|
|
|
+export interface FileNameInfo {
|
|
path: string
|
|
path: string
|
|
name: string
|
|
name: string
|
|
ext: string
|
|
ext: string
|
|
@@ -19,20 +17,12 @@ export interface FileInfo {
|
|
dir: string
|
|
dir: string
|
|
protocol: string
|
|
protocol: string
|
|
query: string
|
|
query: string
|
|
- src: FileInput
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-export function getFileInfo(file: FileInput): FileInfo {
|
|
|
|
- let path: string;
|
|
|
|
|
|
+export function getFileNameInfo(fileName: string): FileNameInfo {
|
|
|
|
+ let path: string = fileName;
|
|
let protocol = '';
|
|
let protocol = '';
|
|
|
|
|
|
- if (file instanceof File) {
|
|
|
|
- path = file.name;
|
|
|
|
- } else if (file instanceof Blob) {
|
|
|
|
- path = '';
|
|
|
|
- } else {
|
|
|
|
- path = file;
|
|
|
|
- }
|
|
|
|
const queryIndex = path.lastIndexOf('?');
|
|
const queryIndex = path.lastIndexOf('?');
|
|
const query = queryIndex !== -1 ? path.substring(queryIndex) : '';
|
|
const query = queryIndex !== -1 ? path.substring(queryIndex) : '';
|
|
path = path.substring(0, queryIndex === -1 ? path.length : queryIndex);
|
|
path = path.substring(0, queryIndex === -1 ? path.length : queryIndex);
|
|
@@ -51,12 +41,14 @@ export function getFileInfo(file: FileInput): FileInfo {
|
|
|
|
|
|
const dir = path.substring(0, path.lastIndexOf('/') + 1);
|
|
const dir = path.substring(0, path.lastIndexOf('/') + 1);
|
|
|
|
|
|
- if (compressedExtList.includes(ext)) {
|
|
|
|
|
|
+ if (COMPRESSED_EXT_LIST.includes(ext)) {
|
|
const n = path.length - ext.length - 1;
|
|
const n = path.length - ext.length - 1;
|
|
|
|
+ // TODO: change logic to String.prototype.substring since substr is deprecated
|
|
ext = (path.substr(0, n).split('.').pop() || '').toLowerCase();
|
|
ext = (path.substr(0, n).split('.').pop() || '').toLowerCase();
|
|
const m = base.length - ext.length - 1;
|
|
const m = base.length - ext.length - 1;
|
|
base = base.substr(0, m);
|
|
base = base.substr(0, m);
|
|
}
|
|
}
|
|
|
|
|
|
- return { path, name, ext, base, dir, protocol, query, src: file };
|
|
|
|
|
|
+ // Note: it appears that most of this data never gets used.
|
|
|
|
+ return { path, name, ext, base, dir, protocol, query };
|
|
}
|
|
}
|