Set file path and mime in file selector.

This commit is contained in:
Franco Montenegro 2022-08-12 18:16:54 -03:00
parent f6a941969f
commit 3bc2373984
5 changed files with 24 additions and 2 deletions

View file

@ -20,6 +20,7 @@ import path from 'path';
import { diskSpaceLinux, diskSpaceWindows, diskSpaceMac } from '../ui/util/diskspace';
const { download } = require('electron-dl');
const mime = require('mime');
const remote = require('@electron/remote/main');
const os = require('os');
const sudo = require('sudo-prompt');
@ -318,6 +319,7 @@ ipcMain.handle('get-file-from-path', (event, path) => {
const fileName = folders[folders.length - 1];
resolve({
name: fileName,
mime: mime.getType(fileName) || undefined,
path: path,
buffer: data,
});

View file

@ -54,6 +54,7 @@
"humanize-duration": "^3.27.0",
"if-env": "^1.0.4",
"match-sorter": "^6.3.0",
"mime": "^3.0.0",
"node-html-parser": "^5.1.0",
"parse-duration": "^1.0.0",
"proxy-polyfill": "0.1.6",

View file

@ -83,7 +83,16 @@ class FileSelector extends React.PureComponent<Props> {
if (!result) {
return;
}
const file = new File([result.buffer], result.name);
const file = new File([result.buffer], result.name, {
type: result.mime,
});
// "path" is a read only property so we have to use this
// hack to overcome the limitation.
// $FlowFixMe
Object.defineProperty(file, 'path', {
value: result.path,
writable: false,
});
this.props.onFileChosen(file);
});
};

View file

@ -233,7 +233,7 @@ function PublishFile(props: Props) {
isTextPost = contentType[1] === 'plain' || contentType[1] === 'markdown';
setCurrentFileType(contentType);
} else if (file.name) {
// If user's machine is missign a valid content type registration
// If user's machine is missing a valid content type registration
// for markdown content: text/markdown, file extension will be used instead
const extension = file.name.split('.').pop();
isTextPost = MARKDOWN_FILE_EXTENSIONS.includes(extension);

View file

@ -11549,6 +11549,7 @@ __metadata:
lodash-es: ^4.17.21
mammoth: ^1.4.16
match-sorter: ^6.3.0
mime: ^3.0.0
moment: ^2.29.2
node-abi: ^2.5.1
node-fetch: ^2.6.7
@ -12576,6 +12577,15 @@ __metadata:
languageName: node
linkType: hard
"mime@npm:^3.0.0":
version: 3.0.0
resolution: "mime@npm:3.0.0"
bin:
mime: cli.js
checksum: f43f9b7bfa64534e6b05bd6062961681aeb406a5b53673b53b683f27fcc4e739989941836a355eef831f4478923651ecc739f4a5f6e20a76487b432bfd4db928
languageName: node
linkType: hard
"mimic-fn@npm:^1.0.0":
version: 1.2.0
resolution: "mimic-fn@npm:1.2.0"