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-11 03:09:19 -07:00
|
|
|
<audio v-else-if="binaryData.fileType === 'audio'" controls autoplay>
|
2023-10-09 08:43:57 -07:00
|
|
|
<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'"
|
2023-10-11 03:09:19 -07:00
|
|
|
:data="data"
|
2022-12-11 05:10:54 -08:00
|
|
|
:deep="3"
|
|
|
|
:showLength="true"
|
|
|
|
/>
|
2023-10-11 03:09:19 -07:00
|
|
|
<run-data-html v-else-if="binaryData.fileType === 'html'" :inputHtml="data" />
|
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-11-28 03:15:08 -08:00
|
|
|
import { useWorkflowsStore } from '@/stores/workflows.store';
|
2023-10-11 03:09:19 -07:00
|
|
|
import RunDataHtml from '@/components/RunDataHtml.vue';
|
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,
|
2023-10-11 03:09:19 -07:00
|
|
|
RunDataHtml,
|
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,
|
2023-10-11 03:09:19 -07:00
|
|
|
data: '',
|
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-10-11 03:09:19 -07:00
|
|
|
const { id, data, fileName, fileType, mimeType } = this.binaryData;
|
2023-01-25 01:19:19 -08:00
|
|
|
const isJSONData = fileType === 'json';
|
2023-10-11 03:09:19 -07:00
|
|
|
const isHTMLData = fileType === 'html';
|
2022-12-11 05:10:54 -08:00
|
|
|
|
2022-11-24 07:54:43 -08:00
|
|
|
if (!id) {
|
2023-10-11 03:09:19 -07:00
|
|
|
if (isJSONData || isHTMLData) {
|
|
|
|
this.data = 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);
|
2023-10-11 03:09:19 -07:00
|
|
|
if (isJSONData || isHTMLData) {
|
|
|
|
const fetchedData = await fetch(binaryUrl, { credentials: 'include' });
|
|
|
|
this.data = await (isJSONData ? fetchedData.json() : fetchedData.text());
|
2022-12-11 05:10:54 -08:00
|
|
|
} 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[] {
|
2023-10-11 03:09:19 -07:00
|
|
|
const { fileType } = this.binaryData;
|
2022-11-24 07:54:43 -08:00
|
|
|
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>
|