From 4b8694b7f9ee25ad09f53cd36e89b1aab58f3623 Mon Sep 17 00:00:00 2001 From: javalikescript Date: Sat, 10 Dec 2022 09:18:27 +0100 Subject: [PATCH] Save export options to project --- htdocs/fcut-utils.js | 27 +++++++++++++++++++++++++++ htdocs/fcut.js | 21 ++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/htdocs/fcut-utils.js b/htdocs/fcut-utils.js index a30647b..9a81258 100644 --- a/htdocs/fcut-utils.js +++ b/htdocs/fcut-utils.js @@ -199,6 +199,17 @@ function readFile(filename, asJson) { }); } +function getJson(response) { + return response.json(); +} + +function rejectIfNotOk(response) { + if (response.ok) { + return response; + } + return Promise.reject(response.statusText); +} + function hashString(s) { var h = 0; if (typeof s !== 'string') { @@ -210,3 +221,19 @@ function hashString(s) { } return h; } + +function isObject(obj) { + return (obj !== null) && (typeof obj === 'object'); +} + +function copyFields(target, source, fields) { + if (isObject(target) && isObject(source) && Array.isArray(fields)) { + for (var i = 0; i < fields.length; i++) { + var field = fields[i]; + if (source.hasOwnProperty(field)) { + target[field] = source[field]; + } + } + } + return target; +} diff --git a/htdocs/fcut.js b/htdocs/fcut.js index f0dbd5b..bb0bd0f 100644 --- a/htdocs/fcut.js +++ b/htdocs/fcut.js @@ -6,6 +6,8 @@ var endRegExp = /^\n -- exit code ([0-9]+)\s/; var DEFAULT_DESTINATION_FILENAME = 'fcut-out.mp4'; var DEFAULT_PROJECT_FILENAME = 'fcut-project.json'; +var EXPORTED_FIELDS = ['destinationFilename', 'projectFilename', 'aspectRatio', 'exportFormat', 'exportVideoCodec', 'exportAudioCodec', 'exportSubtitleCodec', 'exportMapAllStreams', 'time']; + function updatePart(part) { if (typeof part === 'object') { var u = hashString(part.sourceId + (part.from | 0).toString(16)); @@ -93,9 +95,7 @@ var vm = new Vue({ file: filename, extention: extention }) - }).then(function(response) { - return response.json(); - }).then(function(filenames) { + }).then(getJson).then(function(filenames) { if (filenames && (filenames.length > 0)) { if (multiple) { return filenames; @@ -139,11 +139,10 @@ var vm = new Vue({ }, loadConfig: function(boot) { var that = this; - return Promise.all([fetch('config/').then(function(response) { - return response.json(); - }), fetch('/rest/checkFFmpeg', { method: 'POST' }).then(function(response) { - return response.json(); - })]).then(function(values) { + return Promise.all([ + fetch('config/').then(getJson), + fetch('/rest/checkFFmpeg', { method: 'POST' }).then(getJson) + ]).then(function(values) { var config = values[0]; var checkFFmpeg = values[1]; //console.info('config', config, 'checkFFmpeg', checkFFmpeg); @@ -171,9 +170,7 @@ var vm = new Vue({ }, openSourceById: function(sourceId) { var that = this; - return fetch('source/' + sourceId + '/info.json').then(function(response) { - return response.json(); - }).then(function(info) { + return fetch('source/' + sourceId + '/info.json').then(getJson).then(function(info) { //console.info('info', info); that.sources[sourceId] = info; return sourceId; @@ -501,6 +498,7 @@ var vm = new Vue({ parts: this.parts, sources: sources }; + copyFields(project, this, EXPORTED_FIELDS); return project; }, loadProjectFromJson: function(project) { @@ -515,6 +513,7 @@ var vm = new Vue({ }); })).then(function() { that.parts = project.parts; + copyFields(that, project, EXPORTED_FIELDS); that.refreshParts(); that.navigateTo(0); });