diff --git a/frontend/src/components/SearchBox.vue b/frontend/src/components/SearchBox.vue index ab15e36..c914eab 100644 --- a/frontend/src/components/SearchBox.vue +++ b/frontend/src/components/SearchBox.vue @@ -32,8 +32,8 @@ export default { } }, mounted() { - console.log(this.$route) - console.log(this.$route.params.query) + //console.log(this.$route) + //console.log(this.$route.params.query) this.query = decodeURIComponent(this.$route.params.query || encodeURIComponent("")); } } diff --git a/frontend/src/dns.js b/frontend/src/dns.js index 70f2ba5..52cfe06 100644 --- a/frontend/src/dns.js +++ b/frontend/src/dns.js @@ -19,6 +19,7 @@ class FallBackResolver { endpoints: this._servers, } ) + if(result.answers.length === 0) throw new Error('No answer'); const first = result.answers[0]; this._cache[key] = {time: Date.now(), ...first}; // TODO hadle multiple answers localStorage.setItem('dns-cache', JSON.stringify(this._cache)); diff --git a/frontend/src/store.js b/frontend/src/store.js index 6bfdac9..9ae3ef6 100644 --- a/frontend/src/store.js +++ b/frontend/src/store.js @@ -67,6 +67,11 @@ export default createStore({ } else { } router.push('/'); + /*if (this.$route.query.redirect) { + router.push({path: this.$route.query.redirect}); + } else { + router.push({path: '/'}); + }*/ } } }, @@ -109,10 +114,10 @@ export default createStore({ if (state.unreachable_neighbors.queryUnreachable(host)) { throw new Error('unreachable neighbor') } - if(!state.user || !state.keypair) { + if (!state.user || !state.keypair) { throw new Error('no user or keypair') } - const url = host + target + const url = "http://" + host + target // TODO https const signature = nacl.crypto_sign_detached(nacl.encode_utf8(url), state.keypair.signSk) const auth = 'Signature ' + state.user + ':' + nacl.to_hex(signature) return await fetch(url, { @@ -124,13 +129,14 @@ export default createStore({ ).then(response => response.json()) }, async apiFederatedPost({state}, {host, target, data}) { + console.log('apiFederatedPost', host, target, data) if (state.unreachable_neighbors.queryUnreachable(host)) { throw new Error('unreachable neighbor') } - if(!state.user || !state.keypair) { + if (!state.user || !state.keypair) { throw new Error('no user or keypair') } - const url = host + target + const url = "http://" + host + target // TODO https const json = JSON.stringify(data) const signature = nacl.crypto_sign_detached(nacl.encode_utf8(url + json), state.keypair.signSk) const auth = 'Signature ' + state.user + ':' + nacl.to_hex(signature) @@ -163,6 +169,20 @@ export default createStore({ credentials: 'omit', body: JSON.stringify(data) }).then(response => response.json()) + }, + async requestFriend({state, dispatch}, {username}) { + console.log('requesting friend ' + username) + if(username in state.friends) { + return true; + } + const server = await dispatch('getFriendServer', {username}) + const data = await dispatch('apiFederatedPost', { + host: server[0], + target: '/api/friendrequests/', + data: {befriender: state.user, befriendee: username, befriender_key: nacl.to_hex(state.keypair.signPk)} + }) + console.log(data) + return true; } }, getters: { diff --git a/frontend/src/views/Friends.vue b/frontend/src/views/Friends.vue index f70f4ae..6bd72a7 100644 --- a/frontend/src/views/Friends.vue +++ b/frontend/src/views/Friends.vue @@ -15,29 +15,45 @@ Name Server - Actions + + + + Refresh + + + + Add Friend + + + + + + + + + + {{ friend.name }} {{ friend.server.join(', ') }} - + + Edit - + + Delete -
- - Add -
@@ -59,6 +75,8 @@ export default { data() { return { friends: {}, + show_newfriend: false, + newfriend: "" } }, computed: { @@ -75,7 +93,7 @@ export default { } }, methods: { - ...mapActions(['getFriends', "getFriendServer"]), + ...mapActions(['getFriends', "getFriendServer", "requestFriend"]), fetchFriends() { this.getFriends().then((friends) => { friends.map((friend) => { @@ -84,6 +102,18 @@ export default { }) }) }) + }, + showNewFriend() { + this.show_newfriend = true + }, + tryRequestFriend() { + this.requestFriend({username: this.newfriend}).then((ok) => { + if (ok) { + this.show_newfriend = false + this.newfriend = "" + this.fetchFriends() + } + }).catch(() => {}) } }, mounted() { diff --git a/frontend/src/views/Inventory.vue b/frontend/src/views/Inventory.vue index 0ef8a04..aaeeed0 100644 --- a/frontend/src/views/Inventory.vue +++ b/frontend/src/views/Inventory.vue @@ -73,7 +73,7 @@ export default { try { const servers = await this.getFriends().then(friends => friends.map(friend => this.getFriendServer({username: friend}))) const urls = servers.map(server => server.then(s => { - return {host: `http://${s}`, target: "/api/inventory_items/"} + return {host: s, target: "/api/inventory_items/"} })) urls.map(url => url.then(u => this.apiFederatedGet(u).then(items => { this.setInventoryItems({url: u.domain, items}) diff --git a/frontend/src/views/InventoryNew.vue b/frontend/src/views/InventoryNew.vue index 13a3f92..2cfb5e7 100644 --- a/frontend/src/views/InventoryNew.vue +++ b/frontend/src/views/InventoryNew.vue @@ -4,37 +4,36 @@
-
Inventory
+
Create New Item
- - - - - - - - - - - - - - - - - -
ItemQuantityOwnerActions
{{ item.name }}{{ item.quantity }}{{ item.owner }} - - - - - - -
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
- - Add +
@@ -46,13 +45,29 @@