@jinshuju/cli 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands.js +20 -2
- package/package.json +1 -1
package/dist/commands.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CONTAINER_LIST_OPTIONS, CONTAINER_OPTIONS, FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, LIMIT_OPTION, LOCAL_OPTIONS, MINE_OPTION, PAGINATION_OPTIONS, SORT_OPTION, TIME_BUCKETS, UsageError, parseDimension, parseFilter, parseMetric, parseSort, resolveContainer, resolveContainers } from './options.js';
|
|
2
2
|
import { CONFIG_KEYS } from './config.js';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { basename } from 'node:path';
|
|
4
|
+
import { basename, extname } from 'node:path';
|
|
5
5
|
import { validateCreateFormPayload } from './payload.js';
|
|
6
6
|
import { progress } from './progress.js';
|
|
7
7
|
/** Resource order in the root help, and the one-liner each gets. */
|
|
@@ -892,6 +892,23 @@ const VIEW = [
|
|
|
892
892
|
}
|
|
893
893
|
];
|
|
894
894
|
// --- uploads ----------------------------------------------------------------
|
|
895
|
+
/**
|
|
896
|
+
* The media type of an upload, by extension. The server stores the type the
|
|
897
|
+
* multipart part declares and decides from it what the file may be used for, so
|
|
898
|
+
* an untyped part is an .xlsx it refuses as not a spreadsheet.
|
|
899
|
+
*/
|
|
900
|
+
const UPLOAD_TYPES = {
|
|
901
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
902
|
+
'.xlsm': 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
|
903
|
+
'.xls': 'application/vnd.ms-excel',
|
|
904
|
+
'.csv': 'text/csv',
|
|
905
|
+
'.png': 'image/png',
|
|
906
|
+
'.jpg': 'image/jpeg',
|
|
907
|
+
'.jpeg': 'image/jpeg',
|
|
908
|
+
'.gif': 'image/gif',
|
|
909
|
+
'.webp': 'image/webp',
|
|
910
|
+
'.pdf': 'application/pdf'
|
|
911
|
+
};
|
|
895
912
|
/**
|
|
896
913
|
* A file on disk, as multipart. The three endpoints that take one authenticate
|
|
897
914
|
* like every other request, so there is no ticket to fetch first: the file goes
|
|
@@ -906,7 +923,8 @@ function upload(path, file, extra = {}) {
|
|
|
906
923
|
catch (error) {
|
|
907
924
|
throw new UsageError(`could not read ${file}: ${error.message}`);
|
|
908
925
|
}
|
|
909
|
-
|
|
926
|
+
const type = UPLOAD_TYPES[extname(file).toLowerCase()];
|
|
927
|
+
form.append('file', new Blob([new Uint8Array(bytes)], type ? { type } : undefined), basename(file));
|
|
910
928
|
for (const [name, value] of Object.entries(extra))
|
|
911
929
|
form.append(name, value);
|
|
912
930
|
return { method: 'POST', path, form };
|