This commit is contained in:
j3d1 2023-05-28 21:05:22 +02:00
parent 02e41214d2
commit 7e8f984ee2
7 changed files with 15 additions and 12 deletions

View file

@ -11,6 +11,7 @@
"bootstrap-icons-vue": "^1.10.3", "bootstrap-icons-vue": "^1.10.3",
"dns-query": "^0.11.2", "dns-query": "^0.11.2",
"js-nacl": "^1.4.0", "js-nacl": "^1.4.0",
"moment": "^2.29.4",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.1.6", "vue-router": "^4.1.6",
"vuex": "^4.1.0" "vuex": "^4.1.0"

File diff suppressed because one or more lines are too long

View file

@ -48,6 +48,7 @@
<script> <script>
import {mapGetters, mapMutations} from 'vuex'; import {mapGetters, mapMutations} from 'vuex';
import * as BIcons from "bootstrap-icons-vue"; import * as BIcons from "bootstrap-icons-vue";
import moment from 'moment';
export default { export default {
name: 'Notifications', name: 'Notifications',

View file

@ -28,7 +28,7 @@ class ServerSet {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...auth.buildAuthHeader(url) ...auth.buildAuthHeader(url, data)
}, },
credentials: 'omit', credentials: 'omit',
body: JSON.stringify(data) body: JSON.stringify(data)
@ -55,7 +55,7 @@ class ServerSet {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...auth.buildAuthHeader(url) ...auth.buildAuthHeader(url, data)
}, },
credentials: 'omit', credentials: 'omit',
body: JSON.stringify(data) body: JSON.stringify(data)
@ -132,7 +132,7 @@ class ServerSet {
method: 'PUT', method: 'PUT',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...auth.buildAuthHeader(url) ...auth.buildAuthHeader(url, data)
}, },
credentials: 'omit', credentials: 'omit',
body: JSON.stringify(data) body: JSON.stringify(data)
@ -167,6 +167,7 @@ function createSignAuth(username, signKey) {
return new authMethod(({signKey, username}, {url, data}) => { return new authMethod(({signKey, username}, {url, data}) => {
const json = JSON.stringify(data) const json = JSON.stringify(data)
const signature = nacl.crypto_sign_detached(nacl.encode_utf8(url + (data ? json : "")), signKey) const signature = nacl.crypto_sign_detached(nacl.encode_utf8(url + (data ? json : "")), signKey)
console.log('sign', nacl.to_hex(signature), url, json)
return {'Authorization': 'Signature ' + username + ':' + nacl.to_hex(signature)} return {'Authorization': 'Signature ' + username + ':' + nacl.to_hex(signature)}
}, context) }, context)
} }

View file

@ -4,7 +4,6 @@ import { BootstrapIconsPlugin } from 'bootstrap-icons-vue';
import App from './App.vue' import App from './App.vue'
import './assets/css/toolshed.css' import './assets/css/toolshed.css'
import './assets/js/app.js'
import router from './router' import router from './router'
import store from './store'; import store from './store';

View file

@ -175,15 +175,16 @@ export default createStore({
const servers = await dispatch('getAllFriendsServers') const servers = await dispatch('getAllFriendsServers')
return await servers.get(getters.signAuth, '/api/inventory/search/?q=' + query) return await servers.get(getters.signAuth, '/api/inventory/search/?q=' + query)
}, },
async createInventoryItem({state, dispatch, getters}, {item}) { async createInventoryItem({state, dispatch, getters}, item) {
const servers = await dispatch('getHomeServers') const servers = await dispatch('getHomeServers')
return await servers.post(getters.signAuth, '/api/inventory_items/', item) const data = {...item, owned_amount: 1, availability_policy: 'friends', category: 'other'}
return await servers.post(getters.signAuth, '/api/inventory_items/', data)
}, },
async updateInventoryItem({state, dispatch, getters}, {item}) { async updateInventoryItem({state, dispatch, getters}, item) {
const servers = await dispatch('getHomeServers') const servers = await dispatch('getHomeServers')
return await servers.patch(getters.signAuth, '/api/inventory_items/' + item.id + '/', item) return await servers.patch(getters.signAuth, '/api/inventory_items/' + item.id + '/', item)
}, },
async deleteInventoryItem({state, dispatch, getters}, {item}) { async deleteInventoryItem({state, dispatch, getters}, item) {
const servers = await dispatch('getHomeServers') const servers = await dispatch('getHomeServers')
return await servers.delete(getters.signAuth, '/api/inventory_items/' + item.id + '/') return await servers.delete(getters.signAuth, '/api/inventory_items/' + item.id + '/')
}, },

View file

@ -3,7 +3,6 @@ import {fileURLToPath, URL} from 'node:url'
import {defineConfig} from 'vite' import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
resolve: { resolve: {
@ -20,7 +19,10 @@ export default defineConfig({
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token, Authorization, Accept,charset,boundary,Content-Length', 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token, Authorization, Accept,charset,boundary,Content-Length',
'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Credentials': 'true',
'Content-Security-Policy': 'default-src \'self\' \'unsafe-inline\' \'unsafe-eval\' data: \'self\' connect-src *', // change to https://* for production 'Content-Security-Policy': 'default-src \'self\';'
+ ' script-src \'self\' \'wasm-unsafe-eval\';'
+ ' style-src \'self\' \'unsafe-inline\';'
+ ' connect-src * data:', // TODO: change * to https://* for production
}, },
proxy: { proxy: {
'^/api/': { '^/api/': {