diff --git a/public/app/config/config.js b/public/app/config/config.js index 9bd1ac9d..304d8707 100644 --- a/public/app/config/config.js +++ b/public/app/config/config.js @@ -44,8 +44,10 @@ const TMP_FOLDER = 'tmp'; const DEFAULT_LANG = 'en'; const DEFAULT_DEVELOPER_MODE = false; const DEFAULT_GEOLOCATION_ENABLED = false; +const DEFAULT_PROTOCOL = 'https'; module.exports = { + DEFAULT_PROTOCOL, DEFAULT_DEVELOPER_MODE, DEFAULT_GEOLOCATION_ENABLED, DOWNLOADABLE_MIME_TYPES, diff --git a/public/app/download.js b/public/app/download.js index 42c0537b..a72630ad 100644 --- a/public/app/download.js +++ b/public/app/download.js @@ -1,9 +1,11 @@ +const _ = require('lodash'); const request = require('request-promise'); const cheerio = require('cheerio'); const download = require('download'); const providers = require('./config/providers'); const logger = require('./logger'); const mapping = require('./config/mapping'); +const { DEFAULT_PROTOCOL } = require('./config/config'); const { getExtension, isDownloadable, @@ -52,8 +54,8 @@ const downloadSpaceResources = async ({ lang, space, absoluteSpacePath }) => { const { key } = asset; if (url) { // default to https - if (url.startsWith('//')) { - url = `https:${url}`; + if (_.isString(url) && url.startsWith('//')) { + url = `${DEFAULT_PROTOCOL}:${url}`; } // get extension to save file diff --git a/src/components/phase/PhaseItem.js b/src/components/phase/PhaseItem.js index 0884b836..5e731c7d 100644 --- a/src/components/phase/PhaseItem.js +++ b/src/components/phase/PhaseItem.js @@ -1,4 +1,5 @@ import React from 'react'; +import _ from 'lodash'; import PropTypes from 'prop-types'; import { TEXT, @@ -7,14 +8,16 @@ import { RESOURCE, APPLICATION, IFRAME, + DEFAULT_PROTOCOL, } from '../../config/constants'; import PhaseText from './PhaseText'; import PhaseImage from './PhaseImage'; import PhaseVideo from './PhaseVideo'; import PhaseApp from './PhaseApp'; -const renderResource = item => { - const { id, mimeType, content, asset, url, name } = item; +// prop types gets confused when dealing with helper renderers +// eslint-disable-next-line react/prop-types +const renderResource = ({ id, mimeType, content, asset, url, name }) => { if (mimeType === TEXT) { return ; } @@ -44,10 +47,19 @@ const renderResource = item => { }; const PhaseItem = ({ item, spaceId, phaseId }) => { - const { id, category, asset, url, name, appInstance } = item; + const { id, category, asset, name, appInstance, mimeType, content } = item; + + // we might need to fiddle with the url's protocol + let { url } = item; + + // default to https urls for items to avoid electron using file:// by default + if (_.isString(url) && url.startsWith('//')) { + url = `${DEFAULT_PROTOCOL}:${url}`; + } + switch (category) { case RESOURCE: - return renderResource(item); + return renderResource({ id, mimeType, content, asset, url, name }); case APPLICATION: return ( diff --git a/src/config/constants.js b/src/config/constants.js index 415bbbbe..f8048922 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -17,3 +17,4 @@ export const CONTROL_TYPES = { SWITCH: 'SWITCH', }; export const MIN_CARD_WIDTH = 345; +export const DEFAULT_PROTOCOL = 'https';