Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icorrect working attachments in electron-render. #587

Closed
Feverqwe opened this issue Mar 27, 2018 · 1 comment
Closed

Icorrect working attachments in electron-render. #587

Feverqwe opened this issue Mar 27, 2018 · 1 comment

Comments

@Feverqwe
Copy link

Feverqwe commented Mar 27, 2018

Case

Add attachment.

Issue

Icorrect working attachments in electron-render. Webpack 4.

Info

  • Environment: electron
  • Adapter: IndexedDB
  • Stack: React

Code

await file.putAttachment({
    id: 'thumbnail.jpg',
    data: buffer,
    type: 'image/jpeg'
});

Throw error

TypeError: Data must be a string or a buffer
    at Hash.update (crypto.js:97)
    at binaryMd5 (index.es.js:15)
    at preprocessBlob (index.es.js:211)
    at preprocessAttachment (index.es.js:240)
    at eval (index.es.js:271)
    at Array.forEach (<anonymous>)
    at preprocessAttachments (index.es.js:253)
    at idbBulkDocs (index.es.js:300)
    at PouchDB.idb_bulkDocs [as _bulkDocs] (index.es.js:1471)
    at PouchDB.eval (index.es.js:1024)

Here create blob, not buffer.

createBlobBuffer(data, type) {
let blobBuffer;
try {
// for browsers
blobBuffer = new Blob([data], {
type
});
} catch (e) {
// for node
blobBuffer = new Buffer(data, {
type
});
}
return blobBuffer;
},

pouchdb-md5 expect buffer.
https://github.com/pouchdb/pouchdb/blob/7c0988c0ae6b773e2a81554b1b49ffe74471ce97/packages/node_modules/pouchdb-md5/src/binaryMd5.js#L3-L6
But in package.json for browser used other file. Webpack with target "electron-renderer" don't use "browser" files.
https://github.com/pouchdb/pouchdb/blob/7c0988c0ae6b773e2a81554b1b49ffe74471ce97/packages/node_modules/pouchdb-md5/package.json#L11-L15

I can fix it if in webpack add alias

resolve: {
  alias: {
    'pouchdb-md5': path.resolve(__dirname, './node_modules/pouchdb-md5/lib/index-browser')
  },
},

But will better if createBlobBuffer function in rxdb will depend from target via package.json.

@pubkey
Copy link
Owner

pubkey commented Mar 29, 2018

I could reproduce this. Fix will come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants