From a7d5a976caa8ee32dbb3f883ae146e02b3968c16 Mon Sep 17 00:00:00 2001 From: Timothy Farrell Date: Mon, 17 Apr 2017 22:22:44 -0500 Subject: [PATCH] Must use the same db. --- packages/gallery/src/app.js | 2 +- packages/gallery/src/context/generateThumbnails.js | 6 +++--- packages/gallery/src/data/image.js | 5 ++--- packages/gallery/src/services/db.js | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/gallery/src/app.js b/packages/gallery/src/app.js index 61ca3f1..fe0ec22 100644 --- a/packages/gallery/src/app.js +++ b/packages/gallery/src/app.js @@ -8,7 +8,7 @@ document.querySelector('#fInput').onchange = async evt => { }; window.__DEV__ = true; -window.imagedb = getDatabase('gallery-images'); +window.db = getDatabase(); image.imported.subscribe(refresh); diff --git a/packages/gallery/src/context/generateThumbnails.js b/packages/gallery/src/context/generateThumbnails.js index b470c28..6d30269 100644 --- a/packages/gallery/src/context/generateThumbnails.js +++ b/packages/gallery/src/context/generateThumbnails.js @@ -1,7 +1,7 @@ import pica from 'pica/dist/pica'; -import { generateAttachmentUrl } from '../services/db.js'; -import { imported, find, update, addAttachment, DB_NAME } from '../data/image.js'; +import { generateAttachmentUrl, getDatabase } from '../services/db.js'; +import { imported, find, update, addAttachment } from '../data/image.js'; export function maxLinearSize(width, height, max) { const ratio = width / height; @@ -57,7 +57,7 @@ export async function generateThumbnailForImage(id) { const mimetype = attachment.content_type; const { width, height } = maxLinearSize(doc.width, doc.height, 320); const resizedBlob = await resizeImage(attachment.data, mimetype, width, height); - const url = generateAttachmentUrl(DB_NAME, id, 'thumbnail'); + const url = generateAttachmentUrl(getDatabase().name, id, 'thumbnail'); await addAttachment(doc, 'thumbnail', resizedBlob); await update(doc._id, { diff --git a/packages/gallery/src/data/image.js b/packages/gallery/src/data/image.js index c512f34..2b26233 100644 --- a/packages/gallery/src/data/image.js +++ b/packages/gallery/src/data/image.js @@ -6,8 +6,7 @@ import { sha256 } from '../utils/crypto.js'; import { blobToArrayBuffer, deepAssign } from '../utils/conversion.js'; import { Event, backgroundTask } from '../utils/event.js'; -export const DB_NAME = 'gallery-images'; -const db = getDatabase(DB_NAME); +const db = getDatabase(); const PROCESS_PREFIX = 'importing'; // Events @@ -123,7 +122,7 @@ const processImportables = backgroundTask(async function _processImportables() { flash: !!tags.Flash, ISO: tags.ISO, attachmentUrls: { - image: generateAttachmentUrl(DB_NAME, id, 'image') + image: generateAttachmentUrl(db.name, id, 'image') }, gps: { latitude: tags.GPSLatitude, diff --git a/packages/gallery/src/services/db.js b/packages/gallery/src/services/db.js index 4d96c98..595b68d 100644 --- a/packages/gallery/src/services/db.js +++ b/packages/gallery/src/services/db.js @@ -9,7 +9,7 @@ export function generateAttachmentUrl(dbName, docId, attachmentKey) { } const dbs = new Map(); -export function getDatabase(name) { +export function getDatabase(name = 'gallery') { if (!dbs.has(name)) { dbs.set(name, new PouchDB(name)); }