2024-06-18 01:50:28 -07:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { ref, onMounted, computed } from 'vue';
|
|
|
|
import { useWorkflowsStore } from '@/stores/workflows.store';
|
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 VueJsonPretty from 'vue-json-pretty';
|
2023-10-11 03:09:19 -07:00
|
|
|
import RunDataHtml from '@/components/RunDataHtml.vue';
|
2021-12-23 13:29:04 -08:00
|
|
|
|
2024-06-18 01:50:28 -07:00
|
|
|
const props = defineProps<{
|
|
|
|
binaryData: IBinaryData;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const isLoading = ref(true);
|
|
|
|
const embedSource = ref('');
|
|
|
|
const error = ref(false);
|
|
|
|
const data = ref('');
|
|
|
|
|
|
|
|
const workflowsStore = useWorkflowsStore();
|
|
|
|
|
|
|
|
const embedClass = computed(() => {
|
|
|
|
return [props.binaryData.fileType ?? 'other'];
|
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
const { id, data: binaryData, fileName, fileType, mimeType } = props.binaryData;
|
|
|
|
const isJSONData = fileType === 'json';
|
|
|
|
const isHTMLData = fileType === 'html';
|
2022-12-11 05:10:54 -08:00
|
|
|
|
2024-06-18 01:50:28 -07:00
|
|
|
if (!id) {
|
|
|
|
if (isJSONData || isHTMLData) {
|
|
|
|
data.value = jsonParse(atob(binaryData));
|
|
|
|
} else {
|
|
|
|
embedSource.value = 'data:' + mimeType + ';base64,' + binaryData;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const binaryUrl = workflowsStore.getBinaryUrl(id, 'view', fileName ?? '', mimeType);
|
2023-10-11 03:09:19 -07:00
|
|
|
if (isJSONData || isHTMLData) {
|
2024-06-18 01:50:28 -07:00
|
|
|
const fetchedData = await fetch(binaryUrl, { credentials: 'include' });
|
|
|
|
data.value = await (isJSONData ? fetchedData.json() : fetchedData.text());
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
2024-06-18 01:50:28 -07:00
|
|
|
embedSource.value = binaryUrl;
|
2021-12-23 13:29:04 -08:00
|
|
|
}
|
2024-06-18 01:50:28 -07:00
|
|
|
} catch (e) {
|
|
|
|
error.value = true;
|
2022-12-14 01:04:10 -08:00
|
|
|
}
|
2024-06-18 01:50:28 -07:00
|
|
|
}
|
2021-12-23 13:29:04 -08:00
|
|
|
|
2024-06-18 01:50:28 -07:00
|
|
|
isLoading.value = false;
|
2021-12-23 13:29:04 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2024-08-24 06:24:08 -07:00
|
|
|
<template>
|
|
|
|
<span>
|
|
|
|
<div v-if="isLoading">Loading binary data...</div>
|
|
|
|
<div v-else-if="error">Error loading binary data</div>
|
|
|
|
<span v-else>
|
|
|
|
<video v-if="binaryData.fileType === 'video'" controls autoplay>
|
|
|
|
<source :src="embedSource" :type="binaryData.mimeType" />
|
|
|
|
{{ $locale.baseText('binaryDataDisplay.yourBrowserDoesNotSupport') }}
|
|
|
|
</video>
|
|
|
|
<audio v-else-if="binaryData.fileType === 'audio'" controls autoplay>
|
|
|
|
<source :src="embedSource" :type="binaryData.mimeType" />
|
|
|
|
{{ $locale.baseText('binaryDataDisplay.yourBrowserDoesNotSupport') }}
|
|
|
|
</audio>
|
|
|
|
<VueJsonPretty
|
|
|
|
v-else-if="binaryData.fileType === 'json'"
|
|
|
|
:data="data"
|
|
|
|
:deep="3"
|
|
|
|
:show-length="true"
|
|
|
|
/>
|
|
|
|
<RunDataHtml v-else-if="binaryData.fileType === 'html'" :input-html="data" />
|
|
|
|
<embed v-else :src="embedSource" class="binary-data" :class="embedClass" />
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
2021-12-23 13:29:04 -08:00
|
|
|
<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>
|