From d5a3447dad7ac779b15d279bad12582c84a06892 Mon Sep 17 00:00:00 2001 From: Andrew Hill Date: Tue, 25 Aug 2020 10:46:41 -0700 Subject: [PATCH] feat(api): skip ipfs subdomain redirect Signed-off-by: Andrew Hill --- common/constants.js | 4 ++++ components/core/SlateMediaObject.js | 3 ++- components/core/SlateMediaObjectSidebar.js | 4 ++-- components/system/modules/FriendsList.js | 2 +- node_common/constants.js | 1 + node_common/utilities.js | 2 +- pages/_/experiences/friends-list.js | 20 ++++++++++---------- pages/api/slates/add-url.js | 4 +++- pages/api/v1/upload-data/[id].js | 4 +++- scenes/SceneEditAccount.js | 4 +++- scenes/SceneFile.js | 3 ++- scenes/SceneSlate.js | 5 +++-- 12 files changed, 35 insertions(+), 21 deletions(-) diff --git a/common/constants.js b/common/constants.js index 36dc2467..09586a45 100644 --- a/common/constants.js +++ b/common/constants.js @@ -60,3 +60,7 @@ export const theme = { pageBackground: system.foreground, pageText: system.black, }; + +export const gateways = { + ipfs: "ipfs.slate.textile.io", +} \ No newline at end of file diff --git a/components/core/SlateMediaObject.js b/components/core/SlateMediaObject.js index 8c36cd38..11a09bf6 100644 --- a/components/core/SlateMediaObject.js +++ b/components/core/SlateMediaObject.js @@ -50,7 +50,8 @@ const STYLES_IMAGE = css` export default class SlateMediaObject extends React.Component { render() { const name = `${this.props.data.name}`; - const url = this.props.data.url ? this.props.data.url : `https://hub.textile.io${this.props.data.ipfs}`; + const cid = this.props.data.ipfs.replace('/ipfs/', '') + const url = this.props.data.url ? this.props.data.url : `https://${cid}.${Constants.gateways.ipfs}` const type = this.props.data.type ? this.props.data.type : "LEGACY_NO_TYPE"; let element =
No Preview
; diff --git a/components/core/SlateMediaObjectSidebar.js b/components/core/SlateMediaObjectSidebar.js index ad6ee660..455a0927 100644 --- a/components/core/SlateMediaObjectSidebar.js +++ b/components/core/SlateMediaObjectSidebar.js @@ -278,7 +278,7 @@ export default class SlateMediaObjectSidebar extends React.Component { Open file in a new browser tab   ⭢ @@ -289,7 +289,7 @@ export default class SlateMediaObjectSidebar extends React.Component { diff --git a/components/system/modules/FriendsList.js b/components/system/modules/FriendsList.js index 0d518dc0..9f10ae89 100644 --- a/components/system/modules/FriendsList.js +++ b/components/system/modules/FriendsList.js @@ -8,7 +8,7 @@ import { Table } from "~/components/system/components/Table"; import { StatUpload, StatDownload } from "~/components/system/components/Stat"; let genericImg = - "https://hub.textile.io/ipfs/bafybeiblly23jomdjjiq7ilth667npcfm5llqb5xfstodbbfa5pxtoek7u"; + `https://bafybeiblly23jomdjjiq7ilth667npcfm5llqb5xfstodbbfa5pxtoek7u.${Constants.gateways.ipfs}`; const STYLES_BUTTON = ` font-family: ${Constants.font.text}; diff --git a/node_common/constants.js b/node_common/constants.js index c249efaf..69dbcffe 100644 --- a/node_common/constants.js +++ b/node_common/constants.js @@ -1,5 +1,6 @@ export const POLLING_RATE = 5000; export const POWERGATE_HOST = "https://grpcweb.slate.textile.io"; +export const IPFS_GATEWAY_DOMAIN = "ipfs.slate.textile.io"; export const FILE_STORAGE_URL = "./public/static/files/"; export const GITHUB_URL = "https://github.com/filecoin-project/slate"; export const ANALYTICS_URL = "https://slate-stats-dev.azurewebsites.net/"; diff --git a/node_common/utilities.js b/node_common/utilities.js index 8bc3e716..04d0a21a 100644 --- a/node_common/utilities.js +++ b/node_common/utilities.js @@ -18,7 +18,7 @@ const TEXTILE_KEY_INFO = { export const checkTextile = async () => { try { - const response = await fetch("https://hub.textile.io/health", { + const response = await fetch("https://slate.textile.io/health", { headers: { Accept: "application/json", "Content-Type": "application/json", diff --git a/pages/_/experiences/friends-list.js b/pages/_/experiences/friends-list.js index d7553662..c418d298 100644 --- a/pages/_/experiences/friends-list.js +++ b/pages/_/experiences/friends-list.js @@ -14,13 +14,13 @@ const friendsList = { id: 72572959238, user: "@martina", img: - "https://hub.textile.io/ipfs/bafybeiguo2uhd63reslbqkkgsqedgeikhtuwn5lzqpnqzluoaa3rnkfcvi", + "https://bafybeiguo2uhd63reslbqkkgsqedgeikhtuwn5lzqpnqzluoaa3rnkfcvi.ipfs.hub.textile.io", }, { id: 2572952030, user: "@jim", img: - "https://hub.textile.io/ipfs/bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu", + "https://bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu.ipfs.hub.textile.io", }, ], friends: [ @@ -41,7 +41,7 @@ const friendsList = { id: 637838385993, user: "@aaron", img: - "https://hub.textile.io/ipfs/bafkreicb2lookm56omsfjwuwuziwftizmdsj4oneveuqiqlu6k5hc7j5nq", + "https://bafkreicb2lookm56omsfjwuwuziwftizmdsj4oneveuqiqlu6k5hc7j5nq.ipfs.hub.textile.io", info: { chainHead: "bafyl5q5qo5wolfxsui4ciujfucqwf6gqso4lettcjwl2tyismgol7c4tngvoono5rmytuqotye7oosfjv6g7a", @@ -55,7 +55,7 @@ const friendsList = { id: 982799203032, user: "@colin", img: - "https://hub.textile.io/ipfs/bafybeigxb4arecl6iwsvjnwzi2lqpmmif6l2kgwptac7q3tzqmsimci2yq", + "https://bafybeigxb4arecl6iwsvjnwzi2lqpmmif6l2kgwptac7q3tzqmsimci2yq.ipfs.hub.textile.io", info: { chainHead: "t3ual5q5qo5wolfxsui4ciujfucqwf6gqso4lettcjwl2tyismgol7c4tngvoono5rmytuqotye7oosfjv6g7a", @@ -69,7 +69,7 @@ const friendsList = { id: 673883729083, user: "@jason", img: - "https://hub.textile.io/ipfs/bafybeicp3x3poprnrsxhnqscsiuobxejxsbcsu2t4yhte6qmcofjvjqbn4", + "https://bafybeicp3x3poprnrsxhnqscsiuobxejxsbcsu2t4yhte6qmcofjvjqbn4.ipfs.hub.textile.io", info: { chainHead: "t3solnyrrblqlmvi6gmzewzvu62vs7uqvkl22yemzr63bcylbaaqsg44mnipepuafg7efzzx4zwcsi66jgze3q", @@ -97,13 +97,13 @@ export default class SystemPagePeersList extends React.Component { id: 72572959238, user: "@martina", img: - "https://hub.textile.io/ipfs/bafybeiguo2uhd63reslbqkkgsqedgeikhtuwn5lzqpnqzluoaa3rnkfcvi", + "https://bafybeiguo2uhd63reslbqkkgsqedgeikhtuwn5lzqpnqzluoaa3rnkfcvi.ipfs.hub.textile.io", }, { id: 2572952030, user: "@jim", img: - "https://hub.textile.io/ipfs/bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu", + "https://bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu.ipfs.hub.textile.io", }, ], friends: [ @@ -124,7 +124,7 @@ export default class SystemPagePeersList extends React.Component { id: 637838385993, user: "@aaron", img: - "https://hub.textile.io/ipfs/bafkreicb2lookm56omsfjwuwuziwftizmdsj4oneveuqiqlu6k5hc7j5nq", + "https://bafkreicb2lookm56omsfjwuwuziwftizmdsj4oneveuqiqlu6k5hc7j5nq.ipfs.hub.textile.io", info: { chainHead: "bafyl5q5qo5wolfxsui4ciujfucqwf6gqso4lettcjwl2tyismgol7c4tngvoono5rmytuqotye7oosfjv6g7a", @@ -138,7 +138,7 @@ export default class SystemPagePeersList extends React.Component { id: 982799203032, user: "@colin", img: - "https://hub.textile.io/ipfs/bafybeigxb4arecl6iwsvjnwzi2lqpmmif6l2kgwptac7q3tzqmsimci2yq", + "https://bafybeigxb4arecl6iwsvjnwzi2lqpmmif6l2kgwptac7q3tzqmsimci2yq.ipfs.hub.textile.io", info: { chainHead: "t3ual5q5qo5wolfxsui4ciujfucqwf6gqso4lettcjwl2tyismgol7c4tngvoono5rmytuqotye7oosfjv6g7a", @@ -152,7 +152,7 @@ export default class SystemPagePeersList extends React.Component { id: 673883729083, user: "@jason", img: - "https://hub.textile.io/ipfs/bafybeicp3x3poprnrsxhnqscsiuobxejxsbcsu2t4yhte6qmcofjvjqbn4", + "https://bafybeicp3x3poprnrsxhnqscsiuobxejxsbcsu2t4yhte6qmcofjvjqbn4.ipfs.hub.textile.io", info: { chainHead: "t3solnyrrblqlmvi6gmzewzvu62vs7uqvkl22yemzr63bcylbaaqsg44mnipepuafg7efzzx4zwcsi66jgze3q", diff --git a/pages/api/slates/add-url.js b/pages/api/slates/add-url.js index 283f88ce..3d0a09c7 100644 --- a/pages/api/slates/add-url.js +++ b/pages/api/slates/add-url.js @@ -1,4 +1,5 @@ import * as MW from "~/node_common/middleware"; +import { IPFS_GATEWAY_DOMAIN } from "~/node_common/constants"; import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; @@ -48,6 +49,7 @@ export default async (req, res) => { }); } + const cid = req.body.data.ipfs.replace('/ipfs/') const objects = [ ...slate.data.objects, { @@ -56,7 +58,7 @@ export default async (req, res) => { name: req.body.data.name, title: req.body.data.title, type: req.body.data.type, - url: `https://hub.textile.io${req.body.data.ipfs}`, + url: `https:${cid}.${IPFS_GATEWAY_DOMAIN}` }, ]; diff --git a/pages/api/v1/upload-data/[id].js b/pages/api/v1/upload-data/[id].js index ce319eff..39f8128f 100644 --- a/pages/api/v1/upload-data/[id].js +++ b/pages/api/v1/upload-data/[id].js @@ -1,5 +1,6 @@ import * as MW from "~/node_common/middleware"; import * as Data from "~/node_common/data"; +import { IPFS_GATEWAY_DOMAIN } from "~/node_common/constants"; import * as LibraryManager from "~/node_common/managers/library"; import * as Strings from "~/common/strings"; import * as Upload from "~/node_common/upload"; @@ -113,7 +114,8 @@ export default async (req, res) => { }); } - const url = `https://hub.textile.io${updatedData.ipfs}`; + const cid = req.body.data.ipfs.replace('/ipfs/') + const url = `https:${cid}.${IPFS_GATEWAY_DOMAIN}` const newSlateObjectEntity = { id: updatedData.id, name: updatedData.name, diff --git a/scenes/SceneEditAccount.js b/scenes/SceneEditAccount.js index 23866d20..6feffa98 100644 --- a/scenes/SceneEditAccount.js +++ b/scenes/SceneEditAccount.js @@ -1,6 +1,7 @@ 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 Validations from "~/common/validations"; import * as FileUtilities from "~/common/file-utilities"; @@ -63,9 +64,10 @@ export default class SceneEditAccount extends React.Component { return; } + const cid = json.data.ipfs.replace('/ipfs/', '') await Actions.updateViewer({ data: { - photo: `https://hub.textile.io${json.data.ipfs}`, + photo: `https://${cid}.${Constants.gateways.ipfs}`, body: this.state.body, name: this.state.name, }, diff --git a/scenes/SceneFile.js b/scenes/SceneFile.js index 1a74e08a..b4b8f5b4 100644 --- a/scenes/SceneFile.js +++ b/scenes/SceneFile.js @@ -69,7 +69,8 @@ const STYLES_PATH = css` export default class SceneFile extends React.Component { render() { - const fileURL = this.props.data.url ? this.props.data.url : `https://hub.textile.io${this.props.data.ipfs}`; + const cid = this.props.data.ipfs.replace('/ipfs/', '') + const fileURL = this.props.data.url ? this.props.data.url : `https://${cid}.${Constants.gateways.ipfs}`; return (
diff --git a/scenes/SceneSlate.js b/scenes/SceneSlate.js index bca2eaf6..f3ebd48d 100644 --- a/scenes/SceneSlate.js +++ b/scenes/SceneSlate.js @@ -141,8 +141,9 @@ export default class SceneSlate extends React.Component { name: "slate-global-create-carousel", detail: { slides: state.objects.map((each) => { - const cid = each.url.replace("https://hub.textile.io/ipfs/", ""); - + // NOTE + // regex here performs https://{cid}.ipfs.hub.textile.io => [https://{cid}, {cid}] + let cid = each.url.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/i)[1] return { onDelete: this._handleDelete, onObjectSave: this._handleObjectSave,