Skip to content

Commit 4b8694b

Browse files
Save export options to project
1 parent 8ee2a91 commit 4b8694b

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

htdocs/fcut-utils.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ function readFile(filename, asJson) {
199199
});
200200
}
201201

202+
function getJson(response) {
203+
return response.json();
204+
}
205+
206+
function rejectIfNotOk(response) {
207+
if (response.ok) {
208+
return response;
209+
}
210+
return Promise.reject(response.statusText);
211+
}
212+
202213
function hashString(s) {
203214
var h = 0;
204215
if (typeof s !== 'string') {
@@ -210,3 +221,19 @@ function hashString(s) {
210221
}
211222
return h;
212223
}
224+
225+
function isObject(obj) {
226+
return (obj !== null) && (typeof obj === 'object');
227+
}
228+
229+
function copyFields(target, source, fields) {
230+
if (isObject(target) && isObject(source) && Array.isArray(fields)) {
231+
for (var i = 0; i < fields.length; i++) {
232+
var field = fields[i];
233+
if (source.hasOwnProperty(field)) {
234+
target[field] = source[field];
235+
}
236+
}
237+
}
238+
return target;
239+
}

htdocs/fcut.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var endRegExp = /^\n -- exit code ([0-9]+)\s/;
66
var DEFAULT_DESTINATION_FILENAME = 'fcut-out.mp4';
77
var DEFAULT_PROJECT_FILENAME = 'fcut-project.json';
88

9+
var EXPORTED_FIELDS = ['destinationFilename', 'projectFilename', 'aspectRatio', 'exportFormat', 'exportVideoCodec', 'exportAudioCodec', 'exportSubtitleCodec', 'exportMapAllStreams', 'time'];
10+
911
function updatePart(part) {
1012
if (typeof part === 'object') {
1113
var u = hashString(part.sourceId + (part.from | 0).toString(16));
@@ -93,9 +95,7 @@ var vm = new Vue({
9395
file: filename,
9496
extention: extention
9597
})
96-
}).then(function(response) {
97-
return response.json();
98-
}).then(function(filenames) {
98+
}).then(getJson).then(function(filenames) {
9999
if (filenames && (filenames.length > 0)) {
100100
if (multiple) {
101101
return filenames;
@@ -139,11 +139,10 @@ var vm = new Vue({
139139
},
140140
loadConfig: function(boot) {
141141
var that = this;
142-
return Promise.all([fetch('config/').then(function(response) {
143-
return response.json();
144-
}), fetch('/rest/checkFFmpeg', { method: 'POST' }).then(function(response) {
145-
return response.json();
146-
})]).then(function(values) {
142+
return Promise.all([
143+
fetch('config/').then(getJson),
144+
fetch('/rest/checkFFmpeg', { method: 'POST' }).then(getJson)
145+
]).then(function(values) {
147146
var config = values[0];
148147
var checkFFmpeg = values[1];
149148
//console.info('config', config, 'checkFFmpeg', checkFFmpeg);
@@ -171,9 +170,7 @@ var vm = new Vue({
171170
},
172171
openSourceById: function(sourceId) {
173172
var that = this;
174-
return fetch('source/' + sourceId + '/info.json').then(function(response) {
175-
return response.json();
176-
}).then(function(info) {
173+
return fetch('source/' + sourceId + '/info.json').then(getJson).then(function(info) {
177174
//console.info('info', info);
178175
that.sources[sourceId] = info;
179176
return sourceId;
@@ -501,6 +498,7 @@ var vm = new Vue({
501498
parts: this.parts,
502499
sources: sources
503500
};
501+
copyFields(project, this, EXPORTED_FIELDS);
504502
return project;
505503
},
506504
loadProjectFromJson: function(project) {
@@ -515,6 +513,7 @@ var vm = new Vue({
515513
});
516514
})).then(function() {
517515
that.parts = project.parts;
516+
copyFields(that, project, EXPORTED_FIELDS);
518517
that.refreshParts();
519518
that.navigateTo(0);
520519
});

0 commit comments

Comments
 (0)