Merge pull request #178 from filecoin-project/andrew/skip-subdomain-redirect

feat(api): skip ipfs subdomain redirect
This commit is contained in:
CAKE 2020-08-25 10:53:15 -07:00 committed by GitHub
commit eea2a2f866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 36 additions and 22 deletions

View File

@ -60,3 +60,7 @@ export const theme = {
pageBackground: system.foreground,
pageText: system.black,
};
export const gateways = {
ipfs: "ipfs.slate.textile.io",
}

View File

@ -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 = <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://hub.textile.io/ipfs/${this.props.cid}`}
href={`https://${this.props.cid}.${Constants.gateways.ipfs}`}
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://hub.textile.io/ipfs/${this.props.cid}`}
href={`https://${this.props.cid}.${Constants.gateways.ipfs}`}
target="_blank"
download={this.props.cid}
>

View File

@ -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};

View File

@ -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/";

View File

@ -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",

View File

@ -14,13 +14,13 @@ const friendsList = {
id: 72572959238,
user: "@martina",
img:
"https://hub.textile.io/ipfs/bafybeiguo2uhd63reslbqkkgsqedgeikhtuwn5lzqpnqzluoaa3rnkfcvi",
"https://bafybeiguo2uhd63reslbqkkgsqedgeikhtuwn5lzqpnqzluoaa3rnkfcvi.ipfs.slate.textile.io",
},
{
id: 2572952030,
user: "@jim",
img:
"https://hub.textile.io/ipfs/bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu",
"https://bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu.ipfs.slate.textile.io",
},
],
friends: [
@ -41,7 +41,7 @@ const friendsList = {
id: 637838385993,
user: "@aaron",
img:
"https://hub.textile.io/ipfs/bafkreicb2lookm56omsfjwuwuziwftizmdsj4oneveuqiqlu6k5hc7j5nq",
"https://bafkreicb2lookm56omsfjwuwuziwftizmdsj4oneveuqiqlu6k5hc7j5nq.ipfs.slate.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.slate.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.slate.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.slate.textile.io",
},
{
id: 2572952030,
user: "@jim",
img:
"https://hub.textile.io/ipfs/bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu",
"https://bafybeicuz5wrxonu7ud6eskrnshxb66ksg3ncu3ie776xuiydlxrkfuvmu.ipfs.slate.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.slate.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.slate.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.slate.textile.io",
info: {
chainHead:
"t3solnyrrblqlmvi6gmzewzvu62vs7uqvkl22yemzr63bcylbaaqsg44mnipepuafg7efzzx4zwcsi66jgze3q",

View File

@ -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}`
},
];

View File

@ -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,

View File

@ -107,7 +107,7 @@ const STYLES_LINK = css`
export const getServerSideProps = async (context) => {
let buckets = false;
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",

View File

@ -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,
},

View File

@ -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 (
<div css={STYLES_FLEX}>

View File

@ -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.slate.textile.io => [https://{cid}, {cid}]
let cid = each.url.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/i)[1]
return {
onDelete: this._handleDelete,
onObjectSave: this._handleObjectSave,