mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
Rename FileDownloadStore => AttachmentStore
This commit is contained in:
parent
2dce6fcb6a
commit
73b7fe5553
|
@ -1994,7 +1994,7 @@
|
|||
5304677: src/flux/tasks/change-unread-task.js
|
||||
5341333: src/flux/tasks/change-starred-task.js
|
||||
5350052: src/flux/stores/outbox-store.js
|
||||
5960988: src/flux/stores/file-download-store.js
|
||||
5960988: src/flux/stores/attachment-store.js
|
||||
5356198: src/flux/tasks/send-draft-task.js
|
||||
5417961: src/sound-registry.js
|
||||
5975123: node_modules/request-progress/package.json
|
||||
|
@ -2005,7 +2005,7 @@
|
|||
5431422: src/flux/tasks/syncback-model-task.js
|
||||
91991403: src/flux/tasks/notify-plugins-of-send-task.js
|
||||
91821594: src/flux/edgehill-api.js
|
||||
5960988: src/flux/stores/file-download-store.js
|
||||
5960988: src/flux/stores/attachment-store.js
|
||||
5459931: src/flux/tasks/syncback-draft-task.js
|
||||
5975123: node_modules/request-progress/package.json
|
||||
5976554: node_modules/request-progress/index.js
|
||||
|
@ -2260,7 +2260,7 @@
|
|||
5941725: src/flux/stores/file-upload-store.js
|
||||
1894875: node_modules/mkdirp/package.json
|
||||
1896279: node_modules/mkdirp/index.js
|
||||
5960988: src/flux/stores/file-download-store.js
|
||||
5960988: src/flux/stores/attachment-store.js
|
||||
5975123: node_modules/request-progress/package.json
|
||||
5976554: node_modules/request-progress/index.js
|
||||
3708754: static/index.less
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, {Component, PropTypes} from 'react'
|
||||
import {Actions, Utils, FileDownloadStore} from 'nylas-exports'
|
||||
import {Actions, Utils, AttachmentStore} from 'nylas-exports'
|
||||
import {AttachmentItem, ImageAttachmentItem} from 'nylas-component-kit'
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ class MessageAttachments extends Component {
|
|||
renderAttachment(AttachmentRenderer, file) {
|
||||
const {canRemoveAttachments, downloads, filePreviewPaths, headerMessageId} = this.props
|
||||
const download = downloads[file.id]
|
||||
const filePath = FileDownloadStore.pathForFile(file)
|
||||
const filePath = AttachmentStore.pathForFile(file)
|
||||
const fileIconName = `file-${file.displayExtension()}.png`
|
||||
const displayName = file.displayName()
|
||||
const displaySize = file.displayFileSize()
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
Utils,
|
||||
Actions,
|
||||
DraftStore,
|
||||
FileDownloadStore,
|
||||
AttachmentStore,
|
||||
DraftHelpers,
|
||||
} from 'nylas-exports'
|
||||
import {
|
||||
|
@ -312,7 +312,7 @@ export default class ComposerView extends React.Component {
|
|||
key={file.id}
|
||||
className="file-upload"
|
||||
draggable={false}
|
||||
filePath={FileDownloadStore.pathForFile(file)}
|
||||
filePath={AttachmentStore.pathForFile(file)}
|
||||
displayName={file.filename}
|
||||
fileIconName={`file-${file.extension}.png`}
|
||||
onRemoveAttachment={() => Actions.removeAttachment(headerMessageId, file)}
|
||||
|
@ -326,7 +326,7 @@ export default class ComposerView extends React.Component {
|
|||
key={file.id}
|
||||
className="file-upload"
|
||||
draggable={false}
|
||||
filePath={FileDownloadStore.pathForFile(file)}
|
||||
filePath={AttachmentStore.pathForFile(file)}
|
||||
displayName={file.filename}
|
||||
onRemoveAttachment={() => Actions.removeAttachment(headerMessageId, file)}
|
||||
/>
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, {Component, PropTypes} from 'react';
|
|||
import ReactDOM from 'react-dom';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {Actions, FileDownloadStore} from 'nylas-exports'
|
||||
import {Actions, AttachmentStore} from 'nylas-exports'
|
||||
import {ImageAttachmentItem} from 'nylas-component-kit'
|
||||
|
||||
export default class InlineImageUploadContainer extends Component {
|
||||
|
@ -95,7 +95,7 @@ export default class InlineImageUploadContainer extends Component {
|
|||
u.id === fileId
|
||||
);
|
||||
|
||||
const filepath = FileDownloadStore.pathForFile(file);
|
||||
const filepath = AttachmentStore.pathForFile(file);
|
||||
const nextFileName = `edited-${Date.now()}.png`;
|
||||
const nextFilePath = path.join(path.dirname(filepath), nextFileName);
|
||||
|
||||
|
@ -153,7 +153,7 @@ export default class InlineImageUploadContainer extends Component {
|
|||
<ImageAttachmentItem
|
||||
className="file-upload"
|
||||
draggable={false}
|
||||
filePath={FileDownloadStore.pathForFile(file)}
|
||||
filePath={AttachmentStore.pathForFile(file)}
|
||||
displayName={file.filename}
|
||||
onRemoveAttachment={() => Actions.removeAttachment(draft.headerMessageId, file)}
|
||||
/>
|
||||
|
|
|
@ -8,7 +8,7 @@ EmailFrame = require('./email-frame').default
|
|||
MessageUtils,
|
||||
MessageBodyProcessor,
|
||||
QuotedHTMLTransformer,
|
||||
FileDownloadStore
|
||||
AttachmentStore
|
||||
} = require 'nylas-exports'
|
||||
{
|
||||
InjectedComponentSet,
|
||||
|
@ -101,7 +101,7 @@ class MessageItemBody extends React.Component
|
|||
# (Necessary when attachment download mode is set to "manual")
|
||||
cidRegexp = new RegExp("cid:#{file.contentId}(['\"])", 'gi')
|
||||
body = body.replace cidRegexp, (text, quoteCharacter) ->
|
||||
"file://#{FileDownloadStore.pathForFile(file)}#{quoteCharacter} data-nylas-file=\"#{encodedAttributeForFile(file)}\" "
|
||||
"file://#{AttachmentStore.pathForFile(file)}#{quoteCharacter} data-nylas-file=\"#{encodedAttributeForFile(file)}\" "
|
||||
|
||||
# Replace remaining cid: references - we will not display them since they'll
|
||||
# throw "unknown ERR_UNKNOWN_URL_SCHEME". Show a transparent pixel so that there's
|
||||
|
|
|
@ -14,7 +14,7 @@ MessageControls = require './message-controls'
|
|||
MessageBodyProcessor,
|
||||
QuotedHTMLTransformer,
|
||||
ComponentRegistry,
|
||||
FileDownloadStore} = require 'nylas-exports'
|
||||
AttachmentStore} = require 'nylas-exports'
|
||||
{RetinaImg,
|
||||
InjectedComponentSet,
|
||||
InjectedComponent} = require 'nylas-component-kit'
|
||||
|
@ -35,13 +35,13 @@ class MessageItem extends React.Component
|
|||
@state =
|
||||
# Holds the downloadData (if any) for all of our files. It's a hash
|
||||
# keyed by a fileId. The value is the downloadData.
|
||||
downloads: FileDownloadStore.getDownloadDataForFiles(fileIds)
|
||||
filePreviewPaths: FileDownloadStore.previewPathsForFiles(fileIds)
|
||||
downloads: AttachmentStore.getDownloadDataForFiles(fileIds)
|
||||
filePreviewPaths: AttachmentStore.previewPathsForFiles(fileIds)
|
||||
detailedHeaders: false
|
||||
detailedHeadersTogglePos: {top: 18}
|
||||
|
||||
componentDidMount: =>
|
||||
@_storeUnlisten = FileDownloadStore.listen(@_onDownloadStoreChange)
|
||||
@_storeUnlisten = AttachmentStore.listen(@_onDownloadStoreChange)
|
||||
@_setDetailedHeadersTogglePos()
|
||||
|
||||
componentDidUpdate: =>
|
||||
|
@ -269,7 +269,7 @@ class MessageItem extends React.Component
|
|||
_onDownloadStoreChange: =>
|
||||
fileIds = @props.message.fileIds()
|
||||
@setState
|
||||
downloads: FileDownloadStore.getDownloadDataForFiles(fileIds)
|
||||
filePreviewPaths: FileDownloadStore.previewPathsForFiles(fileIds)
|
||||
downloads: AttachmentStore.getDownloadDataForFiles(fileIds)
|
||||
filePreviewPaths: AttachmentStore.previewPathsForFiles(fileIds)
|
||||
|
||||
module.exports = MessageItem
|
||||
|
|
|
@ -6,7 +6,7 @@ ReactTestUtils = require('react-dom/test-utils')
|
|||
{Contact,
|
||||
Message,
|
||||
File,
|
||||
FileDownloadStore,
|
||||
AttachmentStore,
|
||||
MessageBodyProcessor} = require "nylas-exports"
|
||||
|
||||
EmailFrameStub = React.createClass({render: -> <div></div>})
|
||||
|
@ -82,7 +82,7 @@ MessageItemBody = proxyquire '../lib/message-item-body',
|
|||
|
||||
xdescribe "MessageItem", ->
|
||||
beforeEach ->
|
||||
spyOn(FileDownloadStore, 'pathForFile').andCallFake (f) ->
|
||||
spyOn(AttachmentStore, 'pathForFile').andCallFake (f) ->
|
||||
return '/fake/path.png' if f.id is file.id
|
||||
return '/fake/path-inline.png' if f.id is file_inline.id
|
||||
return '/fake/path-downloading.png' if f.id is file_inline_downloading.id
|
||||
|
@ -151,12 +151,12 @@ xdescribe "MessageItem", ->
|
|||
body = ReactTestUtils.findRenderedComponentWithType(@component, EmailFrameStub).props.content
|
||||
expect(body.indexOf('cid')).toEqual(-1)
|
||||
|
||||
it "should replace cid:<file.contentId> with the FileDownloadStore's path for the file", ->
|
||||
it "should replace cid:<file.contentId> with the AttachmentStore's path for the file", ->
|
||||
runs =>
|
||||
body = ReactTestUtils.findRenderedComponentWithType(@component, EmailFrameStub).props.content
|
||||
expect(body.indexOf('alt="A" src="file:///fake/path-inline.png"')).toEqual(@message.body.indexOf('alt="A"'))
|
||||
|
||||
it "should not replace cid:<file.contentId> with the FileDownloadStore's path if the download is in progress", ->
|
||||
it "should not replace cid:<file.contentId> with the AttachmentStore's path if the download is in progress", ->
|
||||
runs =>
|
||||
body = ReactTestUtils.findRenderedComponentWithType(@component, EmailFrameStub).props.content
|
||||
expect(body.indexOf('/fake/path-downloading.png')).toEqual(-1)
|
||||
|
|
|
@ -9,7 +9,7 @@ ReactTestUtils = require 'react-dom/test-utils'
|
|||
Thread,
|
||||
Utils,
|
||||
QuotedHTMLTransformer,
|
||||
FileDownloadStore,
|
||||
AttachmentStore,
|
||||
MessageBodyProcessor} = require "nylas-exports"
|
||||
|
||||
MessageItemBody = React.createClass({render: -> <div></div>})
|
||||
|
@ -91,12 +91,12 @@ MessageTimestamp = require('../lib/message-timestamp').default
|
|||
|
||||
xdescribe "MessageItem", ->
|
||||
beforeEach ->
|
||||
spyOn(FileDownloadStore, 'pathForFile').andCallFake (f) ->
|
||||
spyOn(AttachmentStore, 'pathForFile').andCallFake (f) ->
|
||||
return '/fake/path.png' if f.id is file.id
|
||||
return '/fake/path-inline.png' if f.id is file_inline.id
|
||||
return '/fake/path-downloading.png' if f.id is file_inline_downloading.id
|
||||
return null
|
||||
spyOn(FileDownloadStore, 'getDownloadDataForFiles').andCallFake (ids) ->
|
||||
spyOn(AttachmentStore, 'getDownloadDataForFiles').andCallFake (ids) ->
|
||||
return {'file_1_id': download, 'file_inline_downloading_id': download_inline}
|
||||
|
||||
spyOn(MessageBodyProcessor, '_addToCache').andCallFake ->
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
DraftStore,
|
||||
AccountStore,
|
||||
DatabaseStore,
|
||||
FileDownloadStore,
|
||||
AttachmentStore,
|
||||
DatabaseWriter,
|
||||
SanitizeTransformer,
|
||||
InlineStyleTransformer,
|
||||
|
@ -32,7 +32,7 @@ describe('DraftFactory', function draftFactory() {
|
|||
// Out of the scope of these specs
|
||||
spyOn(InlineStyleTransformer, 'run').andCallFake((input) => Promise.resolve(input));
|
||||
spyOn(SanitizeTransformer, 'run').andCallFake((input) => Promise.resolve(input));
|
||||
spyOn(FileDownloadStore, 'getDownloadDataForFile').andCallFake((fid) => {
|
||||
spyOn(AttachmentStore, 'getDownloadDataForFile').andCallFake((fid) => {
|
||||
return downloadData[fid]
|
||||
});
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ NylasAPI = require('../../src/flux/nylas-api').default
|
|||
NylasAPIRequest = require('../../src/flux/nylas-api-request').default
|
||||
File = require('../../src/flux/models/file').default
|
||||
Message = require('../../src/flux/models/message').default
|
||||
FileDownloadStore = require('../../src/flux/stores/file-download-store').default
|
||||
{Download} = require('../../src/flux/stores/file-download-store')
|
||||
AttachmentStore = require('../../src/flux/stores/attachment-store').default
|
||||
{Download} = require('../../src/flux/stores/attachment-store')
|
||||
AccountStore = require('../../src/flux/stores/account-store').default
|
||||
|
||||
|
||||
xdescribe 'FileDownloadStoreSpecs', ->
|
||||
xdescribe 'AttachmentStoreSpecs', ->
|
||||
|
||||
describe "Download", ->
|
||||
beforeEach ->
|
||||
|
@ -46,7 +46,7 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
it "should create a request for /files/123/download", ->
|
||||
expect(NylasAPIRequest.prototype.run.mostRecentCall.object.options.path).toBe("/files/123/download")
|
||||
|
||||
describe "FileDownloadStore", ->
|
||||
describe "AttachmentStore", ->
|
||||
beforeEach ->
|
||||
account = AccountStore.accounts()[0]
|
||||
|
||||
|
@ -69,29 +69,29 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
targetPath : '/Users/testuser/.nylas-mail/downloads/id/123.png'
|
||||
})
|
||||
|
||||
FileDownloadStore._downloads = {}
|
||||
FileDownloadStore._downloadDirectory = "/Users/testuser/.nylas-mail/downloads"
|
||||
spyOn(FileDownloadStore, '_generatePreview').andReturn(Promise.resolve())
|
||||
AttachmentStore._downloads = {}
|
||||
AttachmentStore._downloadDirectory = "/Users/testuser/.nylas-mail/downloads"
|
||||
spyOn(AttachmentStore, '_generatePreview').andReturn(Promise.resolve())
|
||||
|
||||
describe "pathForFile", ->
|
||||
it "should return path within the download directory with the file id and displayName", ->
|
||||
f = new File(filename: '123.png', contentType: 'image/png', id: 'id')
|
||||
spyOn(f, 'displayName').andCallThrough()
|
||||
expect(FileDownloadStore.pathForFile(f)).toBe("/Users/testuser/.nylas-mail/downloads/id/123.png")
|
||||
expect(AttachmentStore.pathForFile(f)).toBe("/Users/testuser/.nylas-mail/downloads/id/123.png")
|
||||
expect(f.displayName).toHaveBeenCalled()
|
||||
|
||||
it "should return unique paths for identical filenames with different IDs", ->
|
||||
f1 = new File(filename: '123.png', contentType: 'image/png', id: 'id1')
|
||||
f2 = new File(filename: '123.png', contentType: 'image/png', id: 'id2')
|
||||
expect(FileDownloadStore.pathForFile(f1)).toBe("/Users/testuser/.nylas-mail/downloads/id1/123.png")
|
||||
expect(FileDownloadStore.pathForFile(f2)).toBe("/Users/testuser/.nylas-mail/downloads/id2/123.png")
|
||||
expect(AttachmentStore.pathForFile(f1)).toBe("/Users/testuser/.nylas-mail/downloads/id1/123.png")
|
||||
expect(AttachmentStore.pathForFile(f2)).toBe("/Users/testuser/.nylas-mail/downloads/id2/123.png")
|
||||
|
||||
it "should escape the displayName if it contains path separator characters", ->
|
||||
f1 = new File(filename: "static#{path.sep}b#{path.sep}a.jpg", contentType: 'image/png', id: 'id1')
|
||||
expect(FileDownloadStore.pathForFile(f1)).toBe("/Users/testuser/.nylas-mail/downloads/id1/static-b-a.jpg")
|
||||
expect(AttachmentStore.pathForFile(f1)).toBe("/Users/testuser/.nylas-mail/downloads/id1/static-b-a.jpg")
|
||||
|
||||
f1 = new File(filename: "my:file ? Windows /hates/ me :->.jpg", contentType: 'image/png', id: 'id1')
|
||||
expect(FileDownloadStore.pathForFile(f1)).toBe("/Users/testuser/.nylas-mail/downloads/id1/my-file - Windows -hates- me ---.jpg")
|
||||
expect(AttachmentStore.pathForFile(f1)).toBe("/Users/testuser/.nylas-mail/downloads/id1/my-file - Windows -hates- me ---.jpg")
|
||||
|
||||
describe "_checkForDownloadedFile", ->
|
||||
it "should return true if the file exists at the path and is the right size", ->
|
||||
|
@ -99,7 +99,7 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
spyOn(fs, 'statAsync').andCallFake (path) ->
|
||||
Promise.resolve({size: 100})
|
||||
waitsForPromise ->
|
||||
FileDownloadStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||
AttachmentStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||
expect(downloaded).toBe(true)
|
||||
|
||||
it "should return false if the file does not exist", ->
|
||||
|
@ -107,7 +107,7 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
spyOn(fs, 'statAsync').andCallFake (path) ->
|
||||
Promise.reject(new Error("File does not exist"))
|
||||
waitsForPromise ->
|
||||
FileDownloadStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||
AttachmentStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||
expect(downloaded).toBe(false)
|
||||
|
||||
it "should return false if the file is too small", ->
|
||||
|
@ -115,27 +115,27 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
spyOn(fs, 'statAsync').andCallFake (path) ->
|
||||
Promise.resolve({size: 50})
|
||||
waitsForPromise ->
|
||||
FileDownloadStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||
AttachmentStore._checkForDownloadedFile(f).then (downloaded) ->
|
||||
expect(downloaded).toBe(false)
|
||||
|
||||
describe "_ensureFile", ->
|
||||
beforeEach ->
|
||||
spyOn(Download.prototype, 'run').andCallFake -> Promise.resolve(@)
|
||||
spyOn(FileDownloadStore, '_prepareFolder').andCallFake -> Promise.resolve(true)
|
||||
spyOn(AttachmentStore, '_prepareFolder').andCallFake -> Promise.resolve(true)
|
||||
|
||||
it "should make sure that the download file path exists", ->
|
||||
waitsForPromise =>
|
||||
FileDownloadStore._ensureFile(@testfile).then ->
|
||||
expect(FileDownloadStore._prepareFolder).toHaveBeenCalled()
|
||||
AttachmentStore._ensureFile(@testfile).then ->
|
||||
expect(AttachmentStore._prepareFolder).toHaveBeenCalled()
|
||||
|
||||
it "should return the promise returned by download.run if the download already exists", ->
|
||||
existing =
|
||||
fileId: @testfile.id
|
||||
run: jasmine.createSpy('existing.run').andCallFake ->
|
||||
Promise.resolve(existing)
|
||||
FileDownloadStore._downloads[@testfile.id] = existing
|
||||
AttachmentStore._downloads[@testfile.id] = existing
|
||||
|
||||
promise = FileDownloadStore._ensureFile(@testfile)
|
||||
promise = AttachmentStore._ensureFile(@testfile)
|
||||
expect(promise instanceof Promise).toBe(true)
|
||||
waitsForPromise ->
|
||||
promise.then ->
|
||||
|
@ -143,12 +143,12 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
|
||||
describe "when the downloaded file exists", ->
|
||||
beforeEach ->
|
||||
spyOn(FileDownloadStore, '_checkForDownloadedFile').andCallFake ->
|
||||
spyOn(AttachmentStore, '_checkForDownloadedFile').andCallFake ->
|
||||
Promise.resolve(true)
|
||||
|
||||
it "should resolve with a Download without calling download.run", ->
|
||||
waitsForPromise =>
|
||||
FileDownloadStore._ensureFile(@testfile).then (download) ->
|
||||
AttachmentStore._ensureFile(@testfile).then (download) ->
|
||||
expect(Download.prototype.run).not.toHaveBeenCalled()
|
||||
expect(download instanceof Download).toBe(true)
|
||||
expect(download.data()).toEqual({
|
||||
|
@ -162,13 +162,13 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
|
||||
describe "when the downloaded file does not exist", ->
|
||||
beforeEach ->
|
||||
spyOn(FileDownloadStore, '_checkForDownloadedFile').andCallFake ->
|
||||
spyOn(AttachmentStore, '_checkForDownloadedFile').andCallFake ->
|
||||
Promise.resolve(false)
|
||||
|
||||
it "should register the download with the right attributes", ->
|
||||
FileDownloadStore._ensureFile(@testfile)
|
||||
AttachmentStore._ensureFile(@testfile)
|
||||
advanceClock(0)
|
||||
expect(FileDownloadStore.getDownloadDataForFile(@testfile.id)).toEqual({
|
||||
expect(AttachmentStore.getDownloadDataForFile(@testfile.id)).toEqual({
|
||||
state : 'unstarted',fileId : 'id',
|
||||
percent : 0,
|
||||
filename : '123.png',
|
||||
|
@ -178,13 +178,13 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
|
||||
it "should call download.run", ->
|
||||
waitsForPromise =>
|
||||
FileDownloadStore._ensureFile(@testfile)
|
||||
AttachmentStore._ensureFile(@testfile)
|
||||
runs ->
|
||||
expect(Download.prototype.run).toHaveBeenCalled()
|
||||
|
||||
it "should resolve with a Download", ->
|
||||
waitsForPromise =>
|
||||
FileDownloadStore._ensureFile(@testfile).then (download) ->
|
||||
AttachmentStore._ensureFile(@testfile).then (download) ->
|
||||
expect(download instanceof Download).toBe(true)
|
||||
expect(download.data()).toEqual({
|
||||
state : 'unstarted',
|
||||
|
@ -197,17 +197,17 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
|
||||
describe "_fetch", ->
|
||||
it "should call through to startDownload", ->
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake ->
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake ->
|
||||
Promise.resolve(@testdownload)
|
||||
FileDownloadStore._fetch(@testfile)
|
||||
expect(FileDownloadStore._ensureFile).toHaveBeenCalled()
|
||||
AttachmentStore._fetch(@testfile)
|
||||
expect(AttachmentStore._ensureFile).toHaveBeenCalled()
|
||||
|
||||
it "should fail silently since it's called passively", ->
|
||||
spyOn(FileDownloadStore, '_presentError')
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake =>
|
||||
spyOn(AttachmentStore, '_presentError')
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake =>
|
||||
Promise.reject(@testdownload)
|
||||
FileDownloadStore._fetch(@testfile)
|
||||
expect(FileDownloadStore._presentError).not.toHaveBeenCalled()
|
||||
AttachmentStore._fetch(@testfile)
|
||||
expect(AttachmentStore._presentError).not.toHaveBeenCalled()
|
||||
|
||||
describe "_fetchAndOpen", ->
|
||||
it "should open the file once it's been downloaded", ->
|
||||
|
@ -215,23 +215,23 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
download = {targetPath: @savePath}
|
||||
downloadResolve = null
|
||||
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake =>
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake =>
|
||||
new Promise (resolve, reject) ->
|
||||
downloadResolve = resolve
|
||||
|
||||
FileDownloadStore._fetchAndOpen(@testfile)
|
||||
AttachmentStore._fetchAndOpen(@testfile)
|
||||
expect(shell.openItem).not.toHaveBeenCalled()
|
||||
downloadResolve(download)
|
||||
advanceClock(100)
|
||||
expect(shell.openItem).toHaveBeenCalledWith(@savePath)
|
||||
|
||||
it "should open an error if the download fails", ->
|
||||
spyOn(FileDownloadStore, '_presentError')
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake =>
|
||||
spyOn(AttachmentStore, '_presentError')
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake =>
|
||||
Promise.reject(@testdownload)
|
||||
FileDownloadStore._fetchAndOpen(@testfile)
|
||||
AttachmentStore._fetchAndOpen(@testfile)
|
||||
advanceClock(1)
|
||||
expect(FileDownloadStore._presentError).toHaveBeenCalled()
|
||||
expect(AttachmentStore._presentError).toHaveBeenCalled()
|
||||
|
||||
describe "_fetchAndSave", ->
|
||||
beforeEach ->
|
||||
|
@ -239,19 +239,19 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
spyOn(NylasEnv, 'showSaveDialog').andCallFake (options, callback) => callback(@userSelectedPath)
|
||||
|
||||
it "should open a save dialog and prompt the user to choose a download path", ->
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake =>
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake =>
|
||||
new Promise (resolve, reject) -> # never resolve
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
expect(NylasEnv.showSaveDialog).toHaveBeenCalled()
|
||||
expect(FileDownloadStore._ensureFile).toHaveBeenCalledWith(@testfile)
|
||||
expect(AttachmentStore._ensureFile).toHaveBeenCalledWith(@testfile)
|
||||
|
||||
it "should open an error if the download fails", ->
|
||||
spyOn(FileDownloadStore, '_presentError')
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake =>
|
||||
spyOn(AttachmentStore, '_presentError')
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake =>
|
||||
Promise.reject(@testdownload)
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(FileDownloadStore._presentError).toHaveBeenCalled()
|
||||
expect(AttachmentStore._presentError).toHaveBeenCalled()
|
||||
|
||||
describe "when the user confirms a path", ->
|
||||
beforeEach ->
|
||||
|
@ -262,13 +262,13 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
on: (eventName, eventCallback) =>
|
||||
@onEndEventCallback = eventCallback
|
||||
|
||||
spyOn(FileDownloadStore, '_ensureFile').andCallFake =>
|
||||
spyOn(AttachmentStore, '_ensureFile').andCallFake =>
|
||||
Promise.resolve(@download)
|
||||
spyOn(fs, 'createReadStream').andReturn(streamStub)
|
||||
spyOn(fs, 'createWriteStream')
|
||||
|
||||
it "should copy the file to the download path after it's been downloaded and open it after the stream has ended", ->
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(fs.createReadStream).toHaveBeenCalledWith(@download.targetPath)
|
||||
expect(shell.showItemInFolder).not.toHaveBeenCalled()
|
||||
|
@ -276,42 +276,42 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
advanceClock(1)
|
||||
|
||||
it "should show file in folder if download path differs from previous download path", ->
|
||||
spyOn(FileDownloadStore, '_saveDownload').andCallFake =>
|
||||
spyOn(AttachmentStore, '_saveDownload').andCallFake =>
|
||||
Promise.resolve(@testfile)
|
||||
NylasEnv.savedState.lastDownloadDirectory = null
|
||||
@userSelectedPath = "/Users/imaginary/.nylas-mail/Another Random Folder/file.jpg"
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(shell.showItemInFolder).toHaveBeenCalledWith(@userSelectedPath)
|
||||
|
||||
it "should not show the file in the folder if the download path is the previous download path", ->
|
||||
spyOn(FileDownloadStore, '_saveDownload').andCallFake =>
|
||||
spyOn(AttachmentStore, '_saveDownload').andCallFake =>
|
||||
Promise.resolve(@testfile)
|
||||
@userSelectedPath = "/Users/imaginary/.nylas-mail/Another Random Folder/123.png"
|
||||
NylasEnv.savedState.lastDownloadDirectory = "/Users/imaginary/.nylas-mail/Another Random Folder"
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(shell.showItemInFolder).not.toHaveBeenCalled()
|
||||
|
||||
it "should update the NylasEnv.savedState.lastDownloadDirectory if is has changed", ->
|
||||
spyOn(FileDownloadStore, '_saveDownload').andCallFake =>
|
||||
spyOn(AttachmentStore, '_saveDownload').andCallFake =>
|
||||
Promise.resolve(@testfile)
|
||||
NylasEnv.savedState.lastDownloadDirectory = null
|
||||
@userSelectedPath = "/Users/imaginary/.nylas-mail/Another Random Folder/file.jpg"
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(NylasEnv.savedState.lastDownloadDirectory).toEqual('/Users/imaginary/.nylas-mail/Another Random Folder')
|
||||
|
||||
describe "file extensions", ->
|
||||
it "should allow the user to save the file with a different extension", ->
|
||||
@userSelectedPath = "/Users/imaginary/.nylas-mail/Downloads/b-changed.tiff"
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(fs.createWriteStream).toHaveBeenCalledWith(@userSelectedPath)
|
||||
|
||||
it "should restore the extension if the user removed it entirely, because it's usually an accident", ->
|
||||
@userSelectedPath = "/Users/imaginary/.nylas-mail/Downloads/b-changed"
|
||||
FileDownloadStore._fetchAndSave(@testfile)
|
||||
AttachmentStore._fetchAndSave(@testfile)
|
||||
advanceClock(1)
|
||||
expect(fs.createWriteStream).toHaveBeenCalledWith("#{@userSelectedPath}.png")
|
||||
|
||||
|
@ -320,18 +320,18 @@ xdescribe 'FileDownloadStoreSpecs', ->
|
|||
@download =
|
||||
ensureClosed: jasmine.createSpy('abort')
|
||||
fileId: @testfile.id
|
||||
FileDownloadStore._downloads[@testfile.id] = @download
|
||||
AttachmentStore._downloads[@testfile.id] = @download
|
||||
|
||||
it "should cancel the download for the provided file", ->
|
||||
spyOn(fs, 'exists').andCallFake (path, callback) -> callback(true)
|
||||
spyOn(fs, 'unlink')
|
||||
FileDownloadStore._abortFetchFile(@testfile)
|
||||
AttachmentStore._abortFetchFile(@testfile)
|
||||
expect(fs.unlink).toHaveBeenCalled()
|
||||
expect(@download.ensureClosed).toHaveBeenCalled()
|
||||
|
||||
it "should not try to delete the file if doesn't exist", ->
|
||||
spyOn(fs, 'exists').andCallFake (path, callback) -> callback(false)
|
||||
spyOn(fs, 'unlink')
|
||||
FileDownloadStore._abortFetchFile(@testfile)
|
||||
AttachmentStore._abortFetchFile(@testfile)
|
||||
expect(fs.unlink).not.toHaveBeenCalled()
|
||||
expect(@download.ensureClosed).toHaveBeenCalled()
|
||||
|
|
|
@ -33,7 +33,7 @@ const NonPreviewableExtensions = [
|
|||
|
||||
const THUMBNAIL_WIDTH = 320
|
||||
|
||||
class FileDownloadStore extends NylasStore {
|
||||
class AttachmentStore extends NylasStore {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
@ -433,4 +433,4 @@ class FileDownloadStore extends NylasStore {
|
|||
}
|
||||
}
|
||||
|
||||
export default new FileDownloadStore()
|
||||
export default new AttachmentStore()
|
|
@ -1,7 +1,7 @@
|
|||
_ = require 'underscore'
|
||||
path = require 'path'
|
||||
|
||||
{FileDownloadStore} = require 'nylas-exports'
|
||||
{AttachmentStore} = require 'nylas-exports'
|
||||
|
||||
Actions = require('../actions').default
|
||||
DatabaseStore = require('./database-store').default
|
||||
|
|
|
@ -142,7 +142,7 @@ lazyLoadAndRegisterStore(`MailRulesStore`, 'mail-rules-store');
|
|||
lazyLoadAndRegisterStore(`SendActionsStore`, 'send-actions-store');
|
||||
lazyLoadAndRegisterStore(`FeatureUsageStore`, 'feature-usage-store');
|
||||
lazyLoadAndRegisterStore(`ThreadCountsStore`, 'thread-counts-store');
|
||||
lazyLoadAndRegisterStore(`FileDownloadStore`, 'file-download-store');
|
||||
lazyLoadAndRegisterStore(`AttachmentStore`, 'attachment-store');
|
||||
lazyLoadAndRegisterStore(`OnlineStatusStore`, 'online-status-store');
|
||||
lazyLoadAndRegisterStore(`UpdateChannelStore`, 'update-channel-store');
|
||||
lazyLoadAndRegisterStore(`PreferencesUIStore`, 'preferences-ui-store');
|
||||
|
|
Loading…
Reference in a new issue