@scalemule/news-publication 0.0.33 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -158,7 +158,18 @@ function useReviewDrafts(session, revision, initial, request) {
158
158
  }
159
159
  };
160
160
  }
161
+ async function encodePendingPhoto(value) {
162
+ const { file, ...details } = value;
163
+ return { ...details, file: { bytes: await file.arrayBuffer(), name: file.name, type: file.type, lastModified: file.lastModified } };
164
+ }
165
+ function decodePendingPhoto(value) {
166
+ if (!value) return void 0;
167
+ if (value.file instanceof File) return value;
168
+ const file = value.file;
169
+ return { ...value, file: new File([file.bytes], file.name, { type: file.type, lastModified: file.lastModified }) };
170
+ }
161
171
  async function stored(key, value) {
172
+ const encoded = value ? await encodePendingPhoto(value) : value;
162
173
  const db = await new Promise((resolve, reject) => {
163
174
  const request = indexedDB.open("story-review-pending-media", 1);
164
175
  request.onupgradeneeded = () => request.result.createObjectStore("photos");
@@ -169,8 +180,14 @@ async function stored(key, value) {
169
180
  return await new Promise((resolve, reject) => {
170
181
  const tx = db.transaction("photos", value === void 0 ? "readonly" : "readwrite");
171
182
  const store = tx.objectStore("photos");
172
- const request = value === void 0 ? store.get(key) : value === null ? store.delete(key) : store.put(value, key);
173
- tx.oncomplete = () => resolve(value === void 0 ? request.result : void 0);
183
+ const request = value === void 0 ? store.get(key) : value === null ? store.delete(key) : store.put(encoded, key);
184
+ tx.oncomplete = () => {
185
+ try {
186
+ resolve(value === void 0 ? decodePendingPhoto(request.result) : void 0);
187
+ } catch (error) {
188
+ reject(error);
189
+ }
190
+ };
174
191
  tx.onerror = () => reject(tx.error);
175
192
  tx.onabort = () => reject(tx.error);
176
193
  });
@@ -156,7 +156,18 @@ function useReviewDrafts(session, revision, initial, request) {
156
156
  }
157
157
  };
158
158
  }
159
+ async function encodePendingPhoto(value) {
160
+ const { file, ...details } = value;
161
+ return { ...details, file: { bytes: await file.arrayBuffer(), name: file.name, type: file.type, lastModified: file.lastModified } };
162
+ }
163
+ function decodePendingPhoto(value) {
164
+ if (!value) return void 0;
165
+ if (value.file instanceof File) return value;
166
+ const file = value.file;
167
+ return { ...value, file: new File([file.bytes], file.name, { type: file.type, lastModified: file.lastModified }) };
168
+ }
159
169
  async function stored(key, value) {
170
+ const encoded = value ? await encodePendingPhoto(value) : value;
160
171
  const db = await new Promise((resolve, reject) => {
161
172
  const request = indexedDB.open("story-review-pending-media", 1);
162
173
  request.onupgradeneeded = () => request.result.createObjectStore("photos");
@@ -167,8 +178,14 @@ async function stored(key, value) {
167
178
  return await new Promise((resolve, reject) => {
168
179
  const tx = db.transaction("photos", value === void 0 ? "readonly" : "readwrite");
169
180
  const store = tx.objectStore("photos");
170
- const request = value === void 0 ? store.get(key) : value === null ? store.delete(key) : store.put(value, key);
171
- tx.oncomplete = () => resolve(value === void 0 ? request.result : void 0);
181
+ const request = value === void 0 ? store.get(key) : value === null ? store.delete(key) : store.put(encoded, key);
182
+ tx.oncomplete = () => {
183
+ try {
184
+ resolve(value === void 0 ? decodePendingPhoto(request.result) : void 0);
185
+ } catch (error) {
186
+ reject(error);
187
+ }
188
+ };
172
189
  tx.onerror = () => reject(tx.error);
173
190
  tx.onabort = () => reject(tx.error);
174
191
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/news-publication",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Shared server framework for ScaleMule local news publications. Walnut Creek Times is the broadsheet default; each paper supplies its own identity and feature flags.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",