Show file content for non-binary files

This commit is contained in:
2017-11-27 21:33:58 +01:00
parent f190b6aabb
commit 7263f092d0
9 changed files with 92 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
import Component from '@ember/component';
import { alias } from '@ember/object/computed';
export default Component.extend({
storage: null,
classNames: ['file-preview'],
fileLoaded: false,
fileContent: null,
metaData: null,
type: alias('metaData.type'),
isBinary: alias('metaData.isBinary'),
isImage: function() {
return this.get('type').match(/^image\/.+$/);
}.property('type'),
isText: function() {
return !this.get('isBinary');
}.property('isBinary'),
fetchFile: function() {
let path = this.get('metaData.path');
this.get('storage.client').getFile(path).then(file => {
this.set('fileContent', file.data);
this.set('fileLoaded', true);
});
}.on('init')
});

View File

@@ -0,0 +1,9 @@
{{#if fileLoaded}}
{{#if isImage}}
<img src="" alt={{metaData.name}}>
{{/if}}
{{#if isText}}
<code>{{fileContent}}</code>
{{/if}}
{{/if}}