generate temporal file for published story

This commit is contained in:
btzr-io 2020-07-28 23:00:47 -05:00 committed by Sean Yesmunt
parent c47c6f6034
commit 18a6e7c7c1
3 changed files with 36 additions and 20 deletions

View file

@ -53,6 +53,7 @@
"express": "^4.17.1",
"if-env": "^1.0.4",
"remark-breaks": "^1.0.5",
"tempy": "^0.6.0",
"videojs-logo": "^2.0.0"
},
"devDependencies": {

View file

@ -29,9 +29,7 @@ import * as PUBLISH_MODES from 'constants/publish_types';
// @if TARGET='app'
import fs from 'fs';
import { remote } from 'electron';
const { dialog } = remote;
const currentWindow = remote.getCurrentWindow();
import tempy from 'tempy';
// @endif
const MODES = Object.values(PUBLISH_MODES);
@ -209,19 +207,14 @@ function PublishForm(props: Props) {
// @endif
// @if TARGET='app'
// Prompt a file dialog to save a backup file of the story to publish.
function showSaveDialog() {
return dialog.showSaveDialog(currentWindow, {
filters: [{ name: 'Text', extensions: ['md', 'markdown', 'txt'] }],
});
}
// Save file changes locally ( desktop )
async function saveFileChanges() {
function saveFileChanges() {
let output = filePath;
if (!output || output === '') {
output = await showSaveDialog();
// Generate a temporary file:
output = tempy.file({ name: 'story.md' });
}
// User saved the file on a custom location
// Create a temporary file and save file changes
if (typeof output === 'string') {
// Save file changes
return new Promise((resolve, reject) => {
@ -244,6 +237,8 @@ function PublishForm(props: Props) {
// Publish story:
// If here is no file selected yet on desktop, show file dialog and let the
// user choose a file path. On web a new File is created
const validStory = verifyStoryContent();
if (mode === PUBLISH_MODES.STORY) {
let outputFile = filePath;
// If user modified content on the text editor:
@ -258,16 +253,11 @@ function PublishForm(props: Props) {
// @endif
// New content stored locally and is not empty
if (outputFile) {
if (outputFile && validStory) {
updatePublishForm({ filePath: outputFile });
publish(outputFile);
}
}
// Verify if story has a valid content and is not emoty
// On web file size limit will be verified as well
const verified = verifyStoryContent();
if (verified) {
} else if (validStory && outputFile) {
publish(outputFile);
}
}

View file

@ -6105,6 +6105,11 @@ is-stream@^1.0.0, is-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
is-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==
is-string@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6"
@ -10525,6 +10530,11 @@ tar@^2.0.0:
fstream "^1.0.12"
inherits "2"
temp-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-2.0.0.tgz#bde92b05bdfeb1516e804c9c00ad45177f31321e"
integrity sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==
temp-file@^3.3.7:
version "3.3.7"
resolved "https://registry.yarnpkg.com/temp-file/-/temp-file-3.3.7.tgz#686885d635f872748e384e871855958470aeb18a"
@ -10532,6 +10542,16 @@ temp-file@^3.3.7:
async-exit-hook "^2.0.1"
fs-extra "^8.1.0"
tempy@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tempy/-/tempy-0.6.0.tgz#65e2c35abc06f1124a97f387b08303442bde59f3"
integrity sha512-G13vtMYPT/J8A4X2SjdtBTphZlrp1gKv6hZiOjw14RCWg6GbHuQBGtjlx75xLbYV/wEc0D7G5K4rxKP/cXk8Bw==
dependencies:
is-stream "^2.0.0"
temp-dir "^2.0.0"
type-fest "^0.16.0"
unique-string "^2.0.0"
term-size@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/term-size/-/term-size-1.2.0.tgz#458b83887f288fc56d6fffbfad262e26638efa69"
@ -10785,6 +10805,11 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"
type-fest@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.16.0.tgz#3240b891a78b0deae910dbeb86553e552a148860"
integrity sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg==
type-fest@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b"