stash
This commit is contained in:
parent
c8fdfbb09a
commit
72b8bbab76
4 changed files with 34 additions and 15 deletions
|
@ -1,11 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<img :src="image_data" :alt="owner + '/' + src"/>
|
||||||
<!--img src=""-->
|
|
||||||
data:{{ image_data }}<br>
|
|
||||||
owner:{{ owner }}<br>
|
|
||||||
src:{{ src }}<br>
|
|
||||||
servers:{{ servers }}
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -46,7 +40,9 @@ export default {
|
||||||
async mounted() {
|
async mounted() {
|
||||||
try {
|
try {
|
||||||
this.servers = await this.getFriendServers({username: this.owner});
|
this.servers = await this.getFriendServers({username: this.owner});
|
||||||
this.image_data = await this.servers.get(this.signAuth, this.src);
|
const response = await this.servers.getRaw(this.signAuth, this.src);
|
||||||
|
const mime_type = response.headers.get("content-type");
|
||||||
|
this.image_data = "data:" + mime_type + ";base64," + btoa(String.fromCharCode(...new Uint8Array(await response.arrayBuffer())));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,6 +167,34 @@ class ServerSet {
|
||||||
}
|
}
|
||||||
throw new Error('all servers failed')
|
throw new Error('all servers failed')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getRaw(auth, target) {
|
||||||
|
if (!auth || typeof auth.buildAuthHeader !== 'function') {
|
||||||
|
throw new Error('no auth')
|
||||||
|
}
|
||||||
|
for (const server of this.servers) {
|
||||||
|
try {
|
||||||
|
if (this.unreachable_neighbors.queryUnreachable(server)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const url = "https://" + server + target // TODO https
|
||||||
|
return await fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
...auth.buildAuthHeader(url)
|
||||||
|
},
|
||||||
|
credentials: 'omit'
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('get from server failed', server, err)
|
||||||
|
this.unreachable_neighbors.unreachable(server)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('get from server failed', server, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error('all servers failed')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServerSetUnion {
|
class ServerSetUnion {
|
||||||
|
|
|
@ -34,14 +34,9 @@
|
||||||
</div-->
|
</div-->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="image" class="form-label">Image</label>
|
<label for="image" class="form-label">Image</label>
|
||||||
<div>
|
|
||||||
<img v-for="file in files" :key="file.id" :alt="file.name"
|
|
||||||
:src="'https://toolshed.j3d1.de'+file.name" class="img-thumbnail border-info">
|
|
||||||
<!-- TODO replace dirty hack with proper solution -->
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<authenticated-image v-for="file in files" :key="file.id" :src="file.name"
|
<authenticated-image v-for="file in files" :key="file.id" :src="file.name"
|
||||||
:owner="file.owner"></authenticated-image>
|
:owner="file.owner" class="img-thumbnail border-info"></authenticated-image>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default defineConfig({
|
||||||
'Content-Security-Policy': 'default-src \'self\';'
|
'Content-Security-Policy': 'default-src \'self\';'
|
||||||
+ ' script-src \'self\' \'wasm-unsafe-eval\';'
|
+ ' script-src \'self\' \'wasm-unsafe-eval\';'
|
||||||
+ ' style-src \'self\' \'unsafe-inline\';'
|
+ ' style-src \'self\' \'unsafe-inline\';'
|
||||||
+ ' img-src \'self\' * data:; '
|
+ ' img-src \'self\' https://* data:;'
|
||||||
+ ' connect-src * data:', // TODO: change * to https://* for production
|
+ ' connect-src * data:', // TODO: change * to https://* for production
|
||||||
},
|
},
|
||||||
/*https: {
|
/*https: {
|
||||||
|
|
Loading…
Reference in a new issue