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>
|
2023-10-09 08:43:57 -07:00
|
|
|
<audio v-if="binaryData.fileType === 'audio'" controls autoplay>
|
|
|
|
<source :src="embedSource" :type="binaryData.mimeType" />
|
|
|
|
{{ $locale.baseText('binaryDataDisplay.yourBrowserDoesNotSupport') }}
|
|
|
|
</audio>
|
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">
|
2023-05-16 02:43:46 -07:00
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import { mapStores } from 'pinia';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IBinaryData } from 'n8n-workflow';
|
|
|
|
import { jsonParse } from 'n8n-workflow';
|
2022-12-11 05:10:54 -08:00
|
|
|
import type { PropType } from 'vue';
|
|
|
|
import VueJsonPretty from 'vue-json-pretty';
|
2023-04-24 01:50:49 -07:00
|
|
|
import { useWorkflowsStore } from '@/stores';
|
2021-12-23 13:29:04 -08:00
|
|
|
|
2023-05-16 02:43:46 -07:00
|
|
|
export default defineComponent({
|
2021-12-23 13:29:04 -08:00
|
|
|
name: 'BinaryDataDisplayEmbed',
|
2022-12-11 05:10:54 -08:00
|
|
|
components: {
|
|
|
|
VueJsonPretty,
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
props: {
|
2022-12-11 05:10:54 -08:00
|
|
|
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
|
|
|
};
|
|
|
|
},
|
2023-04-24 01:50:49 -07:00
|
|
|
computed: {
|
|
|
|
...mapStores(useWorkflowsStore),
|
|
|
|
},
|
2021-12-23 13:29:04 -08:00
|
|
|
async mounted() {
|
2023-01-25 01:19:19 -08:00
|
|
|
const { id, data, fileName, fileType, mimeType } = (this.binaryData || {}) as IBinaryData;
|
|
|
|
const isJSONData = fileType === 'json';
|
2022-12-11 05:10:54 -08:00
|
|
|
|
2022-11-24 07:54:43 -08:00
|
|
|
if (!id) {
|
2022-12-11 05:10:54 -08:00
|
|
|
if (isJSONData) {
|
2023-01-25 01:19:19 -08:00
|
|
|
this.jsonData = jsonParse(atob(data));
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
2023-01-25 01:19:19 -08:00
|
|
|
this.embedSource = 'data:' + mimeType + ';base64,' + data;
|
2022-12-14 01:04:10 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
2023-04-24 01:50:49 -07:00
|
|
|
const binaryUrl = this.workflowsStore.getBinaryUrl(id, 'view', fileName, mimeType);
|
2022-12-11 05:10:54 -08:00
|
|
|
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-14 01:04:10 -08:00
|
|
|
}
|
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
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
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);
|
|
|
|
}
|
|
|
|
|
2023-10-09 08:43:57 -07:00
|
|
|
&.other,
|
|
|
|
&.pdf {
|
2021-12-23 13:29:04 -08:00
|
|
|
height: calc(100% - 1em);
|
|
|
|
width: calc(100% - 1em);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|