2021-12-23 13:29:04 -08:00
|
|
|
<template>
|
2022-01-22 02:02:27 -08:00
|
|
|
<span>
|
2021-12-23 13:29:04 -08:00
|
|
|
<div v-if="isLoading">
|
|
|
|
Loading binary data...
|
|
|
|
</div>
|
|
|
|
<div v-else-if="error">
|
|
|
|
Error loading binary data
|
|
|
|
</div>
|
2022-01-22 02:02:27 -08:00
|
|
|
<span v-else>
|
2022-11-24 07:54:43 -08:00
|
|
|
<video v-if="binaryData.fileType === 'video'" controls autoplay>
|
2021-12-23 13:29:04 -08:00
|
|
|
<source :src="embedSource" :type="binaryData.mimeType">
|
|
|
|
{{ $locale.baseText('binaryDataDisplay.yourBrowserDoesNotSupport') }}
|
|
|
|
</video>
|
2022-12-11 05:10:54 -08:00
|
|
|
<vue-json-pretty
|
|
|
|
v-else-if="binaryData.fileType === 'json'"
|
|
|
|
:data="jsonData"
|
|
|
|
:deep="3"
|
|
|
|
:showLength="true"
|
|
|
|
/>
|
2022-01-22 02:02:27 -08:00
|
|
|
<embed v-else :src="embedSource" class="binary-data" :class="embedClass()"/>
|
|
|
|
</span>
|
|
|
|
</span>
|
2021-12-23 13:29:04 -08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { restApi } from '@/mixins/restApi';
|
2022-12-11 05:10:54 -08:00
|
|
|
import { IBinaryData, jsonParse } from 'n8n-workflow';
|
|
|
|
import type { PropType } from 'vue';
|
|
|
|
import VueJsonPretty from 'vue-json-pretty';
|
2021-12-23 13:29:04 -08:00
|
|
|
|
|
|
|
export default mixins(
|
|
|
|
restApi,
|
|
|
|
)
|
|
|
|
.extend({
|
|
|
|
name: 'BinaryDataDisplayEmbed',
|
2022-12-11 05:10:54 -08:00
|
|
|
components: {
|
|
|
|
VueJsonPretty,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
binaryData: {
|
|
|
|
type: Object as PropType<IBinaryData>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2021-12-23 13:29:04 -08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoading: true,
|
|
|
|
embedSource: '',
|
|
|
|
error: false,
|
2022-12-11 05:10:54 -08:00
|
|
|
jsonData: '',
|
2021-12-23 13:29:04 -08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
async mounted() {
|
2022-11-24 07:54:43 -08:00
|
|
|
const id = this.binaryData?.id;
|
2022-12-11 05:10:54 -08:00
|
|
|
const isJSONData = this.binaryData.fileType === 'json';
|
|
|
|
|
2022-11-24 07:54:43 -08:00
|
|
|
if(!id) {
|
2022-12-11 05:10:54 -08:00
|
|
|
if (isJSONData) {
|
|
|
|
this.jsonData = jsonParse(atob(this.binaryData.data));
|
|
|
|
} else {
|
|
|
|
this.embedSource = 'data:' + this.binaryData.mimeType + ';base64,' + this.binaryData.data;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const binaryUrl = this.restApi().getBinaryUrl(id);
|
|
|
|
if (isJSONData) {
|
|
|
|
this.jsonData = await (await fetch(binaryUrl)).json();
|
|
|
|
} else {
|
|
|
|
this.embedSource = binaryUrl;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.error = true;
|
|
|
|
}
|
2021-12-23 13:29:04 -08:00
|
|
|
}
|
|
|
|
|
2022-12-11 05:10:54 -08:00
|
|
|
this.isLoading = false;
|
2021-12-23 13:29:04 -08:00
|
|
|
},
|
|
|
|
methods: {
|
2022-01-22 02:02:27 -08:00
|
|
|
embedClass(): string[] {
|
2022-11-24 07:54:43 -08:00
|
|
|
const { fileType } = (this.binaryData || {}) as IBinaryData;
|
|
|
|
return [fileType ?? 'other'];
|
2021-12-23 13:29:04 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
|
|
.binary-data {
|
2022-07-26 03:45:55 -07:00
|
|
|
background-color: var(--color-foreground-xlight);
|
2021-12-23 13:29:04 -08:00
|
|
|
|
|
|
|
&.image {
|
|
|
|
max-height: calc(100% - 1em);
|
|
|
|
max-width: calc(100% - 1em);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.other {
|
|
|
|
height: calc(100% - 1em);
|
|
|
|
width: calc(100% - 1em);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|