Skip to content

Commit

Permalink
fix: default to using https if url has no protocol
Browse files Browse the repository at this point in the history
closes #161
  • Loading branch information
juancarlosfarah committed Aug 8, 2019
1 parent 77afd33 commit 3b6441e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions public/app/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions public/app/download.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions src/components/phase/PhaseItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import _ from 'lodash';
import PropTypes from 'prop-types';
import {
TEXT,
Expand All @@ -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 <PhaseText key={id} id={id} content={content} />;
}
Expand Down Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export const CONTROL_TYPES = {
SWITCH: 'SWITCH',
};
export const MIN_CARD_WIDTH = 345;
export const DEFAULT_PROTOCOL = 'https';

0 comments on commit 3b6441e

Please sign in to comment.