mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Export images together with document
This commit is contained in:
@@ -7,7 +7,7 @@ const os = require('os')
|
||||
let mobileAnalyticsClient
|
||||
|
||||
AWS.config.region = 'us-east-1'
|
||||
if (process.env.NODE_ENV === 'production' && ConfigManager.default.get().amaEnabled) {
|
||||
if (!getSendEventCond()) {
|
||||
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
|
||||
IdentityPoolId: 'us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxx'
|
||||
})
|
||||
@@ -34,8 +34,15 @@ function convertPlatformName (platformName) {
|
||||
}
|
||||
}
|
||||
|
||||
function getSendEventCond () {
|
||||
const isDev = process.env.NODE_ENV !== 'production'
|
||||
const isDisable = !ConfigManager.default.get().amaEnabled
|
||||
const isOffline = !window.navigator.onLine
|
||||
return isDev || isDisable || isOffline
|
||||
}
|
||||
|
||||
function initAwsMobileAnalytics () {
|
||||
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
|
||||
if (getSendEventCond()) return
|
||||
AWS.config.credentials.get((err) => {
|
||||
if (!err) {
|
||||
console.log('Cognito Identity ID: ' + AWS.config.credentials.identityId)
|
||||
@@ -46,7 +53,7 @@ function initAwsMobileAnalytics () {
|
||||
}
|
||||
|
||||
function recordDynamicCustomEvent (type, options = {}) {
|
||||
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
|
||||
if (getSendEventCond()) return
|
||||
try {
|
||||
mobileAnalyticsClient.recordEvent(type, options)
|
||||
} catch (analyticsError) {
|
||||
@@ -57,7 +64,7 @@ function recordDynamicCustomEvent (type, options = {}) {
|
||||
}
|
||||
|
||||
function recordStaticCustomEvent () {
|
||||
if (process.env.NODE_ENV !== 'production' || !ConfigManager.default.get().amaEnabled) return
|
||||
if (getSendEventCond()) return
|
||||
try {
|
||||
mobileAnalyticsClient.recordEvent('UI_COLOR_THEME', {
|
||||
uiColorTheme: ConfigManager.default.get().ui.theme
|
||||
|
||||
@@ -35,7 +35,8 @@ export const DEFAULT_CONFIG = {
|
||||
indentType: 'space',
|
||||
indentSize: '2',
|
||||
switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR
|
||||
scrollPastEnd: false
|
||||
scrollPastEnd: false,
|
||||
type: 'SPLIT'
|
||||
},
|
||||
preview: {
|
||||
fontSize: '14',
|
||||
|
||||
@@ -2,14 +2,14 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
/**
|
||||
* @description Export an image
|
||||
* @description Export a file
|
||||
* @param {String} storagePath
|
||||
* @param {String} srcFilename
|
||||
* @param {String} dstPath
|
||||
* @param {String} dstFilename if not present, destination filename will be equal to srcFilename
|
||||
* @return {Promise} an image path
|
||||
*/
|
||||
function exportImage (storagePath, srcFilename, dstPath, dstFilename = '') {
|
||||
function exportFile (storagePath, srcFilename, dstPath, dstFilename = '') {
|
||||
dstFilename = dstFilename || srcFilename
|
||||
|
||||
const src = path.join(storagePath, 'images', srcFilename)
|
||||
@@ -18,20 +18,19 @@ function exportImage (storagePath, srcFilename, dstPath, dstFilename = '') {
|
||||
dstFilename += path.extname(srcFilename)
|
||||
}
|
||||
|
||||
const dstImagesFolder = path.join(dstPath, 'images')
|
||||
const dst = path.join(dstImagesFolder, dstFilename)
|
||||
const dst = path.join(dstPath, dstFilename)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!fs.existsSync(dstImagesFolder)) fs.mkdirSync(dstImagesFolder)
|
||||
if (!fs.existsSync(dstPath)) fs.mkdirSync(dstPath)
|
||||
|
||||
const input = fs.createReadStream(src)
|
||||
const output = fs.createWriteStream(dst)
|
||||
|
||||
output.on('error', reject)
|
||||
input.on('error', reject)
|
||||
input.on('end', resolve)
|
||||
input.on('end', resolve, dst)
|
||||
input.pipe(output)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = exportImage
|
||||
module.exports = exportFile
|
||||
63
browser/main/lib/dataApi/exportFolder.js
Normal file
63
browser/main/lib/dataApi/exportFolder.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import { findStorage } from 'browser/lib/findStorage'
|
||||
import resolveStorageData from './resolveStorageData'
|
||||
import resolveStorageNotes from './resolveStorageNotes'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
/**
|
||||
* @param {String} storageKey
|
||||
* @param {String} folderKey
|
||||
* @param {String} fileType
|
||||
* @param {String} exportDir
|
||||
*
|
||||
* @return {Object}
|
||||
* ```
|
||||
* {
|
||||
* storage: Object,
|
||||
* folderKey: String,
|
||||
* fileType: String,
|
||||
* exportDir: String
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
|
||||
function exportFolder (storageKey, folderKey, fileType, exportDir) {
|
||||
let targetStorage
|
||||
try {
|
||||
targetStorage = findStorage(storageKey)
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
|
||||
return resolveStorageData(targetStorage)
|
||||
.then(function assignNotes (storage) {
|
||||
return resolveStorageNotes(storage)
|
||||
.then((notes) => {
|
||||
return {
|
||||
storage,
|
||||
notes
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(function exportNotes (data) {
|
||||
const { storage, notes } = data
|
||||
|
||||
notes
|
||||
.filter(note => note.folder === folderKey && note.isTrashed === false && note.type === 'MARKDOWN_NOTE')
|
||||
.forEach(snippet => {
|
||||
const notePath = path.join(exportDir, `${snippet.title}.${fileType}`)
|
||||
fs.writeFileSync(notePath, snippet.content, (err) => {
|
||||
if (err) throw err
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
storage,
|
||||
folderKey,
|
||||
fileType,
|
||||
exportDir
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = exportFolder
|
||||
@@ -7,6 +7,7 @@ const dataApi = {
|
||||
updateFolder: require('./updateFolder'),
|
||||
deleteFolder: require('./deleteFolder'),
|
||||
reorderFolder: require('./reorderFolder'),
|
||||
exportFolder: require('./exportFolder'),
|
||||
createNote: require('./createNote'),
|
||||
updateNote: require('./updateNote'),
|
||||
deleteNote: require('./deleteNote'),
|
||||
|
||||
Reference in New Issue
Block a user