Skip to content

Commit

Permalink
Bump version v1.2
Browse files Browse the repository at this point in the history
- fix some bugs (list files pagination & not catching some errors)
- disable some buttons while "working"
- add ability to lookup a specific app
  • Loading branch information
MichaelFedora committed Jun 23, 2019
1 parent b72f0ae commit 1b2346f
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><title>Mercurius</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="shortcut icon" href="favicon.ico"><link rel="icon" href="assets/images/logo-192.png"><link rel="apple-touch-icon" href="assets/images/logo-180.png"><link href="vendors~mercurius.css" rel="stylesheet"><link href="mercurius.css" rel="stylesheet"></head><body><div id="app"></div><script src="vendors~mercurius.e31d4f49797968e3c856.js"></script><script src="mercurius.70110183055da3ff3e8c.js"></script></body></html>
<!doctype html><html lang="en"><head><title>Mercurius</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="shortcut icon" href="favicon.ico"><link rel="icon" href="assets/images/logo-192.png"><link rel="apple-touch-icon" href="assets/images/logo-180.png"><link href="vendors~mercurius.css" rel="stylesheet"><link href="mercurius.css" rel="stylesheet"></head><body><div id="app"></div><script src="vendors~mercurius.6189cf2c834f9de0dff9.js"></script><script src="mercurius.0a86cfccab5d4b5f63e3.js"></script></body></html>
1 change: 1 addition & 0 deletions docs/mercurius.0a86cfccab5d4b5f63e3.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/mercurius.70110183055da3ff3e8c.js

This file was deleted.

Large diffs are not rendered by default.

195 changes: 155 additions & 40 deletions src/components/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { makeV1GaiaAuthToken } from 'util/token-util';
import JSZip from 'jszip';
import FileSaver from 'file-saver';
import defaultApps from '../../data/apps-defaults';
import AppsNode from 'data/apps-node';

