Merge branch 'hotfix/v1.1.1' of github.com:ONLYOFFICE/AppServer into hotfix/v1.1.1

This commit is contained in:
Tatiana Lopaeva 2022-02-15 14:03:41 +03:00
commit 2f5feb4041
20 changed files with 329 additions and 112 deletions

View File

@ -23,7 +23,7 @@ class FirebaseHelper {
this.remoteConfig = firebase.remoteConfig();
this.remoteConfig.settings = {
fetchTimeMillis: 60000,
fetchTimeMillis: 3600000,
minimumFetchIntervalMillis: 3600000,
};
@ -94,19 +94,13 @@ class FirebaseHelper {
}
async getCampaignsImages(banner) {
const storageRef = this.firebaseStorage.ref();
const tangRef = storageRef.child(
`campaigns/images/campaigns.${banner}.png`
);
return await tangRef.getDownloadURL();
const domain = this.config["authDomain"];
return `https://${domain}/images/campaigns.${banner}.png`;
}
async getCampaignsTranslations(banner, lng) {
const storageRef = this.firebaseStorage.ref();
const tangRef = storageRef.child(
`campaigns/locales/${lng}/CampaignPersonal${banner}.json`
);
return await tangRef.getDownloadURL();
const domain = this.config["authDomain"];
return `https://${domain}/locales/${lng}/CampaignPersonal${banner}.json`;
}
}

View File

