changed to accomodate new database changes

This commit is contained in:
Martina 2020-11-19 14:14:34 -08:00
parent 2919377e6d
commit 5de86b0708
12 changed files with 39 additions and 33 deletions

View File

@ -288,7 +288,7 @@ export default class CarouselSidebarData extends React.Component {
return;
}
const cid = json.data.ipfs.replace("/ipfs/", "");
const cid = json.data.cid || json.data.ipfs.replace("/ipfs/", "");
let updateReponse = await Actions.updateData({
data: {
id: this.props.data.id,

View File

@ -265,7 +265,8 @@ export default class DataView extends React.Component {
} else {
cids = Object.keys(this.state.checked).map((id) => {
let index = parseInt(id);
return this.props.viewer.library[0].children[index].ipfs.replace("/ipfs/", "");
let item = this.props.viewer.library[0].children[index];
return item.cid || item.ipfs.replace("/ipfs/", "");
});
}
this._handleLoading({ cids });
@ -535,7 +536,7 @@ export default class DataView extends React.Component {
{header}
<div css={STYLES_IMAGE_GRID}>
{this.props.items.slice(0, this.state.viewLimit).map((each, i) => {
const cid = each.ipfs.replace("/ipfs/", "");
const cid = each.cid || each.ipfs.replace("/ipfs/", "");
return (
<div
key={each.id}
@ -546,7 +547,7 @@ export default class DataView extends React.Component {
>
<SlateMediaObjectPreview
blurhash={each.blurhash}
url={`${Constants.gateways.ipfs}/${each.ipfs.replace("/ipfs/", "")}`}
url={Strings.getCIDGatewayURL(each.cid || each.ipfs.replace("/ipfs/", ""))}
title={each.file || each.name}
type={each.type || each.icon}
previewImage={each.previewImage}
@ -594,7 +595,7 @@ export default class DataView extends React.Component {
{
text: "Copy link",
onClick: (e) =>
this._handleCopy(e, `${Constants.gateways.ipfs}/${cid}`),
this._handleCopy(e, Strings.getCIDGatewayURL(cid)),
},
{
text: "Delete",
@ -695,7 +696,7 @@ export default class DataView extends React.Component {
},
];
const rows = this.props.items.slice(0, this.state.viewLimit).map((each, index) => {
const cid = each.ipfs.replace("/ipfs/", "");
const cid = each.cid || each.ipfs.replace("/ipfs/", "");
const isOnNetwork = each.networks && each.networks.includes("FILECOIN");
return {
@ -762,7 +763,7 @@ export default class DataView extends React.Component {
},
{
text: "Copy link",
onClick: (e) => this._handleCopy(e, `${Constants.gateways.ipfs}/${cid}`),
onClick: (e) => this._handleCopy(e, Strings.getCIDGatewayURL(cid)),
},
{
text: "Delete",

View File

@ -1,6 +1,7 @@
import * as React from "react";
import * as Constants from "~/common/constants";
import * as Validations from "~/common/validations";
import * as Strings from "~/common/strings";
import { css, keyframes } from "@emotion/core";
import { useState } from "react";
@ -53,7 +54,7 @@ export const FilePreviewBubble = (props) => {
</div>
{showPreview && (
<div css={STYLES_FILE_PREVIEW_BUBBLE}>
<img css={STYLES_FILE_PREVIEW} src={`${Constants.gateways.ipfs}/${props.url}`} />
<img css={STYLES_FILE_PREVIEW} src={Strings.getCIDGatewayURL(props.url)} />
</div>
)}
</React.Fragment>

View File

@ -72,7 +72,7 @@ export default class SidebarFileStorageDeal extends React.Component {
}
this.props.onSidebarLoading(true);
await this._handleMakeDeal({ ipfs: this.props.data.ipfs });
await this._handleMakeDeal({ ipfs: this.props.data.ipfs || `/ipfs/${this.props.data.cid}` });
await this.props.onSubmit({});
};

View File

@ -348,7 +348,7 @@ export class GlobalCarousel extends React.Component {
this.state.index < this.props.viewer.library[0].children.length
) {
data = this.props.viewer.library[0].children[this.state.index];
data.url = `${Constants.gateways.ipfs}/${data.cid || data.ipfs.replace("/ipfs/", "")}`;
data.url = Strings.getCIDGatewayURL(data.cid || data.ipfs.replace("/ipfs/", ""));
}
if (!data) {
this._handleClose();

View File

@ -34,7 +34,7 @@ export const createLocalDataIncomplete = ({ type, size, name }, id = null) => {
date: new Date(),
networks: [],
job: null,
ipfs: null,
cid: null,
storage: 0,
retrieval: 0,
};
@ -75,7 +75,7 @@ export const getDataByIPFS = (user, ipfs) => {
// TODO(jim): Totally purges the ID.
for (let i = 0; i < library.length; i++) {
for (let j = 0; j < library[i].children.length; j++) {
if (library[i].children[j].ipfs === ipfs) {
if (library[i].children[j].ipfs === ipfs || library[i].children[j].cid === ipfs) {
return library[i].children[j];
}
}
@ -89,12 +89,20 @@ export const addData = ({ user, files }) => {
// TODO(jim): Since we don't support bucket organization... yet.
// Add just pushes to the first set. But we can change this easily later.
let noRepeats = [...files];
let noRepeats = [];
for (let file of files) {
file.cid = file.ipfs.replace("/ipfs/", "");
delete file.ipfs;
noRepeats.push(file);
}
for (let i = 0; i < library.length; i++) {
let cids = library[i].children.map((file) => file.ipfs);
let cids = library[i].children.map((file) => file.cid || file.ipfs.replace("/ipfs/", ""));
for (let j = 0; j < files.length; j++) {
if (cids.includes(files[j].ipfs)) {
if (
(files[j].cid && cids.includes(files[j].cid)) ||
cids.includes(files[j].ipfs.replace("/ipfs/", ""))
) {
noRepeats[j] = null;
}
}

View File

@ -12,15 +12,11 @@ const check = async (PG, jobId) =>
export default async (req, res) => {
if (!req.body.data) {
return res
.status(500)
.send({ decorator: "SERVER_NO_CIDS_TO_CHECK", error: true });
return res.status(500).send({ decorator: "SERVER_NO_CIDS_TO_CHECK", error: true });
}
if (!req.body.data.length) {
return res
.status(500)
.send({ decorator: "SERVER_NO_CIDS_TO_CHECK", error: true });
return res.status(500).send({ decorator: "SERVER_NO_CIDS_TO_CHECK", error: true });
}
const id = Utilities.getIdFromCookie(req);
@ -80,7 +76,7 @@ export default async (req, res) => {
if (failed.length) {
for (let i = 0; i < failed.length; i++) {
let data = LibraryManager.getDataByIPFS(targetUser, failed[i].ipfs);
let data = LibraryManager.getDataByIPFS(targetUser, failed[i].ipfs || failed[i].cid);
if (!data) {
continue;
}
@ -100,7 +96,7 @@ export default async (req, res) => {
if (success.length) {
for (let i = 0; i < success.length; i++) {
let data = LibraryManager.getDataByIPFS(targetUser, success[i].ipfs);
let data = LibraryManager.getDataByIPFS(targetUser, success[i].ipfs || success[i].cid);
if (!data) {
continue;
}
@ -118,7 +114,7 @@ export default async (req, res) => {
if (reset.length) {
for (let i = 0; i < reset.length; i++) {
let data = LibraryManager.getDataByIPFS(targetUser, reset[i].ipfs);
let data = LibraryManager.getDataByIPFS(targetUser, reset[i].ipfs || reset[i].cid);
if (!data) {
continue;
}

View File

@ -41,8 +41,8 @@ export default async (req, res) => {
let cids = [];
let noRepeats = [];
for (let entry of pending) {
if (cids.includes(entry.data.ipfs)) continue;
cids.push(entry.data.ipfs);
if (cids.includes(entry.data.cid || entry.data.ipfs)) continue;
cids.push(entry.data.cid || entry.data.ipfs);
noRepeats.push(entry.data);
}

View File

@ -173,7 +173,7 @@ export default async (req, res) => {
...user.data.library[0],
children: user.data.library[0].children.filter((o) => {
for (let cid of req.body.data.cids) {
if (o.ipfs.includes(cid)) {
if ((o.ipfs && o.ipfs.includes(cid)) || (o.cid && o.cid === cid)) {
return false;
}
}

View File

@ -67,19 +67,19 @@ export default async (req, res) => {
let newIPFSs = [];
addlObjects = newObjects.filter((each) => {
if (
slateURLs.includes(`${Constants.IPFS_GATEWAY_URL}/${each.ipfs.replace("/ipfs/", "")}`) ||
newIPFSs.includes(each.ipfs)
slateURLs.includes(Strings.getCIDGatewayURL(each.cid || each.ipfs.replace("/ipfs/", ""))) ||
newIPFSs.includes(each.cid || each.ipfs)
) {
return false;
}
newIPFSs.push(each.ipfs);
newIPFSs.push(each.cid || each.ipfs);
return true;
});
}
addlObjects = addlObjects.map((each) => {
let url = each.ipfs
? `${Constants.IPFS_GATEWAY_URL}/${each.ipfs.replace("/ipfs/", "")}`
? Strings.getCIDGatewayURL(each.cid || each.ipfs.replace("/ipfs/", ""))
: each.url;
let cid = each.url
? Strings.urlToCid(each.url)

View File

@ -110,7 +110,7 @@ export default class SceneEditAccount extends React.Component {
const { json } = response;
const cid = json.data.ipfs.replace("/ipfs/", "");
const cid = json.data.cid || json.data.ipfs.replace("/ipfs/", "");
const url = Strings.getCIDGatewayURL(cid);
let updateResponse = await Actions.updateViewer({
data: {

View File

@ -70,7 +70,7 @@ const STYLES_PATH = css`
export default class SceneFile extends React.Component {
render() {
const cid = this.props.data.ipfs.replace("/ipfs/", "");
const cid = this.props.data.cid || this.props.data.ipfs.replace("/ipfs/", "");
const fileURL = Strings.getCIDGatewayURL(cid);
return (