const CIPHER_OBJ_KEYS = ['iv', 'ephemeralPK', 'cipherText', 'mac', 'wasString'];
const MORE_APPS = [
Expand Down Expand Up @@ -140,10 +141,8 @@ export default (Vue as VVue).component('mercurius-home', {
let page;

do {
let url = gaiaHubConfig.server + '/list-files/' + gaiaHubConfig.address;
if(page)
url += '?page=' + page;
const res = await Axios.post(url, null, { headers });
const url = gaiaHubConfig.server + '/list-files/' + gaiaHubConfig.address;
const res = await Axios.post(url, { page }, { headers });

if(res.data.page)
page = res.data.page;
Expand All @@ -155,6 +154,27 @@ export default (Vue as VVue).component('mercurius-home', {

return bigList;
},
makeApp(skeleton: { website: string, name?: string }, appsNode?: AppsNode) {
if(!skeleton.name)
skeleton.name = skeleton.website.replace(/https?:\/\//, '');

appsNode = appsNode || this.masterKeychain.getIdentityOwnerAddressNode(0).appsNode;
const node = appsNode.getAppNode(skeleton.website);

const address = node.getAddress();

if(this.annotations[address])
return null;

Vue.set(this.annotations, address, skeleton.name);

return {
name: skeleton.name,
website: skeleton.website,
address,
privateKey: node.privateKey.toString('hex')
};
},
async getApps() {
const newApps: { name: string, website: string, address: string, privateKey: string }[] = [];

Expand All @@ -175,14 +195,16 @@ export default (Vue as VVue).component('mercurius-home', {
}

const appsNode = this.masterKeychain.getIdentityOwnerAddressNode(0).appsNode;
// const res = await Axios.get('https://api.app.co/api/app-mining-apps'); // other one is WAY too large
let res;
try {
res = await Axios.get('https://api.app.co/api/apps'); // other one is WAY too large
// res = await Axios.get('https://api.app.co/api/app-mining-apps'); // good for testing / qc
res = await Axios.get('https://api.app.co/api/apps'); // quite large, but "needed" for prod
} catch(e) {
this.handleError(e);
this.workingOn = '';
res = { data: { apps: [] } };
}

const apps: { name: string, website: string }[] = res.data.apps.filter(a =>
(a.storageNetworkID === 0 || a.storageNetwork === 'Gaia') &&
(a.authenticationID === 0 || a.authentication === 'Blockstack'))
Expand All @@ -191,24 +213,36 @@ export default (Vue as VVue).component('mercurius-home', {
.concat(MORE_APPS);

for(const app of apps) {
const node = appsNode.getAppNode(app.website);

if(this.annotations[node.getAddress()])
continue;

Vue.set(this.annotations, node.getAddress(), app.name);
const a = this.makeApp(app, appsNode);
if(a)
newApps.push(a);
}

newApps.push({
name: app.name,
website: app.website,
address: node.getAddress(),
privateKey: node.privateKey.toString('hex')
});
this.apps = newApps;
this.$store.commit('setAppCache', newApps);

this.apps = newApps;
this.$store.commit('setAppCache', newApps);
this.workingOn = '';
},
async listFilesSingle(app: { address: string, privateKey: string, name: string }, hubInfo: {
challenge_text: string,
latest_auth_version: string,
read_url_prefix: string
}, server: string) {
try {
const gc: GaiaHubConfig = { // optimized so we don't spam hub_info as well as /list-files
url_prefix: hubInfo.read_url_prefix,
address: app.address,
token: makeV1GaiaAuthToken(hubInfo, app.privateKey, server),
server
};
const list = await this.listBucketFiles(gc);

this.workingOn = '';
if(list.length)
return list.map(a => app.address + '/' + a);
else return [];
} catch(e) {
console.error('Error listing files for app ' + app.name + '!');
console.error(e);
}
},
async listFiles() {
Expand All @@ -226,25 +260,12 @@ export default (Vue as VVue).component('mercurius-home', {
this.bigList = bigList;

for(let i = 0, app = this.apps[i]; i < this.apps.length; i++, app = this.apps[i]) {
try {
this.workingOn = 'Looking up ' + app.name + '\'s app bucket (' + i + '/' + this.apps.length + ')';

const gc: GaiaHubConfig = { // optimized so we don't spam hub_info as well as /list-files
url_prefix: hubInfo.read_url_prefix,
address: app.address,
token: makeV1GaiaAuthToken(hubInfo, app.privateKey, server),
server
};
const list = await this.listBucketFiles(gc);

if(list.length)
bigList.push(...list.map(a => app.address + '/' + a));
this.progress += 1 / (this.apps.length + 1);
await new Promise(resolve => setTimeout(resolve, 500));
} catch(e) {
console.error('Error listing files for app ' + app.name + '!');
console.error(e);
}
this.workingOn = 'Looking up ' + app.name + '\'s app bucket (' + i + '/' + this.apps.length + ')';
const list = await this.listFilesSingle(app, hubInfo, server);
if(list)
bigList.push(...list);
this.progress += 1 / (this.apps.length + 1);
await new Promise(resolve => setTimeout(resolve, 500));
}

this.workingOn = 'Getting profile app bucket';
Expand Down Expand Up @@ -409,6 +430,100 @@ export default (Vue as VVue).component('mercurius-home', {
this.workingOn = '';
this.working = false;
},
lookupApp() {
if(this.working)
return;
this.working = true;
this.workingOn = 'Looking up app...';

this.$dialog.prompt({
message: 'App domain:',
inputAttrs: {
type: 'url',
placeholder: 'https://helloblockstack.com/'
},
onConfirm: async value => {
if(!value.startsWith('http'))
value = 'https://' + value;

let app: {
website: string;
name: string;
address: string;
privateKey: string;
};
try {
app = this.makeApp({ website: value });
} catch(e) {
this.$dialog.alert({
type: 'is-danger',
message: 'Could not create an app from website "' + value + '"!'
});
this.working = false;
this.workingOn = '';
return;
}
if(!app) {
this.$dialog.alert({
type: 'is-info',
message: 'App already listed!'
});
this.working = false;
this.workingOn = '';
return;
}
if(app && !this.apps.find(a => a.address === app.address))
this.apps.push(app);
let hubInfo;
try {
const res = await Axios.get(this.activeGaia.server + '/hub_info');
hubInfo = res.data;
} catch(e) {
this.$dialog.alert({
type: 'is-danger',
message: 'Could not get hub info from active gaia hub "' + this.activeGaia.server + '"!'
});
this.working = false;
this.workingOn = '';
return;
}
let files: string[];
try {
files = await this.listFilesSingle(app, hubInfo, this.activeGaia.server);
} catch(e) {
this.$dialog.alert({
type: 'is-danger',
message: 'Could not create list files from address "' + app.address + '"!'
});
this.working = false;
this.workingOn = '';
return;
}
const filteredFiles = files.filter(a => !this.bigList.includes(a));
if(filteredFiles.length) {
this.bigList = [ ...this.bigList, ...files.filter(a => !this.bigList.includes(a)) ].sort();
this.$store.commit('setBigListCache', this.bigList);
} else if(files.length) {
this.$dialog.alert({
type: 'is-info',
message: 'No *new* files from "' + app.name + '" to be listed!'
});
} else {
this.$dialog.alert({
type: 'is-info',
message: 'No files from "' + app.name + '" to be listed!'
});
}

this.working = false;
this.workingOn = '';
},
onCancel: () => {
this.working = false;
this.workingOn = '';
}
});
},
drawStart(event: MouseEvent) {
if(event.button !== 0)
return;
Expand Down
5 changes: 3 additions & 2 deletions src/components/home/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
</template>
</div>
<div id='buttons'>
<button class='button is-small is-white' @click='refresh()' title='Refresh'><b-icon icon='refresh'></b-icon></button>
<button class='button is-small is-white' :disabled='!anyActive' @click='download()' title='Download'><b-icon icon='download'></b-icon></button>
<button class='button is-small is-white' @click='refresh()' :disabled='working' title='Refresh'><b-icon icon='refresh'></b-icon></button>
<button class='button is-small is-white' :disabled='!anyActive || working' @click='download()' title='Download'><b-icon icon='download'></b-icon></button>
<button class='button is-small is-white' :disabled='working' @click='lookupApp()' title='Lookup App'><b-icon icon='cloud-search'></b-icon></button>
<a class='button is-small is-white' :href='"data:application/json," + JSON.stringify(index)' target='_blank' rel='noopener noreferrer' title='Migration Index'><b-icon icon='script-text'></b-icon></a>
</div>
</div>
Expand Down

0 comments on commit 1b2346f

Please sign in to comment.