This commit is contained in:
j3d1 2023-11-01 03:17:25 +01:00
parent c8fdfbb09a
commit 72b8bbab76
4 changed files with 34 additions and 15 deletions

View file

@ -1,11 +1,5 @@
<template>
<div>
<!--img src=""-->
data:{{ image_data }}<br>
owner:{{ owner }}<br>
src:{{ src }}<br>
servers:{{ servers }}
</div>
<img :src="image_data" :alt="owner + '/' + src"/>
</template>
<style scoped>
@ -46,7 +40,9 @@ export default {
async mounted() {
try {
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) {
console.log(e);
}

View file

@ -167,6 +167,34 @@ class ServerSet {
}
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 {

View file

@ -34,14 +34,9 @@
</div-->
<div class="mb-3">
<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>
<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>

View file

@ -23,7 +23,7 @@ export default defineConfig({
'Content-Security-Policy': 'default-src \'self\';'
+ ' script-src \'self\' \'wasm-unsafe-eval\';'
+ ' style-src \'self\' \'unsafe-inline\';'
+ ' img-src \'self\' * data:; '
+ ' img-src \'self\' https://* data:;'
+ ' connect-src * data:', // TODO: change * to https://* for production
},
/*https: {