From 254b284f75934e7805e7558cf8aee261a6942467 Mon Sep 17 00:00:00 2001 From: maxkadushkin Date: Mon, 11 Sep 2023 14:19:26 +0300 Subject: [PATCH] [error page] added custom error page --- .gitignore | 2 +- common/errorpage/build/Gruntfile.js | 129 ++++++++++++++++++ common/errorpage/build/package.json | 15 ++ common/errorpage/deploy/error.html | 1 + common/errorpage/res/connection_error.svg | 5 + common/errorpage/src/code.js | 43 ++++++ common/errorpage/src/index.html | 82 +++++++++++ common/errorpage/src/index.html.deploy | 76 +++++++++++ common/errorpage/src/locale.js | 16 +++ .../vendor/svg-injector/svg-injector.map.js | 1 + .../vendor/svg-injector/svg-injector.min.js | 9 ++ 11 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 common/errorpage/build/Gruntfile.js create mode 100644 common/errorpage/build/package.json create mode 100644 common/errorpage/deploy/error.html create mode 100644 common/errorpage/res/connection_error.svg create mode 100644 common/errorpage/src/code.js create mode 100644 common/errorpage/src/index.html create mode 100644 common/errorpage/src/index.html.deploy create mode 100644 common/errorpage/src/locale.js create mode 100644 common/errorpage/vendor/svg-injector/svg-injector.map.js create mode 100644 common/errorpage/vendor/svg-injector/svg-injector.min.js diff --git a/.gitignore b/.gitignore index ae0bc482d..4ed19acaf 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ win-linux/package/linux/suse-rpm/builddir win-linux/package/linux/tar common/loginpage/build/plugins/* -common/loginpage/build/node_modules/* +common/**/node_modules/* common/loginpage/deploy/* common/loginpage/src/dlglogin.min.js common/converter/* diff --git a/common/errorpage/build/Gruntfile.js b/common/errorpage/build/Gruntfile.js new file mode 100644 index 000000000..54d01b8b3 --- /dev/null +++ b/common/errorpage/build/Gruntfile.js @@ -0,0 +1,129 @@ +module.exports = function(grunt) { + // var defaultConfig; + + + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-htmlmin'); + grunt.loadNpmTasks('grunt-text-replace'); + grunt.loadNpmTasks('grunt-svgmin'); + grunt.loadNpmTasks('grunt-terser'); + + function doRegisterInitializeAppTask(name, appName, configFile) { + return grunt.registerTask('init-build-' + name, 'Initialize build ' + appName, function(){ + // defaultConfig = configFile; + }); + } + + grunt.registerTask('desktop-app-extra', function() { + grunt.initConfig({ + // pkg: grunt.file.readJSON(defaultConfig), + + terser: { + options: { + format: { + comments: false, + }, + compress: { + drop_console: true, + }, + }, + core: { + src: ['../src/locale.js', '../src/code.js'], + dest: '../deploy/code.min.js', + }, + }, + + htmlmin: { + dist: { + options: { + removeComments: true, + collapseWhitespace: true, + minifyCSS: true + }, + files: { + '../deploy/error.html': '../src/index.html.deploy' + } + } + }, + + clean: { + options: { + force: true + }, + files: ["../deploy/*.png"] + }, + + svgmin: { + options: { + plugins: [ + { + name: 'preset-default', + params: { + overrides: { + sortAttrs: false, + removeUselessDefs: false, + cleanupIds: false, + } + } + } + ] + }, + dist: { + files: [{ + expand: true, + cwd: "../res", + src: ['*.svg'], + dest: '../deploy', + }] + } + }, + }); + }); + + grunt.registerTask('compile-html', function(){ + if ( !grunt.option('external-image') ) { + grunt.config('replace.insert-css', { + src: ['../deploy/error.html'], + overwrite: true, + replacements: [{ + from: /(\)/, + to: function(matchedWord, index, fullText, regexMatches) { + var css = grunt.file.read('../deploy/' + regexMatches[1]); + return ''; + } + },{ + from: /(\]+replace[^\>]+"([\w\S\.]+\.js)\"\>\<\/script\>)/g, + to: function(matchedWord, index, fullText, regexMatches) { + console.log('replace js ', regexMatches[1]); + if (!grunt.file.exists('../deploy/' + regexMatches[1])) { + grunt.log.error().writeln('file does not exists: ' + regexMatches[1]); + } + + var script = grunt.file.read('../deploy/' + regexMatches[1]); + return ''; + } + },{ + from: /(\]+inline-svg[^\>]+"([\w\S\.]+\.svg)\"\>)/g, + to: function(matchedWord, index, fullText, regexMatches) { + console.log('replace svg ', regexMatches[1]); + if (!grunt.file.exists('../deploy/' + regexMatches[1])) { + grunt.log.error().writeln('file does not exists: ' + regexMatches[1]); + } + + const svgsource = grunt.file.read('../deploy/' + regexMatches[1]); + return svgsource; + } + }] + }); + + grunt.config('clean.files', ['../deploy/*.js','../deploy/*.css','../deploy/*.svg']); + grunt.task.run('replace:insert-css', 'clean'); + } + }); + + + doRegisterInitializeAppTask('startpage', 'Desktop start page', 'startpage.json'); + + grunt.registerTask('deploy-desktop-startpage', ['desktop-app-extra', 'clean', 'terser', 'htmlmin', 'svgmin', 'compile-html']); + grunt.registerTask('default', ['init-build-startpage','deploy-desktop-startpage']); +}; \ No newline at end of file diff --git a/common/errorpage/build/package.json b/common/errorpage/build/package.json new file mode 100644 index 000000000..01ba08fc9 --- /dev/null +++ b/common/errorpage/build/package.json @@ -0,0 +1,15 @@ +{ + "name": "common", + "version": "0.0.8", + "homepage": "http://www.onlyoffice.com", + "private": true, + "dependencies": { + "grunt": "^1.6.1", + "grunt-contrib-clean": "^2.0.1", + "grunt-contrib-htmlmin": "^3.1.0", + "grunt-terser": "^2.0.0", + "grunt-text-replace": "0.4.0", + "grunt-svgmin": "^7.0.0", + "terser": "^5.17.3" + } +} diff --git a/common/errorpage/deploy/error.html b/common/errorpage/deploy/error.html new file mode 100644 index 000000000..0297e5578 --- /dev/null +++ b/common/errorpage/deploy/error.html @@ -0,0 +1 @@ +asc error
\ No newline at end of file diff --git a/common/errorpage/res/connection_error.svg b/common/errorpage/res/connection_error.svg new file mode 100644 index 000000000..d9bafd9c8 --- /dev/null +++ b/common/errorpage/res/connection_error.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/common/errorpage/src/code.js b/common/errorpage/src/code.js new file mode 100644 index 000000000..749eed00f --- /dev/null +++ b/common/errorpage/src/code.js @@ -0,0 +1,43 @@ +function getUrlParams() { + let e; + const a = /\+/g, // Regex for replacing addition symbol with a space + r = /([^&=]+)=?([^&]*)/g, + d = s => decodeURIComponent(s.replace(a, " ")), + q = window.location.search.substring(1), + urlParams = {}; + + while (e = r.exec(q)) + urlParams[d(e[1])] = d(e[2]); + + return urlParams; +} + +const nativevars = window.RendererProcessVariable; +let lang, theme, page; + +if ( nativevars ) { + lang = nativevars.lang; + theme = nativevars?.theme?.type; +} + +const params = getUrlParams(); +window.i18n.lang = lang || (params["lang"] || 'en').split(/[\-\_]/)[0]; +!theme && (theme = params['uitheme'] || 'light'); +page = params['page']; + +if ( theme == 'dark' ) { + document.body.classList.add('theme-type-dark') +} + +const ms = document.getElementById("idx-msg-short"); +if ( ms ) ms.innerText = window.i18n.tr("msgNoConn"); + +const ml = document.getElementById("idx-msg-long"); +if ( ml ) { + if ( page == 'file' ) + ml.innerText = window.i18n.tr("msgFileNoConnDesc"); + else + if ( page == 'templates') + ml.innerText = window.i18n.tr("msgTemplatesNoConnDesc"); + else ml.innerText = window.i18n.tr("msgNoConnDesc"); +} diff --git a/common/errorpage/src/index.html b/common/errorpage/src/index.html new file mode 100644 index 000000000..d25607da2 --- /dev/null +++ b/common/errorpage/src/index.html @@ -0,0 +1,82 @@ + + + + ONLYOFFICE Documents error + + + + + + + + + +
+ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/common/errorpage/src/index.html.deploy b/common/errorpage/src/index.html.deploy new file mode 100644 index 000000000..fc1128d76 --- /dev/null +++ b/common/errorpage/src/index.html.deploy @@ -0,0 +1,76 @@ + + + + asc error + + + + + + + + + +
+ + + + + +
+ + + + \ No newline at end of file diff --git a/common/errorpage/src/locale.js b/common/errorpage/src/locale.js new file mode 100644 index 000000000..0da6aa689 --- /dev/null +++ b/common/errorpage/src/locale.js @@ -0,0 +1,16 @@ +const locale = { + en: { + msgNoConn: 'Internet connection failed...', + msgNoConnDesc: 'Check connection', + msgFileNoConnDesc: "You are unable to edit the document because the Internet connection is lost or restricted. Please check your connection and re-open the document to continue.", + msgTemplatesNoConnDesc: "Couldn't load this section because you are experiencing possible network issues. Please check your internet connection and try again.", + } +} + +locale.ru = { + msgNoConn: 'Страница не доступна...', + msgNoConnDesc: 'Проверьте соединение', +} + +locale.tr = n => locale[locale.lang][n] || locale.en[n]; +window.i18n = locale; \ No newline at end of file diff --git a/common/errorpage/vendor/svg-injector/svg-injector.map.js b/common/errorpage/vendor/svg-injector/svg-injector.map.js new file mode 100644 index 000000000..02335c0a9 --- /dev/null +++ b/common/errorpage/vendor/svg-injector/svg-injector.map.js @@ -0,0 +1 @@ +{"version":3,"file":"./svg-injector.min.js","sources":["./svg-injector.js"],"names":["window","document","uniqueClasses","list","split","hash","i","length","out","hasOwnProperty","unshift","join","isLocal","location","protocol","hasSvgSupport","implementation","hasFeature","forEach","Array","prototype","fn","scope","this","TypeError","len","call","svgCache","injectCount","injectedElements","requestQueue","ranScripts","cloneSvg","sourceSvg","cloneNode","queueRequest","url","callback","push","processRequestQueue","index","setTimeout","loadSvg","undefined","SVGSVGElement","XMLHttpRequest","httpRequest","onreadystatechange","readyState","status","responseXML","statusText","Document","documentElement","DOMParser","Function","xmlDoc","parser","parseFromString","responseText","e","getElementsByTagName","open","overrideMimeType","send","injectElement","el","evalScripts","pngFallback","imgUrl","getAttribute","test","perElementFallback","setAttribute","pop","replace","indexOf","svg","imgId","imgTitle","classMerge","concat","imgStyle","imgData","filter","attributes","at","name","dataAttr","value","element","elementDefs","properties","currentId","newId","iriElementsAndProperties","clipPath","color-profile","cursor","linearGradient","marker","mask","pattern","radialGradient","Object","keys","key","querySelectorAll","elementsLen","id","referencingElements","property","j","referencingElementLen","removeAttribute","script","scriptType","scripts","scriptsToEval","k","scriptsLen","innerText","textContent","removeChild","l","scriptsToEvalLen","styleTags","styleTag","parentNode","replaceChild","SVGInjector","elements","options","done","eachCallback","each","elementsLoaded","module","exports","define","amd"],"mappings":";;;;;;;CAQC,SAAUA,EAAQC,GAEjB,YAMA,SAASC,GAAcC,GACrBA,EAAOA,EAAKC,MAAM,IAMlB,KAJA,GAAIC,MACAC,EAAIH,EAAKI,OACTC,KAEGF,KACAD,EAAKI,eAAeN,EAAKG,MAC5BD,EAAKF,EAAKG,IAAM,EAChBE,EAAIE,QAAQP,EAAKG,IAIrB,OAAOE,GAAIG,KAA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AAW,OAITE,GAAMA,EAAK,GAOC,iBAAXI,SAAiD,gBAAnBA,QAAOC,QAC9CD,OAAOC,QAAUA,QAAUR,EAGF,kBAAXS,SAAyBA,OAAOC,IAC9CD,OAAO,WACL,MAAOT,KAIgB,gBAAXlI,KACdA,EAAOkI,YAAcA,IAIvBlI,OAAQC"} \ No newline at end of file diff --git a/common/errorpage/vendor/svg-injector/svg-injector.min.js b/common/errorpage/vendor/svg-injector/svg-injector.min.js new file mode 100644 index 000000000..243424bee --- /dev/null +++ b/common/errorpage/vendor/svg-injector/svg-injector.min.js @@ -0,0 +1,9 @@ +/** + * SVGInjector v1.1.3 - Fast, caching, dynamic inline SVG DOM injection library + * https://github.com/iconic/SVGInjector + * + * Copyright (c) 2014-2015 Waybury + * @license MIT + */ +!function(t,e){"use strict";function r(t){t=t.split(" ");for(var e={},r=t.length,n=[];r--;)e.hasOwnProperty(t[r])||(e[t[r]]=1,n.unshift(t[r]));return n.join(" ")}var n="file:"===t.location.protocol,i=e.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"),o=Array.prototype.forEach||function(t,e){if(void 0===this||null===this||"function"!=typeof t)throw new TypeError;var r,n=this.length>>>0;for(r=0;n>r;++r)r in this&&t.call(e,this[r],r,this)},a={},l=0,s=[],u=[],c={},f=function(t){return t.cloneNode(!0)},p=function(t,e){u[t]=u[t]||[],u[t].push(e)},d=function(t){for(var e=0,r=u[t].length;r>e;e++)!function(e){setTimeout(function(){u[t][e](f(a[t]))},0)}(e)},v=function(e,r){if(void 0!==a[e])a[e]instanceof SVGSVGElement?r(f(a[e])):p(e,r);else{if(!t.XMLHttpRequest)return r("Browser does not support XMLHttpRequest"),!1;a[e]={},p(e,r);var i=new XMLHttpRequest;i.onreadystatechange=function(){if(4===i.readyState){if(404===i.status||null===i.responseXML)return r("Unable to load SVG file: "+e),n&&r("Note: SVG injection ajax calls do not work locally without adjusting security setting in your browser. Or consider using a local webserver."),r(),!1;if(!(200===i.status||n&&0===i.status))return r("There was a problem injecting the SVG: "+i.status+" "+i.statusText),!1;if(i.responseXML instanceof Document)a[e]=i.responseXML.documentElement;else if(DOMParser&&DOMParser instanceof Function){var t;try{var o=new DOMParser;t=o.parseFromString(i.responseText,"text/xml")}catch(l){t=void 0}if(!t||t.getElementsByTagName("parsererror").length)return r("Unable to parse SVG file: "+e),!1;a[e]=t.documentElement}d(e)}},i.open("GET",e),i.overrideMimeType&&i.overrideMimeType("text/xml"),i.send()}},h=function(e,n,a,u){var f=e.getAttribute("data-src")||e.getAttribute("src");if(!/\.svg/i.test(f))return void u("Attempted to inject a file with a non-svg extension: "+f);if(!i){var p=e.getAttribute("data-fallback")||e.getAttribute("data-png");return void(p?(e.setAttribute("src",p),u(null)):a?(e.setAttribute("src",a+"/"+f.split("/").pop().replace(".svg",".png")),u(null)):u("This browser does not support SVG and no PNG fallback was defined."))}-1===s.indexOf(e)&&(s.push(e),e.setAttribute("src",""),v(f,function(i){if("undefined"==typeof i||"string"==typeof i)return u(i),!1;var a=e.getAttribute("id");a&&i.setAttribute("id",a);var p=e.getAttribute("title");p&&i.setAttribute("title",p);var d=[].concat(i.getAttribute("class")||[],"injected-svg",e.getAttribute("class")||[]).join(" ");i.setAttribute("class",r(d));var v=e.getAttribute("style");v&&i.setAttribute("style",v);var h=[].filter.call(e.attributes,function(t){return/^data-\w[\w\-]*$/.test(t.name)});o.call(h,function(t){t.name&&t.value&&i.setAttribute(t.name,t.value)});var g,m,b,y,A,w={clipPath:["clip-path"],"color-profile":["color-profile"],cursor:["cursor"],filter:["filter"],linearGradient:["fill","stroke"],marker:["marker","marker-start","marker-mid","marker-end"],mask:["mask"],pattern:["fill","stroke"],radialGradient:["fill","stroke"]};Object.keys(w).forEach(function(t){g=t,b=w[t],m=i.querySelectorAll("defs "+g+"[id]");for(var e=0,r=m.length;r>e;e++){y=m[e].id,A=y+"-"+l;var n;o.call(b,function(t){n=i.querySelectorAll("["+t+'*="'+y+'"]');for(var e=0,r=n.length;r>e;e++)n[e].setAttribute(t,"url(#"+A+")")}),m[e].id=A}}),i.removeAttribute("xmlns:a");for(var x,S,k=i.querySelectorAll("script"),j=[],G=0,T=k.length;T>G;G++)S=k[G].getAttribute("type"),S&&"application/ecmascript"!==S&&"application/javascript"!==S||(x=k[G].innerText||k[G].textContent,j.push(x),i.removeChild(k[G]));if(j.length>0&&("always"===n||"once"===n&&!c[f])){for(var M=0,V=j.length;V>M;M++)new Function(j[M])(t);c[f]=!0}var E=i.querySelectorAll("style");o.call(E,function(t){t.textContent+=""}),e.parentNode.replaceChild(i,e),delete s[s.indexOf(e)],e=null,l++,u(i)}))},g=function(t,e,r){e=e||{};var n=e.evalScripts||"always",i=e.pngFallback||!1,a=e.each;if(void 0!==t.length){var l=0;o.call(t,function(e){h(e,n,i,function(e){a&&"function"==typeof a&&a(e),r&&t.length===++l&&r(l)})})}else t?h(t,n,i,function(e){a&&"function"==typeof a&&a(e),r&&r(1),t=null}):r&&r(0)};"object"==typeof module&&"object"==typeof module.exports?module.exports=exports=g:"function"==typeof define&&define.amd?define(function(){return g}):"object"==typeof t&&(t.SVGInjector=g)}(window,document); +//# sourceMappingURL=svg-injector.map.js \ No newline at end of file