gateways: adds getCIDGatewayURL to strings

This commit is contained in:
@wwwjim 2020-08-25 11:08:42 -07:00
parent eea2a2f866
commit 5d682fd1ef
5 changed files with 18 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import * as Constants from "~/common/constants";
const MINUTE = 60;
const HOUR = MINUTE * 60;
const DAY = HOUR * 24;
@ -29,6 +31,10 @@ export const getKey = (text) => {
return text.replace("Basic ", "");
};
export const getCIDGatewayURL = (cid) => {
return `https://${cid}.${Constants.gateways.ipfs}`;
};
export const createSlug = (text) => {
if (isEmpty(text)) {
return "untitled";

View File

@ -1,5 +1,6 @@
import * as React from "react";
import * as Constants from "~/common/constants";
import * as Strings from "~/common/strings";
import { css } from "@emotion/react";
@ -50,8 +51,8 @@ const STYLES_IMAGE = css`
export default class SlateMediaObject extends React.Component {
render() {
const name = `${this.props.data.name}`;
const cid = this.props.data.ipfs.replace('/ipfs/', '')
const url = this.props.data.url ? this.props.data.url : `https://${cid}.${Constants.gateways.ipfs}`
const cid = this.props.data.ipfs.replace("/ipfs/", "");
const url = Strings.getCIDGatewayURL(cid);
const type = this.props.data.type ? this.props.data.type : "LEGACY_NO_TYPE";
let element = <div css={STYLES_FAILURE}>No Preview</div>;

View File

@ -278,7 +278,7 @@ export default class SlateMediaObjectSidebar extends React.Component {
<a
key="sidebar-media-open-file"
css={STYLES_BUTTON}
href={`https://${this.props.cid}.${Constants.gateways.ipfs}`}
href={Strings.getCIDGatewayURL(this.props.cid)}
target="_blank"
>
Open file in a new browser tab &nbsp;&nbsp;
@ -289,7 +289,7 @@ export default class SlateMediaObjectSidebar extends React.Component {
<a
key="sidebar-media-download-file"
css={STYLES_BUTTON}
href={`https://${this.props.cid}.${Constants.gateways.ipfs}`}
href={Strings.getCIDGatewayURL(this.props.cid)}
target="_blank"
download={this.props.cid}
>

View File

@ -1,7 +1,8 @@
import * as React from "react";
import * as System from "~/components/system";
import * as Actions from "~/common/actions";
import * as Constants from "~/common/Constants";
import * as Constants from "~/common/constants";
import * as Strings from "~/common/strings";
import * as Validations from "~/common/validations";
import * as FileUtilities from "~/common/file-utilities";
@ -64,10 +65,10 @@ export default class SceneEditAccount extends React.Component {
return;
}
const cid = json.data.ipfs.replace('/ipfs/', '')
const cid = json.data.ipfs.replace("/ipfs/", "");
await Actions.updateViewer({
data: {
photo: `https://${cid}.${Constants.gateways.ipfs}`,
photo: Strings.getCIDGatewayURL(cid),
body: this.state.body,
name: this.state.name,
},

View File

@ -1,6 +1,7 @@
import * as React from "react";
import * as Constants from "~/common/constants";
import * as SVG from "~/components/system/svg";
import * as Strings from "~/common/strings";
import { css } from "@emotion/react";
@ -69,8 +70,8 @@ const STYLES_PATH = css`
export default class SceneFile extends React.Component {
render() {
const cid = this.props.data.ipfs.replace('/ipfs/', '')
const fileURL = this.props.data.url ? this.props.data.url : `https://${cid}.${Constants.gateways.ipfs}`;
const cid = this.props.data.ipfs.replace("/ipfs/", "");
const fileURL = Strings.getCIDGatewayURL(cid);
return (
<div css={STYLES_FLEX}>