mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-16 11:15:12 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78c00b1722 | ||
|
|
2ff655d2dc | ||
|
|
e53717cd87 | ||
|
|
8b8d915ab7 | ||
|
|
54de57ee7b | ||
|
|
e0d9cf7f5c | ||
|
|
10ea5d00eb | ||
|
|
de76f55fe2 | ||
|
|
cd301d514c | ||
|
|
0f232b3d86 | ||
|
|
53ff693e95 | ||
|
|
215484c19a | ||
|
|
885f656d34 | ||
|
|
851d3ba159 | ||
|
|
62ab444b29 | ||
|
|
f1b929c13b | ||
|
|
806139091c | ||
|
|
6960c8b2d6 | ||
|
|
b1c6c0442f | ||
|
|
a85a27f225 | ||
|
|
950d31ada8 | ||
|
|
543c31cec6 | ||
|
|
5e87ec2627 | ||
|
|
7165c4550b | ||
|
|
472496d59c | ||
|
|
127da40256 | ||
|
|
a113b99de0 | ||
|
|
1683d63f33 | ||
|
|
4cce52f9ce | ||
|
|
33fb03066e | ||
|
|
294bf742cd | ||
|
|
ea5970ab1c | ||
|
|
72df418953 | ||
|
|
f566b567be | ||
|
|
900f20f164 | ||
|
|
c2e4bae9dd | ||
|
|
2908884202 |
@@ -888,10 +888,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
handlePaste (editor, forceSmartPaste) {
|
handlePaste (editor, forceSmartPaste) {
|
||||||
const { storageKey, noteKey, fetchUrlTitle, enableSmartPaste } = this.props
|
const { storageKey, noteKey, fetchUrlTitle, enableSmartPaste } = this.props
|
||||||
|
|
||||||
const isURL = str => {
|
const isURL = str => /(?:^\w+:|^)\/\/(?:[^\s\.]+\.\S{2}|localhost[\:?\d]*)/.test(str)
|
||||||
const matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/
|
|
||||||
return matcher.test(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
const isInLinkTag = editor => {
|
const isInLinkTag = editor => {
|
||||||
const startCursor = editor.getCursor('start')
|
const startCursor = editor.getCursor('start')
|
||||||
@@ -964,7 +961,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
} else {
|
} else {
|
||||||
const image = clipboard.readImage()
|
const image = clipboard.readImage()
|
||||||
if (!image.isEmpty()) {
|
if (!image.isEmpty()) {
|
||||||
attachmentManagement.handlePastNativeImage(
|
attachmentManagement.handlePasteNativeImage(
|
||||||
this,
|
this,
|
||||||
storageKey,
|
storageKey,
|
||||||
noteKey,
|
noteKey,
|
||||||
@@ -1109,7 +1106,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
iconv.encodingExists(_charset)
|
iconv.encodingExists(_charset)
|
||||||
? _charset
|
? _charset
|
||||||
: 'utf-8'
|
: 'utf-8'
|
||||||
resolve(iconv.decode(new Buffer(buff), charset).toString())
|
resolve(iconv.decode(Buffer.from(buff), charset).toString())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e)
|
reject(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -832,6 +832,81 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const markdownPreviewIframe = document.querySelector('.MarkdownPreview')
|
||||||
|
const rect = markdownPreviewIframe.getBoundingClientRect()
|
||||||
|
const imgList = markdownPreviewIframe.contentWindow.document.body.querySelectorAll('img')
|
||||||
|
for (const img of imgList) {
|
||||||
|
img.onclick = () => {
|
||||||
|
const widthMagnification = document.body.clientWidth / img.width
|
||||||
|
const heightMagnification = document.body.clientHeight / img.height
|
||||||
|
const baseOnWidth = widthMagnification < heightMagnification
|
||||||
|
const magnification = baseOnWidth ? widthMagnification : heightMagnification
|
||||||
|
|
||||||
|
const zoomImgWidth = img.width * magnification
|
||||||
|
const zoomImgHeight = img.height * magnification
|
||||||
|
const zoomImgTop = (document.body.clientHeight - zoomImgHeight) / 2
|
||||||
|
const zoomImgLeft = (document.body.clientWidth - zoomImgWidth) / 2
|
||||||
|
const originalImgTop = img.y + rect.top
|
||||||
|
const originalImgLeft = img.x + rect.left
|
||||||
|
const originalImgRect = {
|
||||||
|
top: `${originalImgTop}px`,
|
||||||
|
left: `${originalImgLeft}px`,
|
||||||
|
width: `${img.width}px`,
|
||||||
|
height: `${img.height}px`
|
||||||
|
}
|
||||||
|
const zoomInImgRect = {
|
||||||
|
top: `${baseOnWidth ? zoomImgTop : 0}px`,
|
||||||
|
left: `${baseOnWidth ? 0 : zoomImgLeft}px`,
|
||||||
|
width: `${zoomImgWidth}px`,
|
||||||
|
height: `${zoomImgHeight}px`
|
||||||
|
}
|
||||||
|
const animationSpeed = 300
|
||||||
|
|
||||||
|
const zoomImg = document.createElement('img')
|
||||||
|
zoomImg.src = img.src
|
||||||
|
zoomImg.style = `
|
||||||
|
position: absolute;
|
||||||
|
top: ${baseOnWidth ? zoomImgTop : 0}px;
|
||||||
|
left: ${baseOnWidth ? 0 : zoomImgLeft}px;
|
||||||
|
width: ${zoomImgWidth};
|
||||||
|
height: ${zoomImgHeight}px;
|
||||||
|
`
|
||||||
|
zoomImg.animate([
|
||||||
|
originalImgRect,
|
||||||
|
zoomInImgRect
|
||||||
|
], animationSpeed)
|
||||||
|
|
||||||
|
const overlay = document.createElement('div')
|
||||||
|
overlay.style = `
|
||||||
|
background-color: rgba(0,0,0,0.5);
|
||||||
|
cursor: zoom-out;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: ${document.body.clientHeight}px;
|
||||||
|
z-index: 100;
|
||||||
|
`
|
||||||
|
overlay.onclick = () => {
|
||||||
|
zoomImg.style = `
|
||||||
|
position: absolute;
|
||||||
|
top: ${originalImgTop}px;
|
||||||
|
left: ${originalImgLeft}px;
|
||||||
|
width: ${img.width}px;
|
||||||
|
height: ${img.height}px;
|
||||||
|
`
|
||||||
|
const zoomOutImgAnimation = zoomImg.animate([
|
||||||
|
zoomInImgRect,
|
||||||
|
originalImgRect
|
||||||
|
], animationSpeed)
|
||||||
|
zoomOutImgAnimation.onfinish = () => overlay.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
overlay.appendChild(zoomImg)
|
||||||
|
document.body.appendChild(overlay)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
focus () {
|
focus () {
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ p
|
|||||||
white-space pre-line
|
white-space pre-line
|
||||||
word-wrap break-word
|
word-wrap break-word
|
||||||
img
|
img
|
||||||
|
cursor zoom-in
|
||||||
max-width 100%
|
max-width 100%
|
||||||
strong, b
|
strong, b
|
||||||
font-weight bold
|
font-weight bold
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function strip (input) {
|
|||||||
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
|
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
|
||||||
.replace(/>/g, '')
|
.replace(/>/g, '')
|
||||||
.replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '')
|
.replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '')
|
||||||
.replace(/^#{1,6}\s*([^#]*)\s*(#{1,6})?/gm, '$1')
|
.replace(/^#{1,6}\s*/gm, '')
|
||||||
.replace(/(`{3,})(.*?)\1/gm, '$2')
|
.replace(/(`{3,})(.*?)\1/gm, '$2')
|
||||||
.replace(/^-{3,}\s*$/g, '')
|
.replace(/^-{3,}\s*$/g, '')
|
||||||
.replace(/`(.+?)`/g, '$1')
|
.replace(/`(.+?)`/g, '$1')
|
||||||
|
|||||||
@@ -100,7 +100,12 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
handleUpdateContent () {
|
handleUpdateContent () {
|
||||||
const { note } = this.state
|
const { note } = this.state
|
||||||
note.content = this.refs.content.value
|
note.content = this.refs.content.value
|
||||||
note.title = markdown.strip(striptags(findNoteTitle(note.content, this.props.config.editor.enableFrontMatterTitle, this.props.config.editor.frontMatterTitleField)))
|
|
||||||
|
let title = findNoteTitle(note.content, this.props.config.editor.enableFrontMatterTitle, this.props.config.editor.frontMatterTitleField)
|
||||||
|
title = striptags(title)
|
||||||
|
title = markdown.strip(title)
|
||||||
|
note.title = title
|
||||||
|
|
||||||
this.updateNote(note)
|
this.updateNote(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export const DEFAULT_CONFIG = {
|
|||||||
theme: 'base16-light',
|
theme: 'base16-light',
|
||||||
keyMap: 'sublime',
|
keyMap: 'sublime',
|
||||||
fontSize: '14',
|
fontSize: '14',
|
||||||
fontFamily: win ? 'Segoe UI' : 'Monaco, Consolas',
|
fontFamily: win ? 'Consolas' : 'Monaco',
|
||||||
indentType: 'space',
|
indentType: 'space',
|
||||||
indentSize: '2',
|
indentSize: '2',
|
||||||
enableRulers: false,
|
enableRulers: false,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const mdurl = require('mdurl')
|
|||||||
const fse = require('fs-extra')
|
const fse = require('fs-extra')
|
||||||
const escapeStringRegexp = require('escape-string-regexp')
|
const escapeStringRegexp = require('escape-string-regexp')
|
||||||
const sander = require('sander')
|
const sander = require('sander')
|
||||||
|
const url = require('url')
|
||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
|
|
||||||
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
|
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
|
||||||
@@ -18,15 +19,23 @@ const PATH_SEPARATORS = escapeStringRegexp(path.posix.sep) + escapeStringRegexp(
|
|||||||
* @returns {Promise<Image>} Image element created
|
* @returns {Promise<Image>} Image element created
|
||||||
*/
|
*/
|
||||||
function getImage (file) {
|
function getImage (file) {
|
||||||
return new Promise((resolve) => {
|
if (_.isString(file)) {
|
||||||
const reader = new FileReader()
|
return new Promise(resolve => {
|
||||||
const img = new Image()
|
const img = new Image()
|
||||||
img.onload = () => resolve(img)
|
img.onload = () => resolve(img)
|
||||||
reader.onload = e => {
|
img.src = file
|
||||||
img.src = e.target.result
|
})
|
||||||
}
|
} else {
|
||||||
reader.readAsDataURL(file)
|
return new Promise(resolve => {
|
||||||
})
|
const reader = new FileReader()
|
||||||
|
const img = new Image()
|
||||||
|
img.onload = () => resolve(img)
|
||||||
|
reader.onload = e => {
|
||||||
|
img.src = e.target.result
|
||||||
|
}
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,23 +160,28 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const isBase64 = typeof sourceFilePath === 'object' && sourceFilePath.type === 'base64'
|
const isBase64 = typeof sourceFilePath === 'object' && sourceFilePath.type === 'base64'
|
||||||
if (!fs.existsSync(sourceFilePath) && !isBase64) {
|
if (!isBase64 && !fs.existsSync(sourceFilePath)) {
|
||||||
return reject('source file does not exist')
|
return reject('source file does not exist')
|
||||||
}
|
}
|
||||||
const targetStorage = findStorage.findStorage(storageKey)
|
|
||||||
|
const sourcePath = sourceFilePath.sourceFilePath || sourceFilePath
|
||||||
|
const sourceURL = url.parse(/^\w+:\/\//.test(sourcePath) ? sourcePath : 'file:///' + sourcePath)
|
||||||
|
|
||||||
let destinationName
|
let destinationName
|
||||||
if (useRandomName) {
|
if (useRandomName) {
|
||||||
destinationName = `${uniqueSlug()}${path.extname(sourceFilePath.sourceFilePath || sourceFilePath)}`
|
destinationName = `${uniqueSlug()}${path.extname(sourceURL.pathname) || '.png'}`
|
||||||
} else {
|
} else {
|
||||||
destinationName = path.basename(sourceFilePath.sourceFilePath || sourceFilePath)
|
destinationName = path.basename(sourceURL.pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const targetStorage = findStorage.findStorage(storageKey)
|
||||||
const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
||||||
createAttachmentDestinationFolder(targetStorage.path, noteKey)
|
createAttachmentDestinationFolder(targetStorage.path, noteKey)
|
||||||
const outputFile = fs.createWriteStream(path.join(destinationDir, destinationName))
|
const outputFile = fs.createWriteStream(path.join(destinationDir, destinationName))
|
||||||
|
|
||||||
if (isBase64) {
|
if (isBase64) {
|
||||||
const base64Data = sourceFilePath.data.replace(/^data:image\/\w+;base64,/, '')
|
const base64Data = sourceFilePath.data.replace(/^data:image\/\w+;base64,/, '')
|
||||||
const dataBuffer = new Buffer(base64Data, 'base64')
|
const dataBuffer = Buffer.from(base64Data, 'base64')
|
||||||
outputFile.write(dataBuffer, () => {
|
outputFile.write(dataBuffer, () => {
|
||||||
resolve(destinationName)
|
resolve(destinationName)
|
||||||
})
|
})
|
||||||
@@ -231,11 +245,11 @@ function fixLocalURLS (renderedHTML, storagePath) {
|
|||||||
A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
|
A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
|
||||||
|
|
||||||
- `STORAGE_FOLDER_PLACEHOLDER` will match `:storage`
|
- `STORAGE_FOLDER_PLACEHOLDER` will match `:storage`
|
||||||
- `(?:(?:\\\/|%5C)[\\w.]+)+` will match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`
|
- `(?:(?:\\\/|%5C)[-.\\w]+)+` will match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`
|
||||||
- `(?:\\\/|%5C)[\\w.]+` will either match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564` or `/f939b2c3.jpg`
|
- `(?:\\\/|%5C)[-.\\w]+` will either match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564` or `/f939b2c3.jpg`
|
||||||
- `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
|
- `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
|
||||||
*/
|
*/
|
||||||
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[\\w.]+)+', 'g'), function (match) {
|
return renderedHTML.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[-.\\w]+)+', 'g'), function (match) {
|
||||||
var encodedPathSeparators = new RegExp(mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep), 'g')
|
var encodedPathSeparators = new RegExp(mdurl.encode(path.win32.sep) + '|' + mdurl.encode(path.posix.sep), 'g')
|
||||||
return match.replace(encodedPathSeparators, path.sep).replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g'), 'file:///' + path.join(storagePath, DESTINATION_FOLDER))
|
return match.replace(encodedPathSeparators, path.sep).replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER, 'g'), 'file:///' + path.join(storagePath, DESTINATION_FOLDER))
|
||||||
})
|
})
|
||||||
@@ -261,22 +275,69 @@ function generateAttachmentMarkdown (fileName, path, showPreview) {
|
|||||||
* @param {Event} dropEvent DropEvent
|
* @param {Event} dropEvent DropEvent
|
||||||
*/
|
*/
|
||||||
function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
||||||
const file = dropEvent.dataTransfer.files[0]
|
|
||||||
const filePath = file.path
|
|
||||||
const originalFileName = path.basename(filePath)
|
|
||||||
const fileType = file['type']
|
|
||||||
const isImage = fileType.startsWith('image')
|
|
||||||
let promise
|
let promise
|
||||||
if (isImage) {
|
if (dropEvent.dataTransfer.files.length > 0) {
|
||||||
promise = fixRotate(file).then(base64data => {
|
promise = Promise.all(Array.from(dropEvent.dataTransfer.files).map(file => {
|
||||||
return copyAttachment({type: 'base64', data: base64data, sourceFilePath: filePath}, storageKey, noteKey)
|
if (file.type.startsWith('image')) {
|
||||||
})
|
if (file.type === 'image/gif' || file.type === 'image/svg+xml') {
|
||||||
|
return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({
|
||||||
|
fileName,
|
||||||
|
title: path.basename(file.path),
|
||||||
|
isImage: true
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
return fixRotate(file)
|
||||||
|
.then(data => copyAttachment({type: 'base64', data: data, sourceFilePath: file.path}, storageKey, noteKey)
|
||||||
|
.then(fileName => ({
|
||||||
|
fileName,
|
||||||
|
title: path.basename(file.path),
|
||||||
|
isImage: true
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({
|
||||||
|
fileName,
|
||||||
|
title: path.basename(file.path),
|
||||||
|
isImage: false
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
promise = copyAttachment(filePath, storageKey, noteKey)
|
let imageURL = dropEvent.dataTransfer.getData('text/plain')
|
||||||
|
|
||||||
|
if (!imageURL) {
|
||||||
|
const match = /<img[^>]*[\s"']src="([^"]+)"/.exec(dropEvent.dataTransfer.getData('text/html'))
|
||||||
|
if (match) {
|
||||||
|
imageURL = match[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!imageURL) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
promise = Promise.all([getImage(imageURL)
|
||||||
|
.then(image => {
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
const context = canvas.getContext('2d')
|
||||||
|
canvas.width = image.width
|
||||||
|
canvas.height = image.height
|
||||||
|
context.drawImage(image, 0, 0)
|
||||||
|
|
||||||
|
return copyAttachment({type: 'base64', data: canvas.toDataURL(), sourceFilePath: imageURL}, storageKey, noteKey)
|
||||||
|
})
|
||||||
|
.then(fileName => ({
|
||||||
|
fileName,
|
||||||
|
title: imageURL,
|
||||||
|
isImage: true
|
||||||
|
}))])
|
||||||
}
|
}
|
||||||
promise.then((fileName) => {
|
|
||||||
const imageMd = generateAttachmentMarkdown(originalFileName, path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName), isImage)
|
promise.then(files => {
|
||||||
codeEditor.insertAttachmentMd(imageMd)
|
const attachments = files.filter(file => !!file).map(file => generateAttachmentMarkdown(file.title, path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, file.fileName), file.isImage))
|
||||||
|
|
||||||
|
codeEditor.insertAttachmentMd(attachments.join('\n'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +348,7 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
|||||||
* @param {String} noteKey Key of the current note
|
* @param {String} noteKey Key of the current note
|
||||||
* @param {DataTransferItem} dataTransferItem Part of the past-event
|
* @param {DataTransferItem} dataTransferItem Part of the past-event
|
||||||
*/
|
*/
|
||||||
function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem) {
|
function handlePasteImageEvent (codeEditor, storageKey, noteKey, dataTransferItem) {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
throw new Error('codeEditor has to be given')
|
throw new Error('codeEditor has to be given')
|
||||||
}
|
}
|
||||||
@@ -331,7 +392,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem
|
|||||||
* @param {String} noteKey Key of the current note
|
* @param {String} noteKey Key of the current note
|
||||||
* @param {NativeImage} image The native image
|
* @param {NativeImage} image The native image
|
||||||
*/
|
*/
|
||||||
function handlePastNativeImage (codeEditor, storageKey, noteKey, image) {
|
function handlePasteNativeImage (codeEditor, storageKey, noteKey, image) {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
throw new Error('codeEditor has to be given')
|
throw new Error('codeEditor has to be given')
|
||||||
}
|
}
|
||||||
@@ -429,7 +490,14 @@ function replaceNoteKeyWithNewNoteKey (noteContent, oldNoteKey, newNoteKey) {
|
|||||||
* @returns {String} Input without the references
|
* @returns {String} Input without the references
|
||||||
*/
|
*/
|
||||||
function removeStorageAndNoteReferences (input, noteKey) {
|
function removeStorageAndNoteReferences (input, noteKey) {
|
||||||
return input.replace(new RegExp(mdurl.encode(path.sep), 'g'), path.sep).replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + escapeStringRegexp(path.sep) + noteKey + ')?', 'g'), DESTINATION_FOLDER)
|
return input.replace(new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|])', 'g'), function (match) {
|
||||||
|
const temp = match
|
||||||
|
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.sep)
|
||||||
|
.replace(new RegExp(mdurl.encode(path.posix.sep), 'g'), path.sep)
|
||||||
|
.replace(new RegExp(escapeStringRegexp(path.win32.sep), 'g'), path.sep)
|
||||||
|
.replace(new RegExp(escapeStringRegexp(path.posix.sep), 'g'), path.sep)
|
||||||
|
return temp.replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + '(' + escapeStringRegexp(path.sep) + noteKey + ')?', 'g'), DESTINATION_FOLDER)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -584,8 +652,8 @@ module.exports = {
|
|||||||
fixLocalURLS,
|
fixLocalURLS,
|
||||||
generateAttachmentMarkdown,
|
generateAttachmentMarkdown,
|
||||||
handleAttachmentDrop,
|
handleAttachmentDrop,
|
||||||
handlePastImageEvent,
|
handlePasteImageEvent,
|
||||||
handlePastNativeImage,
|
handlePasteNativeImage,
|
||||||
getAttachmentsInMarkdownContent,
|
getAttachmentsInMarkdownContent,
|
||||||
getAbsolutePathsOfAttachmentsInContent,
|
getAbsolutePathsOfAttachmentsInContent,
|
||||||
removeStorageAndNoteReferences,
|
removeStorageAndNoteReferences,
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Crowdfunding extends React.Component {
|
|||||||
<p>{i18n.__('We thought that it will be nice if we can pay reward for our contributors.')}</p>
|
<p>{i18n.__('We thought that it will be nice if we can pay reward for our contributors.')}</p>
|
||||||
<br />
|
<br />
|
||||||
<p>{i18n.__('### We believe Meritocracy')}</p>
|
<p>{i18n.__('### We believe Meritocracy')}</p>
|
||||||
<p>{i18n.__('We think developers who has skill and did great things must be rewarded properly.')}</p>
|
<p>{i18n.__('We think developers who have skills and do great things must be rewarded properly.')}</p>
|
||||||
<p>{i18n.__('OSS projects are used in everywhere on the internet, but no matter how they great, most of owners of those projects need to have another job to sustain their living.')}</p>
|
<p>{i18n.__('OSS projects are used in everywhere on the internet, but no matter how they great, most of owners of those projects need to have another job to sustain their living.')}</p>
|
||||||
<p>{i18n.__('It sometimes looks like exploitation.')}</p>
|
<p>{i18n.__('It sometimes looks like exploitation.')}</p>
|
||||||
<p>{i18n.__('We’ve realized IssueHunt could enhance sustainability of open-source ecosystem.')}</p>
|
<p>{i18n.__('We’ve realized IssueHunt could enhance sustainability of open-source ecosystem.')}</p>
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ const app = electron.app
|
|||||||
const Menu = electron.Menu
|
const Menu = electron.Menu
|
||||||
const ipc = electron.ipcMain
|
const ipc = electron.ipcMain
|
||||||
const GhReleases = require('electron-gh-releases')
|
const GhReleases = require('electron-gh-releases')
|
||||||
const isDev = process.env.NODE_ENV !== 'production'
|
const { isPackaged } = app
|
||||||
// electron.crashReporter.start()
|
// electron.crashReporter.start()
|
||||||
|
|
||||||
var ipcServer = null
|
var ipcServer = null
|
||||||
|
|
||||||
var mainWindow = null
|
var mainWindow = null
|
||||||
@@ -36,7 +37,7 @@ const updater = new GhReleases(ghReleasesOpts)
|
|||||||
// Check for updates
|
// Check for updates
|
||||||
// `status` returns true if there is a new update available
|
// `status` returns true if there is a new update available
|
||||||
function checkUpdate () {
|
function checkUpdate () {
|
||||||
if (isDev) { // Prevents app from attempting to update when in dev mode.
|
if (!isPackaged) { // Prevents app from attempting to update when in dev mode.
|
||||||
console.log('Updates are disabled in Development mode, see main-app.js')
|
console.log('Updates are disabled in Development mode, see main-app.js')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -99,12 +100,12 @@ app.on('ready', function () {
|
|||||||
|
|
||||||
// Check update every day
|
// Check update every day
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
if (!isDev) checkUpdate()
|
if (isPackaged) checkUpdate()
|
||||||
}, 1000 * 60 * 60 * 24)
|
}, 1000 * 60 * 60 * 24)
|
||||||
|
|
||||||
// Check update after 10 secs to prevent file locking of Windows
|
// Check update after 10 secs to prevent file locking of Windows
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!isDev) checkUpdate()
|
if (isPackaged) checkUpdate()
|
||||||
|
|
||||||
ipc.on('update-check', function (event, msg) {
|
ipc.on('update-check', function (event, msg) {
|
||||||
if (isUpdateReady) {
|
if (isUpdateReady) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "boost",
|
"name": "boost",
|
||||||
"productName": "Boostnote",
|
"productName": "Boostnote",
|
||||||
"version": "0.11.13",
|
"version": "0.11.15",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"description": "Boostnote",
|
"description": "Boostnote",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ it('should test that copyAttachment should throw an error if sourcePath dosen\'t
|
|||||||
fs.existsSync = jest.fn()
|
fs.existsSync = jest.fn()
|
||||||
fs.existsSync.mockReturnValue(false)
|
fs.existsSync.mockReturnValue(false)
|
||||||
|
|
||||||
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(() => {}, error => {
|
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(() => {}, error => {
|
||||||
expect(error).toBe('source file does not exist')
|
expect(error).toBe('source file does not exist')
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith('path')
|
expect(fs.existsSync).toHaveBeenCalledWith('path')
|
||||||
})
|
})
|
||||||
@@ -64,7 +64,7 @@ it('should test that copyAttachment works correctly assuming correct working of
|
|||||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
uniqueSlug.mockReturnValue(dummyUniquePath)
|
uniqueSlug.mockReturnValue(dummyUniquePath)
|
||||||
|
|
||||||
systemUnderTest.copyAttachment(sourcePath, storageKey, noteKey).then(
|
return systemUnderTest.copyAttachment(sourcePath, storageKey, noteKey).then(
|
||||||
function (newFileName) {
|
function (newFileName) {
|
||||||
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||||
expect(fs.createReadStream).toHaveBeenCalledWith(sourcePath)
|
expect(fs.createReadStream).toHaveBeenCalledWith(sourcePath)
|
||||||
@@ -83,7 +83,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
|
|||||||
const dummyReadStream = {}
|
const dummyReadStream = {}
|
||||||
|
|
||||||
dummyReadStream.pipe = jest.fn()
|
dummyReadStream.pipe = jest.fn()
|
||||||
dummyReadStream.on = jest.fn()
|
dummyReadStream.on = jest.fn((event, callback) => { callback() })
|
||||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||||
fs.existsSync = jest.fn()
|
fs.existsSync = jest.fn()
|
||||||
fs.existsSync.mockReturnValueOnce(true)
|
fs.existsSync.mockReturnValueOnce(true)
|
||||||
@@ -95,7 +95,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
|
|||||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
uniqueSlug.mockReturnValue('dummyPath')
|
uniqueSlug.mockReturnValue('dummyPath')
|
||||||
|
|
||||||
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(
|
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(
|
||||||
function () {
|
function () {
|
||||||
expect(fs.existsSync).toHaveBeenCalledWith(attachmentFolderPath)
|
expect(fs.existsSync).toHaveBeenCalledWith(attachmentFolderPath)
|
||||||
expect(fs.mkdirSync).toHaveBeenCalledWith(attachmentFolderPath)
|
expect(fs.mkdirSync).toHaveBeenCalledWith(attachmentFolderPath)
|
||||||
@@ -109,7 +109,7 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
|||||||
const dummyReadStream = {}
|
const dummyReadStream = {}
|
||||||
|
|
||||||
dummyReadStream.pipe = jest.fn()
|
dummyReadStream.pipe = jest.fn()
|
||||||
dummyReadStream.on = jest.fn()
|
dummyReadStream.on = jest.fn((event, callback) => { callback() })
|
||||||
fs.createReadStream = jest.fn(() => dummyReadStream)
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||||
fs.existsSync = jest.fn()
|
fs.existsSync = jest.fn()
|
||||||
fs.existsSync.mockReturnValueOnce(true)
|
fs.existsSync.mockReturnValueOnce(true)
|
||||||
@@ -120,14 +120,155 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
|||||||
findStorage.findStorage.mockReturnValue(dummyStorage)
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
uniqueSlug.mockReturnValue('dummyPath')
|
uniqueSlug.mockReturnValue('dummyPath')
|
||||||
|
|
||||||
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey', false).then(
|
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey', false).then(
|
||||||
function (newFileName) {
|
function (newFileName) {
|
||||||
expect(newFileName).toBe('path')
|
expect(newFileName).toBe('path')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should test that copyAttachment with url (with extension, without query)', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
|
||||||
|
const dummyReadStream = {
|
||||||
|
pipe: jest.fn(),
|
||||||
|
on: jest.fn((event, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||||
|
|
||||||
|
const dummyWriteStream = {
|
||||||
|
write: jest.fn((data, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||||
|
|
||||||
|
fs.existsSync = jest.fn()
|
||||||
|
fs.existsSync.mockReturnValueOnce(true)
|
||||||
|
fs.existsSync.mockReturnValueOnce(false)
|
||||||
|
fs.mkdirSync = jest.fn()
|
||||||
|
|
||||||
|
findStorage.findStorage = jest.fn()
|
||||||
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
|
uniqueSlug.mockReturnValue('dummyPath')
|
||||||
|
|
||||||
|
const sourcePath = {
|
||||||
|
sourceFilePath: 'http://www.foo.bar/baz/qux.jpg',
|
||||||
|
type: 'base64',
|
||||||
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||||
|
}
|
||||||
|
|
||||||
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||||
|
function (newFileName) {
|
||||||
|
expect(newFileName).toBe('dummyPath.jpg')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that copyAttachment with url (with extension, with query)', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
|
||||||
|
const dummyReadStream = {
|
||||||
|
pipe: jest.fn(),
|
||||||
|
on: jest.fn((event, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||||
|
|
||||||
|
const dummyWriteStream = {
|
||||||
|
write: jest.fn((data, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||||
|
|
||||||
|
fs.existsSync = jest.fn()
|
||||||
|
fs.existsSync.mockReturnValueOnce(true)
|
||||||
|
fs.existsSync.mockReturnValueOnce(false)
|
||||||
|
fs.mkdirSync = jest.fn()
|
||||||
|
|
||||||
|
findStorage.findStorage = jest.fn()
|
||||||
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
|
uniqueSlug.mockReturnValue('dummyPath')
|
||||||
|
|
||||||
|
const sourcePath = {
|
||||||
|
sourceFilePath: 'http://www.foo.bar/baz/qux.jpg?h=1080',
|
||||||
|
type: 'base64',
|
||||||
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||||
|
}
|
||||||
|
|
||||||
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||||
|
function (newFileName) {
|
||||||
|
expect(newFileName).toBe('dummyPath.jpg')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that copyAttachment with url (without extension, without query)', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
|
||||||
|
const dummyReadStream = {
|
||||||
|
pipe: jest.fn(),
|
||||||
|
on: jest.fn((event, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||||
|
|
||||||
|
const dummyWriteStream = {
|
||||||
|
write: jest.fn((data, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||||
|
|
||||||
|
fs.existsSync = jest.fn()
|
||||||
|
fs.existsSync.mockReturnValueOnce(true)
|
||||||
|
fs.existsSync.mockReturnValueOnce(false)
|
||||||
|
fs.mkdirSync = jest.fn()
|
||||||
|
|
||||||
|
findStorage.findStorage = jest.fn()
|
||||||
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
|
uniqueSlug.mockReturnValue('dummyPath')
|
||||||
|
|
||||||
|
const sourcePath = {
|
||||||
|
sourceFilePath: 'http://www.foo.bar/baz/qux',
|
||||||
|
type: 'base64',
|
||||||
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||||
|
}
|
||||||
|
|
||||||
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||||
|
function (newFileName) {
|
||||||
|
expect(newFileName).toBe('dummyPath.png')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that copyAttachment with url (without extension, with query)', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
|
||||||
|
const dummyReadStream = {
|
||||||
|
pipe: jest.fn(),
|
||||||
|
on: jest.fn((event, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
||||||
|
|
||||||
|
const dummyWriteStream = {
|
||||||
|
write: jest.fn((data, callback) => { callback() })
|
||||||
|
}
|
||||||
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
||||||
|
|
||||||
|
fs.existsSync = jest.fn()
|
||||||
|
fs.existsSync.mockReturnValueOnce(true)
|
||||||
|
fs.existsSync.mockReturnValueOnce(false)
|
||||||
|
fs.mkdirSync = jest.fn()
|
||||||
|
|
||||||
|
findStorage.findStorage = jest.fn()
|
||||||
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
||||||
|
uniqueSlug.mockReturnValue('dummyPath')
|
||||||
|
|
||||||
|
const sourcePath = {
|
||||||
|
sourceFilePath: 'http://www.foo.bar/baz/qux?h=1080',
|
||||||
|
type: 'base64',
|
||||||
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
||||||
|
}
|
||||||
|
|
||||||
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
||||||
|
function (newFileName) {
|
||||||
|
expect(newFileName).toBe('dummyPath.png')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('should replace the all ":storage" path with the actual storage path', function () {
|
it('should replace the all ":storage" path with the actual storage path', function () {
|
||||||
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
||||||
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||||
const testInput =
|
const testInput =
|
||||||
'<html>\n' +
|
'<html>\n' +
|
||||||
' <head>\n' +
|
' <head>\n' +
|
||||||
@@ -136,14 +277,18 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href=":storage' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="6">\n' +
|
' <p data-line="6">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
|
' <pre class="fence" data-line="8">\n' +
|
||||||
|
' <span class="filename"></span>\n' +
|
||||||
|
' <div class="gallery" data-autoplay="undefined" data-height="undefined">:storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'f939b2c3.jpg</div>\n' +
|
||||||
|
' </pre>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
const storagePath = '<<dummyStoragePath>>'
|
const storagePath = '<<dummyStoragePath>>'
|
||||||
@@ -155,14 +300,18 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="6">\n' +
|
' <p data-line="6">\n' +
|
||||||
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
|
' <pre class="fence" data-line="8">\n' +
|
||||||
|
' <span class="filename"></span>\n' +
|
||||||
|
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'f939b2c3.jpg</div>\n' +
|
||||||
|
' </pre>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
const actual = systemUnderTest.fixLocalURLS(testInput, storagePath)
|
const actual = systemUnderTest.fixLocalURLS(testInput, storagePath)
|
||||||
@@ -171,6 +320,7 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|||||||
|
|
||||||
it('should replace the ":storage" path with the actual storage path when they have different path separators', function () {
|
it('should replace the ":storage" path with the actual storage path when they have different path separators', function () {
|
||||||
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
||||||
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||||
const testInput =
|
const testInput =
|
||||||
'<html>\n' +
|
'<html>\n' +
|
||||||
' <head>\n' +
|
' <head>\n' +
|
||||||
@@ -179,10 +329,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href=":storage' + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href=":storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
@@ -195,10 +345,10 @@ it('should replace the ":storage" path with the actual storage path when they ha
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
@@ -251,28 +401,17 @@ it('should test that getAttachmentsInMarkdownContent finds all attachments when
|
|||||||
|
|
||||||
it('should test that getAbsolutePathsOfAttachmentsInContent returns all absolute paths', function () {
|
it('should test that getAbsolutePathsOfAttachmentsInContent returns all absolute paths', function () {
|
||||||
const dummyStoragePath = 'dummyStoragePath'
|
const dummyStoragePath = 'dummyStoragePath'
|
||||||
const testInput =
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
||||||
'<html>\n' +
|
const testInput = '"# Test\n' +
|
||||||
' <head>\n' +
|
'\n' +
|
||||||
' //header\n' +
|
'\n' +
|
||||||
' </head>\n' +
|
'\n' +
|
||||||
' <body data-theme="default">\n' +
|
'"'
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
||||||
' <p data-line="2">\n' +
|
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
||||||
' </p>\n' +
|
|
||||||
' <p data-line="4">\n' +
|
|
||||||
' <a href=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
||||||
' </p>\n' +
|
|
||||||
' <p data-line="6">\n' +
|
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
||||||
' </p>\n' +
|
|
||||||
' </body>\n' +
|
|
||||||
'</html>'
|
|
||||||
const actual = systemUnderTest.getAbsolutePathsOfAttachmentsInContent(testInput, dummyStoragePath)
|
const actual = systemUnderTest.getAbsolutePathsOfAttachmentsInContent(testInput, dummyStoragePath)
|
||||||
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.6r4zdgc22xp.png',
|
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png',
|
||||||
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.q2i4iw0fyx.pdf',
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf',
|
||||||
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + 'd6c5ee92.jpg']
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + 'd6c5ee92.jpg']
|
||||||
expect(actual).toEqual(expect.arrayContaining(expected))
|
expect(actual).toEqual(expect.arrayContaining(expected))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -287,13 +426,13 @@ it('should remove the all ":storage" and noteKey references', function () {
|
|||||||
' <body data-theme="default">\n' +
|
' <body data-theme="default">\n' +
|
||||||
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
||||||
' <p data-line="2">\n' +
|
' <p data-line="2">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="4">\n' +
|
' <p data-line="4">\n' +
|
||||||
' <a href=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
' <a href=":storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' <p data-line="6">\n' +
|
' <p data-line="6">\n' +
|
||||||
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.posix.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
@@ -323,8 +462,8 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c
|
|||||||
const noteKey = 'noteKey'
|
const noteKey = 'noteKey'
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + noteKey + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + noteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
|
|
||||||
const expectedOutput =
|
const expectedOutput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
@@ -476,8 +615,8 @@ it('should test that moveAttachments returns a correct modified content version'
|
|||||||
const newNoteKey = 'newNoteKey'
|
const newNoteKey = 'newNoteKey'
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNoteKey + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNoteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
const expectedOutput =
|
const expectedOutput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
@@ -492,8 +631,8 @@ it('should test that cloneAttachments modifies the content of the new note corre
|
|||||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
newNote.content = testInput
|
newNote.content = testInput
|
||||||
findStorage.findStorage = jest.fn()
|
findStorage.findStorage = jest.fn()
|
||||||
findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})
|
findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})
|
||||||
@@ -516,8 +655,8 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
|||||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
|
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
' \n' +
|
||||||
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
||||||
oldNote.content = testInput
|
oldNote.content = testInput
|
||||||
newNote.content = testInput
|
newNote.content = testInput
|
||||||
|
|
||||||
@@ -566,14 +705,22 @@ it('should test that isAttachmentLink works correctly', function () {
|
|||||||
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
||||||
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).toBe(false)
|
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).toBe(false)
|
||||||
expect(systemUnderTest.isAttachmentLink('text ')).toBe(false)
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(false)
|
||||||
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf)')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf)')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf) test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf) test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf)')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf)')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf) test')).toBe(true)
|
||||||
|
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should test that handleAttachmentLinkPaste copies the attachments to the new location', function () {
|
it('should test that handleAttachmentLinkPaste copies the attachments to the new location', function () {
|
||||||
@@ -581,7 +728,7 @@ it('should test that handleAttachmentLinkPaste copies the attachments to the new
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
@@ -596,12 +743,53 @@ it('should test that handleAttachmentLinkPaste copies the attachments to the new
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist', function () {
|
it('should test that handleAttachmentLinkPaste copies the attachments to the new location - win32 path', function () {
|
||||||
const dummyStorage = {path: 'dummyStoragePath'}
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
|
const storageKey = 'storageKey'
|
||||||
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
||||||
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
||||||
|
|
||||||
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||||
|
.then(() => {
|
||||||
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||||
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
||||||
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePath, storageKey, newNoteKey)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist - win32 path', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
|
const pasteText = 'text '
|
||||||
|
const storageKey = 'storageKey'
|
||||||
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
|
sander.exists = jest.fn(() => Promise.resolve(false))
|
||||||
|
systemUnderTest.copyAttachment = jest.fn()
|
||||||
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
||||||
|
|
||||||
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||||
|
.then(() => {
|
||||||
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||||
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
||||||
|
expect(systemUnderTest.copyAttachment).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist -- posix', function () {
|
||||||
|
const dummyStorage = {path: 'dummyStoragePath'}
|
||||||
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
|
const pasteText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
|
|
||||||
@@ -622,8 +810,8 @@ it('should test that handleAttachmentLinkPaste copies multiple attachments if mu
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text  ..' +
|
const pasteText = 'text  ..' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||||
@@ -647,7 +835,7 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyNewFileName = 'dummyNewFileName'
|
const dummyNewFileName = 'dummyNewFileName'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
const expectedText = 'text '
|
const expectedText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
|
|
||||||
@@ -667,8 +855,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyNewFileNameOne = 'dummyNewFileName'
|
const dummyNewFileNameOne = 'dummyNewFileName'
|
||||||
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
||||||
const pasteText = 'text  ' +
|
const pasteText = 'text  ' +
|
||||||
''
|
''
|
||||||
const expectedText = 'text  ' +
|
const expectedText = 'text  ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
@@ -689,8 +877,8 @@ it('should test that handleAttachmentLinkPaste calls the copy method correct if
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text  ..' +
|
const pasteText = 'text  ..' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||||
@@ -716,7 +904,7 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text '
|
const pasteText = 'text '
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const expectedPastText = 'text ' + fileNotFoundMD
|
const expectedPastText = 'text ' + fileNotFoundMD
|
||||||
@@ -735,8 +923,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const pasteText = 'text  ' +
|
const pasteText = 'text  ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
||||||
@@ -757,8 +945,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyFoundFileName = 'dummyFileName'
|
const dummyFoundFileName = 'dummyFileName'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const pasteText = 'text  .. ' +
|
const pasteText = 'text  .. ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
||||||
|
|
||||||
@@ -781,8 +969,8 @@ it('should test that handleAttachmentLinkPaste returns the correct modified past
|
|||||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||||
const dummyFoundFileName = 'dummyFileName'
|
const dummyFoundFileName = 'dummyFileName'
|
||||||
const fileNotFoundMD = 'file not found'
|
const fileNotFoundMD = 'file not found'
|
||||||
const pasteText = 'text  .. ' +
|
const pasteText = 'text  .. ' +
|
||||||
''
|
''
|
||||||
const storageKey = 'storageKey'
|
const storageKey = 'storageKey'
|
||||||
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ test(t => {
|
|||||||
['`MY_TITLE`', 'MY_TITLE'],
|
['`MY_TITLE`', 'MY_TITLE'],
|
||||||
['MY_TITLE', 'MY_TITLE'],
|
['MY_TITLE', 'MY_TITLE'],
|
||||||
// I have no idea for it...
|
// I have no idea for it...
|
||||||
['```test', '`test']
|
['```test', '`test'],
|
||||||
|
['# C# Features', 'C# Features']
|
||||||
]
|
]
|
||||||
|
|
||||||
testCases.forEach(testCase => {
|
testCases.forEach(testCase => {
|
||||||
|
|||||||
Reference in New Issue
Block a user