Cleanup of EEPROM init code.
This commit is contained in:
parent
a08793d992
commit
1dcddffc03
4 changed files with 83 additions and 64 deletions
|
@ -1,35 +1,37 @@
|
||||||
#include utility.js
|
#include eeprom/script.jsx
|
||||||
|
|
||||||
const MamiEEPROM = function() {
|
const MamiEEPROM = function(baseUrl, getAuthLine) {
|
||||||
//
|
if(typeof baseUrl !== 'string')
|
||||||
};
|
throw 'baseUrl must be a string';
|
||||||
MamiEEPROM.init = (function() {
|
if(typeof getAuthLine !== 'function')
|
||||||
let initialised = false;
|
throw 'getAuthLine must be a function';
|
||||||
|
|
||||||
return () => {
|
// when the pools rewrite happen, retrieve this from futami common
|
||||||
return new Promise((resolve, reject) => {
|
const appId = '1';
|
||||||
if(initialised)
|
let client;
|
||||||
return new Promise(resolve => resolve());
|
|
||||||
|
|
||||||
const script = $e({
|
return {
|
||||||
tag: 'script',
|
get client() {
|
||||||
attrs: {
|
return client;
|
||||||
charset: 'utf-8',
|
|
||||||
type: 'text/javascript',
|
|
||||||
src: `${futami.get('eeprom2')}/scripts/eepromv1a.js`,
|
|
||||||
onload: () => {
|
|
||||||
initialised = true;
|
|
||||||
resolve();
|
|
||||||
},
|
},
|
||||||
onerror: () => {
|
|
||||||
$r(script);
|
|
||||||
console.error('Failed to load EEPROM script!');
|
|
||||||
reject();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
document.body.appendChild(script);
|
init: async () => {
|
||||||
});
|
await MamiEEPROMLoadScript(baseUrl);
|
||||||
|
client = new EEPROM(appId, baseUrl, getAuthLine);
|
||||||
|
},
|
||||||
|
|
||||||
|
create: fileInput => {
|
||||||
|
if(client === undefined)
|
||||||
|
throw 'eeprom client is uninitialised';
|
||||||
|
|
||||||
|
return client.create(fileInput);
|
||||||
|
},
|
||||||
|
|
||||||
|
delete: async fileInfo => {
|
||||||
|
if(client === undefined)
|
||||||
|
throw 'eeprom client is uninitialised';
|
||||||
|
|
||||||
|
await client.delete(fileInfo);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
})();
|
};
|
||||||
|
|
19
src/mami.js/eeprom/script.jsx
Normal file
19
src/mami.js/eeprom/script.jsx
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include utility.js
|
||||||
|
|
||||||
|
const MamiEEPROMLoadScript = baseUrl => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if(typeof baseUrl !== 'string')
|
||||||
|
throw 'baseUrl must be a string';
|
||||||
|
|
||||||
|
const src = `${baseUrl}/scripts/eepromv1a.js`;
|
||||||
|
|
||||||
|
let script = $q(`script[src="${src}"]`);
|
||||||
|
if(script instanceof Element) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
script = <script src={src} onload={() => { resolve(); }} onerror={() => { $r(script); reject(); }} />;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
});
|
||||||
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
window.Umi = { UI: {} };
|
||||||
|
|
||||||
#include animate.js
|
#include animate.js
|
||||||
#include common.js
|
#include common.js
|
||||||
|
@ -422,14 +422,12 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
||||||
Umi.UI.InputMenus.Add('emotes', 'Emoticons');
|
Umi.UI.InputMenus.Add('emotes', 'Emoticons');
|
||||||
|
|
||||||
let doUpload;
|
let doUpload;
|
||||||
MamiEEPROM.init()
|
ctx.eeprom = new MamiEEPROM(futami.get('eeprom2'), MamiMisuzuAuth.getLine);
|
||||||
|
ctx.eeprom.init()
|
||||||
.catch(ex => {
|
.catch(ex => {
|
||||||
console.log('Failed to initialise EEPROM.', ex);
|
console.log('Failed to initialise EEPROM.', ex);
|
||||||
ctx.eeprom = undefined;
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
ctx.eeprom = new EEPROM('1', futami.get('eeprom2'), MamiMisuzuAuth.getLine);
|
|
||||||
|
|
||||||
Umi.UI.Menus.Add('uploads', 'Upload History', !FUTAMI_DEBUG);
|
Umi.UI.Menus.Add('uploads', 'Upload History', !FUTAMI_DEBUG);
|
||||||
|
|
||||||
doUpload = async file => {
|
doUpload = async file => {
|
||||||
|
|
|
@ -43,11 +43,12 @@ Umi.UI.Menus = (function() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Add: function(baseId, title, initiallyHidden) {
|
Add: function(baseId, title, initiallyHidden) {
|
||||||
if(ids.indexOf(baseId) < 0) {
|
if(ids.includes(baseId))
|
||||||
|
return;
|
||||||
ids.push(baseId);
|
ids.push(baseId);
|
||||||
|
|
||||||
const menuClass = [sidebarMenu, sidebarMenu + '--' + baseId];
|
const menuClass = [sidebarMenu, `${sidebarMenu}--${baseId}`];
|
||||||
const iconClass = [sidebarSelectorMode, sidebarSelectorMode + '--' + baseId];
|
const iconClass = [sidebarSelectorMode, `${sidebarSelectorMode}--${baseId}`];
|
||||||
|
|
||||||
const menus = $i('umi-menus');
|
const menus = $i('umi-menus');
|
||||||
const icons = $i('umi-menu-icons');
|
const icons = $i('umi-menu-icons');
|
||||||
|
@ -64,7 +65,7 @@ Umi.UI.Menus = (function() {
|
||||||
|
|
||||||
icons.appendChild($e({
|
icons.appendChild($e({
|
||||||
attrs: {
|
attrs: {
|
||||||
id: 'umi-menu-icons-' + baseId,
|
id: `umi-menu-icons-${baseId}`,
|
||||||
classList: iconClass,
|
classList: iconClass,
|
||||||
title: title,
|
title: title,
|
||||||
onclick: function() {
|
onclick: function() {
|
||||||
|
@ -73,8 +74,7 @@ Umi.UI.Menus = (function() {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
menus.appendChild($e({ attrs: { 'class': menuClass, id: 'umi-menus-' + baseId } }));
|
menus.appendChild($e({ attrs: { 'class': menuClass, id: `umi-menus-${baseId}` } }));
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Get: function(baseId, icon) {
|
Get: function(baseId, icon) {
|
||||||
const id = (icon ? 'umi-menu-icons' : 'umi-menus') + '-' + baseId;
|
const id = (icon ? 'umi-menu-icons' : 'umi-menus') + '-' + baseId;
|
||||||
|
|
Loading…
Reference in a new issue