Skip to content

Commit db72812

Browse files
committed
feat: adding FileBrowser component for input if ffmpegd is enabled.
1 parent 7046ba1 commit db72812

File tree

2 files changed

+134
-4
lines changed

2 files changed

+134
-4
lines changed

src/components/Editor.vue

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<b-form-group label="Input:" label-for="input">
1212
<b-input-group>
1313
<b-form-select
14-
v-if="!$store.state.ffmpegdEnabled"
14+
v-if="!$store.state.ffmpegdEnabled || !$store.state.wsConnected"
1515
class="protocol"
1616
v-model="protocolInput"
1717
@change="setProtocol('input', $event)"
@@ -20,19 +20,30 @@
2020
</b-form-select>
2121

2222
<b-form-input
23-
v-if="!$store.state.ffmpegdEnabled"
23+
v-if="!$store.state.ffmpegdEnabled || !$store.state.wsConnected"
2424
v-model="form.input"
2525
:state="Boolean(form.input)"
2626
placeholder="Example: output.mp4"
2727
></b-form-input>
2828

29-
<b-form-file
29+
<b-form-input
30+
v-else
31+
v-model="form.input"
32+
placeholder=""
33+
@focus="onFileFocus"
34+
></b-form-input>
35+
36+
<div v-if="showFileBrowser">
37+
<FileBrowser v-on:file="onFileSelect" v-on:close="onClose" />
38+
</div>
39+
40+
<!-- <b-form-file
3041
v-else
3142
v-model="form.inputFile"
3243
:state="Boolean(form.inputFile)"
3344
placeholder="Choose a file or drop it here..."
3445
drop-placeholder="Drop file here..."
35-
></b-form-file>
46+
></b-form-file> -->
3647
</b-input-group>
3748
</b-form-group>
3849
</b-col>
@@ -136,6 +147,7 @@ import Options from './Options.vue';
136147
import Command from './Command.vue';
137148
import Toolbar from './Toolbar.vue';
138149
import JsonViewer from './JsonViewer.vue';
150+
import FileBrowser from './FileBrowser.vue';
139151
140152
const {
141153
protocols,
@@ -155,6 +167,7 @@ export default {
155167
Command,
156168
Toolbar,
157169
JsonViewer,
170+
FileBrowser,
158171
},
159172
props: {},
160173
data() {
@@ -234,6 +247,7 @@ export default {
234247
controls: {
235248
showJSON: false,
236249
},
250+
showFileBrowser: false,
237251
};
238252
},
239253
created() {
@@ -340,6 +354,16 @@ export default {
340354
});
341355
this.$emit('onEncode');
342356
},
357+
onFileSelect(file) {
358+
this.form.input = file;
359+
this.showFileBrowser = false;
360+
},
361+
onFileFocus() {
362+
this.showFileBrowser = true;
363+
},
364+
onClose() {
365+
this.showFileBrowser = false;
366+
},
343367
},
344368
};
345369
</script>

src/components/FileBrowser.vue

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<template>
2+
<div id="file-browser">
3+
<div>
4+
<ul>
5+
<li class="cwd">{{ data.cwd }}</li>
6+
<li v-if="prefix !== ''">
7+
<a href="#" @click.prevent="goBack">...</a>
8+
</li>
9+
<li v-for="o in filteredFiles" v-bind:key="o.label">
10+
<a href="#" @click.prevent="onFileSelect">{{ o.label }}</a>
11+
</li>
12+
</ul>
13+
<b-button
14+
class="float-right mr-2"
15+
squared variant="light"
16+
size="sm"
17+
@click="close"
18+
>Cancel</b-button>
19+
</div>
20+
</div>
21+
</template>
22+
23+
<script>
24+
const LOCALSTORAGE_HOST_URI = 'host';
25+
const host = window.localStorage.getItem(LOCALSTORAGE_HOST_URI) || 'http://localhost:8080';
26+
27+
export default {
28+
data() {
29+
return {
30+
prefix: '',
31+
data: [],
32+
};
33+
},
34+
computed: {
35+
filteredFiles() {
36+
const items = [];
37+
if (this.data && this.data.folders) {
38+
this.data.folders.forEach((item) => {
39+
const o = {
40+
label: item,
41+
children: [],
42+
};
43+
items.push(o);
44+
});
45+
}
46+
if (this.data && this.data.files) {
47+
this.data.files.forEach((item) => {
48+
const o = {
49+
label: item.name,
50+
children: [],
51+
};
52+
items.push(o);
53+
});
54+
}
55+
return items.filter((o) => o.label !== this.prefix);
56+
},
57+
},
58+
mounted() {
59+
this.getData();
60+
},
61+
methods: {
62+
onFileSelect(event) {
63+
const { text } = event.target;
64+
if (text[text.length - 1] !== '/') {
65+
this.$emit('file', `${event.target.text}`);
66+
} else {
67+
this.getData(text);
68+
}
69+
},
70+
goBack() {
71+
const arr = this.prefix.split('/');
72+
arr.splice(-2, 1); // Remove last path, but keep leading slash.
73+
const newPrefix = arr.join('/');
74+
this.getData(newPrefix);
75+
},
76+
getData(prefix = '') {
77+
fetch(`${host}/files?prefix=${prefix}`)
78+
.then((response) => response.json())
79+
.then((data) => {
80+
this.data = data;
81+
this.prefix = prefix;
82+
});
83+
},
84+
close() {
85+
this.$emit('close');
86+
},
87+
},
88+
};
89+
</script>
90+
91+
<style scoped>
92+
#file-browser {
93+
width: 100%;
94+
position: absolute;
95+
padding: 15px 0;
96+
left: 0;
97+
top: 36px;
98+
background: white;
99+
border: #ced4da solid 1px;
100+
z-index: 1;
101+
}
102+
.cwd {
103+
list-style: none;
104+
font-family: monospace;
105+
}
106+
</style>

0 commit comments

Comments
 (0)