@ -31,9 +31,8 @@ const CampaignsBanner = (props) => {
<Text className="banner-sub-header" fontWeight="500" fontSize="12px">
{subHeaderLabel}
</Text>
{!imageLoad && <Loaders.Rectangle height="140px" borderRadius="5px" />}
<img src={img} onMouseDown={onMouseDown} onLoad={handleImageLoaded} />
{!imageLoad && <Loaders.Rectangle height="140px" borderRadius="5px" />}
</a>
<Button

View File

@ -1,130 +1,85 @@
import React, { useEffect, useState } from "react";
import { withTranslation } from "react-i18next";
import i18n from "i18next";
import Backend from "i18next-http-backend";
import { getLanguage } from "@appserver/common/utils";
import React, { useState, useEffect } from "react";
import CampaignsBanner from "@appserver/components/campaigns-banner";
import { ADS_TIMEOUT } from "../../../helpers/constants";
import { LANGUAGE } from "@appserver/common/constants";
import { getLanguage } from "@appserver/common/utils";
const i18nConfig = i18n.createInstance();
const Banner = () => {
const [campaignImage, setCampaignImage] = useState();
const [campaignTranslate, setCampaignTranslate] = useState();
let translationUrl;
const loadLanguagePath = async () => {
if (!window.firebaseHelper) return;
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
const lng = localStorage.getItem(LANGUAGE) || "en";
const language = getLanguage(lng instanceof Array ? lng[0] : lng);
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
const index = Number(localStorage.getItem("bannerIndex") || 0);
const campaign = campaigns[index];
try {
translationUrl = await window.firebaseHelper.getCampaignsTranslations(
campaign,
language
const getImage = async (campaign) => {
const imageUrl = await window.firebaseHelper.getCampaignsImages(
campaign.toLowerCase()
);
} catch (e) {
translationUrl = await window.firebaseHelper.getCampaignsTranslations(
return imageUrl;
};
const getTranslation = async (campaign, lng) => {
let translationUrl = await window.firebaseHelper.getCampaignsTranslations(
campaign,
"en"
lng
);
//console.error(e);
}
return translationUrl;
};
const bannerHOC = (WrappedComponent) => (props) => {
const { FirebaseHelper } = props;
const res = await fetch(translationUrl);
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
if (!res.ok) {
translationUrl = await window.firebaseHelper.getCampaignsTranslations(
campaign,
"en"
);
}
return await (await fetch(translationUrl)).json();
};
const [bannerImage, setBannerImage] = useState("");
const [bannerTranslation, setBannerTranslation] = useState();
const updateBanner = async () => {
const getBanner = async () => {
let index = Number(localStorage.getItem("bannerIndex") || 0);
const campaign = campaigns[index];
const currentCampaign = campaigns[index];
if (campaigns.length < 1 || index + 1 >= campaigns.length) {
index = 0;
} else {
index++;
}
try {
const translationUrl = await loadLanguagePath();
setBannerTranslation(translationUrl);
i18nConfig.use(Backend).init({
lng: localStorage.getItem(LANGUAGE) || "en",
fallbackLng: "en",
load: "currentOnly",
debug: false,
defaultNS: "",
backend: {
loadPath: function () {
return translationUrl;
},
},
});
const image = await FirebaseHelper.getCampaignsImages(
campaign.toLowerCase()
);
setBannerImage(image);
} catch (e) {
updateBanner();
//console.error(e);
}
localStorage.setItem("bannerIndex", index);
const image = await getImage(currentCampaign);
const translate = await getTranslation(currentCampaign, language);
setCampaignImage(image);
setCampaignTranslate(translate);
};
useEffect(() => {
updateBanner();
setInterval(updateBanner, ADS_TIMEOUT);
getBanner();
const adsInterval = setInterval(getBanner, ADS_TIMEOUT);
return function cleanup() {
clearInterval(adsInterval);
};
}, []);
if (!bannerTranslation || !bannerImage) return <></>;
return <WrappedComponent bannerImage={bannerImage} {...props} />;
};
const Banner = (props) => {
//console.log("Banner render", props);
const { t, tReady, bannerImage } = props;
const campaigns = (localStorage.getItem("campaigns") || "")
.split(",")
.filter((campaign) => campaign.length > 0);
if (!campaigns.length || !tReady) {
return <></>;
}
return (
<CampaignsBanner
headerLabel={t("Header")}
subHeaderLabel={t("SubHeader")}
img={bannerImage}
btnLabel={t("ButtonLabel")}
link={t("Link")}
/>
<>
{campaignImage && campaignTranslate && (
<CampaignsBanner
headerLabel={campaignTranslate.Header}
subHeaderLabel={campaignTranslate.SubHeader}
img={campaignImage}
btnLabel={campaignTranslate.ButtonLabel}
link={campaignTranslate.Link}
/>
)}
</>
);
};
const BannerWithTranslation = withTranslation()(Banner);
const WrapperBanner = (props) => (
<BannerWithTranslation i18n={i18nConfig} useSuspense={false} {...props} />
);
export default bannerHOC(WrapperBanner);
export default Banner;

View File

@ -9,4 +9,4 @@ export const thumbnailStatuses = {
NOT_REQUIRED: 3,
};
export const ADS_TIMEOUT = 60000;
export const ADS_TIMEOUT = 300000; // 5 min

View File

@ -0,0 +1,5 @@
{
"projects": {
"default": "appserver-c011a"
}
}

66
web/ASC.Web.Campaigns/.gitignore vendored Normal file
View File

@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*
# Firebase cache
.firebase/
# Firebase config
# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env

View File

@ -0,0 +1,26 @@
{
"hosting": {
"public": "public",
"headers": [
{
"source": "**",
"headers": [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
}
]
},
{
"source": "**/*.@(png|json)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=7200"
}
]
}
],
"ignore": ["firebase.json", "**/node_modules/**"]
}
}

View File

@ -0,0 +1,12 @@
{
"name": "@appserver/campaigns",
"version": "0.1.0",
"private": true,
"scripts": {
"firebase:login": "firebase login",
"firebase:deploy": "firebase deploy"
},
"dependencies": {
"firebase-tools": "^10.2.0"
}
}

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>
<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1,89 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>
<!-- update the version number as needed -->
<script defer src="/__/firebase/9.6.6/firebase-app-compat.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/9.6.6/firebase-auth-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-database-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-firestore-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-functions-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-messaging-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-storage-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-analytics-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-remote-config-compat.js"></script>
<script defer src="/__/firebase/9.6.6/firebase-performance-compat.js"></script>
<!--
initialize the SDK after all desired features are loaded, set useEmulator to false
to avoid connecting the SDK to running emulators.
-->
<script defer src="/__/firebase/init.js?useEmulator=true"></script>
<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px; border-radius: 3px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>Welcome</h2>
<h1>Firebase Hosting Setup Complete</h1>
<p>You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!</p>
<a target="_blank" href="https://firebase.google.com/docs/hosting/">Open Hosting Documentation</a>
</div>
<p id="load">Firebase SDK Loading&hellip;</p>
<script>
document.addEventListener('DOMContentLoaded', function() {
const loadEl = document.querySelector('#load');
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
// // The Firebase SDK is initialized and available here!
//
// firebase.auth().onAuthStateChanged(user => { });
// firebase.database().ref('/path/to/ref').on('value', snapshot => { });
// firebase.firestore().doc('/foo/bar').get().then(() => { });
// firebase.functions().httpsCallable('yourFunction')().then(() => { });
// firebase.messaging().requestPermission().then(() => { });
// firebase.storage().ref('/path/to/ref').getDownloadURL().then(() => { });
// firebase.analytics(); // call to activate
// firebase.analytics().logEvent('tutorial_completed');
// firebase.performance(); // call to activate
//
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
try {
let app = firebase.app();
let features = [
'auth',
'database',
'firestore',
'functions',
'messaging',
'storage',
'analytics',
'remoteConfig',
'performance',
].filter(feature => typeof app[feature] === 'function');
loadEl.textContent = `Firebase SDK loaded with ${features.join(', ')}`;
} catch (e) {
console.error(e);
loadEl.textContent = 'Error loading the Firebase SDK, check the console.';
}
});
</script>
</body>
</html>

View File

@ -0,0 +1,6 @@
{
"Header": "ONLYOFFICE for schools",
"SubHeader": "Learn about education discounts",
"ButtonLabel": "Learn more",
"Link": "https://www.onlyoffice.com/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -0,0 +1,6 @@
{
"Header": "ONLYOFFICE for business",
"SubHeader": "Docs, projects, clients & emails",
"ButtonLabel": "Start free trial",
"Link": "https://www.onlyoffice.com/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -0,0 +1,6 @@
{
"Header": "ONLYOFFICE for PC",
"SubHeader": "Get a free alternative to MS Office",
"ButtonLabel": "Download",
"Link": "https://www.onlyoffice.com/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -0,0 +1,6 @@
{
"Header": "ONLYOFFICE для бизнеса",
"SubHeader": "Документы, проекты, клиенты и почта",
"ButtonLabel": "Начните бесплатно",
"Link": "https://www.onlyoffice.com/ru/registration.aspx?utm_source=personal&utm_campaign=BannerPersonalCloud"
}

View File

@ -0,0 +1,6 @@
{
"Header": "ONLYOFFICE для ПК",
"SubHeader": "Получите бесплатную альтернативу MS Office",
"ButtonLabel": "Скачать",
"Link": "https://www.onlyoffice.com/ru/download-desktop.aspx?utm_source=personal&utm_campaign=BannerPersonalDesktop"
}

View File

@ -0,0 +1,6 @@
{
"Header": "ONLYOFFICE для школ",
"SubHeader": "Узнайте больше об образовательных скидках",
"ButtonLabel": "Узнать больше",
"Link": "https://www.onlyoffice.com/ru/education.aspx?utm_source=personal&utm_campaign=BannerPersonalEducation"
}

View File

@ -324,11 +324,13 @@ const Shell = ({ items = [], page = "home", ...rest }) => {
fetchMaintenance();
fetchBanners();
fbInterval = setInterval(fetchMaintenance, 60000);
const bannerInterval = setInterval(fetchBanners, 60000 * 720); // get every 12 hours
return () => {
if (fbInterval) {
clearInterval(fbInterval);
}
clearInterval(bannerInterval);
clearSnackBarTimer();
};
}, [isLoaded]);