From f7e777d5a674a029b05026a22c6734393944a299 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 5 Mar 2021 16:44:28 +0100 Subject: [PATCH] Fix image upload with the same name in onlyoffice --- www/common/onlyoffice/inner.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index c29253f99..8a177ca3a 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1457,6 +1457,25 @@ define([ // Add image to the list var mediasSources = getMediasSources(); + + // Check if name already exists + var getUniqueName = function (name, mediasSources) { + var get = function () { + var s = name.split('.'); + if (s.length > 1) { + s[s.length - 2] = s[s.length - 2] + '-' + Util.uid(); + name = s.join('.'); + } else { + name += '-'+ Util.uid(); + } + }; + while (mediasSources[name]) { get(); } + return name; + }; + if (mediasSources[name]) { + name = getUniqueName(name, mediasSources); + data.name = name; + } mediasSources[name] = data; APP.onLocal();