29 lines
971 B
JavaScript
29 lines
971 B
JavaScript
(function(root, factory) {
|
|
const api = factory();
|
|
if (typeof module === 'object' && module.exports) module.exports = api;
|
|
else root.sharedImageCapture = api;
|
|
})(typeof self !== 'undefined' ? self : this, function() {
|
|
'use strict';
|
|
|
|
const RECORD_ID = 'shared-image';
|
|
const TYPES = new Set(['image/png', 'image/jpeg', 'image/webp']);
|
|
|
|
async function consume({marker, store, restore, status = () => {}}) {
|
|
if (!marker) return false;
|
|
if (marker !== 'image') {
|
|
status('Share one PNG, JPEG, or WebP screenshot.');
|
|
return false;
|
|
}
|
|
const value = await store?.get(RECORD_ID);
|
|
if (!value?.blob || !value.filename || !TYPES.has(String(value.contentType || ''))) {
|
|
status('The shared screenshot is unavailable. Share it again.');
|
|
return false;
|
|
}
|
|
restore(value);
|
|
await store.delete(RECORD_ID);
|
|
status('Shared screenshot ready to file with this issue.');
|
|
return true;
|
|
}
|
|
|
|
return {consume, RECORD_ID};
|
|
}); |