mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-23 00:51:32 +03:00
uploads: supports IPFS bucket uploads
This commit is contained in:
parent
dc5f3313ec
commit
7b7245a74f
@ -73,8 +73,6 @@ export const getInitialState = (props) => {
|
|||||||
username,
|
username,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
console.log({ getInitialState: props });
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: info.id,
|
id: info.id,
|
||||||
username,
|
username,
|
||||||
|
@ -43,20 +43,6 @@ const STYLES_IMAGE_PREVIEW = css`
|
|||||||
margin-top: 48px;
|
margin-top: 48px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const SELECT_MENU_OPTIONS = [
|
|
||||||
{ value: "1", name: "Anywhere" },
|
|
||||||
{ value: "2", name: "China" },
|
|
||||||
{ value: "3", name: "Russia" },
|
|
||||||
{ value: "4", name: "USA" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const SELECT_MENU_MAP = {
|
|
||||||
"1": "Anywhere",
|
|
||||||
"2": "China",
|
|
||||||
"3": "Russia",
|
|
||||||
"4": "USA",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default class SidebarFileStorageDeal extends React.Component {
|
export default class SidebarFileStorageDeal extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
settings_cold_default_duration: this.props.viewer
|
settings_cold_default_duration: this.props.viewer
|
||||||
|
@ -32,6 +32,7 @@ const RETRIEVAL_DEAL_STATES = {
|
|||||||
|
|
||||||
const COMPONENTS_ICON = {
|
const COMPONENTS_ICON = {
|
||||||
PNG: <SVG.FileImage height="24px" />,
|
PNG: <SVG.FileImage height="24px" />,
|
||||||
|
["image/png"]: <SVG.FileImage height="24px" />,
|
||||||
FOLDER: <OldSVG.Folder height="24px" />,
|
FOLDER: <OldSVG.Folder height="24px" />,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,12 +1,4 @@
|
|||||||
import path from "path";
|
|
||||||
|
|
||||||
export const POLLING_RATE = 5000;
|
export const POLLING_RATE = 5000;
|
||||||
export const POWERGATE_HOST = "http://pow.slate.textile.io:6002";
|
export const POWERGATE_HOST = "http://pow.slate.textile.io:6002";
|
||||||
|
export const FILE_STORAGE_URL = "./public/static/files/";
|
||||||
export const AVATAR_STORAGE_URL = path.join(
|
|
||||||
__dirname,
|
|
||||||
"../public/static/system/"
|
|
||||||
);
|
|
||||||
export const FILE_STORAGE_URL = path.join(__dirname, "../public/static/files/");
|
|
||||||
|
|
||||||
export const GITHUB_URL = "https://github.com/filecoin-project/filecoin-client";
|
export const GITHUB_URL = "https://github.com/filecoin-project/filecoin-client";
|
||||||
|
@ -24,8 +24,6 @@ export const getUserFromCookie = (req) => {
|
|||||||
"$1"
|
"$1"
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log({ token });
|
|
||||||
|
|
||||||
if (!Strings.isEmpty(token)) {
|
if (!Strings.isEmpty(token)) {
|
||||||
try {
|
try {
|
||||||
const decoded = JWT.verify(token, Environment.JWT_SECRET);
|
const decoded = JWT.verify(token, Environment.JWT_SECRET);
|
||||||
@ -82,10 +80,6 @@ export const refresh = async ({ PG }) => {
|
|||||||
const Peers = await PG.net.peers();
|
const Peers = await PG.net.peers();
|
||||||
const peersList = Peers.peersList ? Peers.peersList : null;
|
const peersList = Peers.peersList ? Peers.peersList : null;
|
||||||
|
|
||||||
console.log({ status });
|
|
||||||
console.log({ messageList });
|
|
||||||
console.log({ peersList });
|
|
||||||
|
|
||||||
return { peersList, messageList, status };
|
return { peersList, messageList, status };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,9 +91,6 @@ export const refreshWithToken = async ({ PG }) => {
|
|||||||
const NetworkInfo = await PG.ffs.info();
|
const NetworkInfo = await PG.ffs.info();
|
||||||
const info = NetworkInfo.info ? NetworkInfo.info : null;
|
const info = NetworkInfo.info ? NetworkInfo.info : null;
|
||||||
|
|
||||||
console.log({ addrsList });
|
|
||||||
console.log({ info });
|
|
||||||
|
|
||||||
return { addrsList, info };
|
return { addrsList, info };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
81
pages/api/data/[upload].js
Normal file
81
pages/api/data/[upload].js
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import * as MW from "~/node_common/middleware";
|
||||||
|
import * as Constants from "~/node_common/constants";
|
||||||
|
import * as Data from "~/node_common/data";
|
||||||
|
import * as Utilities from "~/node_common/utilities";
|
||||||
|
|
||||||
|
import FORM from "formidable";
|
||||||
|
import FS from "fs-extra";
|
||||||
|
|
||||||
|
const initCORS = MW.init(MW.CORS);
|
||||||
|
const initAuth = MW.init(MW.RequireCookieAuthentication);
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
api: {
|
||||||
|
bodyParser: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async (req, res) => {
|
||||||
|
initCORS(req, res);
|
||||||
|
initAuth(req, res);
|
||||||
|
|
||||||
|
const f = new FORM.IncomingForm();
|
||||||
|
f.uploadDir = Constants.FILE_STORAGE_URL;
|
||||||
|
f.keepExtensions = true;
|
||||||
|
f.parse(req, async (e, fields, files) => {
|
||||||
|
if (e) {
|
||||||
|
return res.status(500).send({ decorator: "SERVER_UPLOAD", error: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!files.image) {
|
||||||
|
return res.status(500).send({ decorator: "SERVER_UPLOAD", error: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = files.image;
|
||||||
|
const data = {
|
||||||
|
decorator: "FILE",
|
||||||
|
icon: file.type,
|
||||||
|
size: file.size,
|
||||||
|
name: file.name,
|
||||||
|
file: file.name,
|
||||||
|
type: file.type,
|
||||||
|
path: file._writeStream.path,
|
||||||
|
date: new Date(),
|
||||||
|
storage_status: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO(jim): Send this file to buckets.
|
||||||
|
const username = Utilities.getUserFromCookie(req);
|
||||||
|
const user = await Data.getUserByUsername({
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
buckets,
|
||||||
|
bucketKey,
|
||||||
|
bucketName,
|
||||||
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api);
|
||||||
|
|
||||||
|
// NOTE(jim): Push pathPath to your bucket.
|
||||||
|
const readFile = await FS.readFileSync(data.path).buffer;
|
||||||
|
const push = await buckets.pushPath(bucketKey, file.name, readFile);
|
||||||
|
data.ipfs = push.path.path;
|
||||||
|
data.id = data.ipfs;
|
||||||
|
|
||||||
|
user.data.library[0].children.push(data);
|
||||||
|
|
||||||
|
// TODO(jim): Update library on user.
|
||||||
|
const response = await Data.updateUserById({
|
||||||
|
id: user.id,
|
||||||
|
data: { ...user.data },
|
||||||
|
});
|
||||||
|
|
||||||
|
// NOTE(jim): Remove the file when you're done with it.
|
||||||
|
await FS.unlinkSync(`./${data.path}`);
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
decorator: "SERVER_UPLOAD",
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
19
pages/api/data/get.js
Normal file
19
pages/api/data/get.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import * as MW from "~/node_common/middleware";
|
||||||
|
import * as Constants from "~/node_common/constants";
|
||||||
|
import * as Data from "~/node_common/data";
|
||||||
|
import * as Utilities from "~/node_common/utilities";
|
||||||
|
|
||||||
|
import FS from "fs-extra";
|
||||||
|
|
||||||
|
const initCORS = MW.init(MW.CORS);
|
||||||
|
|
||||||
|
export default async (req, res) => {
|
||||||
|
initCORS(req, res);
|
||||||
|
|
||||||
|
const { buckets } = await Utilities.getBucketAPI();
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
decorator: "SERVER_GET",
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
};
|
@ -63,28 +63,10 @@ export default async (req, res) => {
|
|||||||
photo: null,
|
photo: null,
|
||||||
settings_deals_auto_approve: false,
|
settings_deals_auto_approve: false,
|
||||||
tokens: { pg, api },
|
tokens: { pg, api },
|
||||||
// TODO(jim):
|
|
||||||
// Get rid of this after the refactor.
|
|
||||||
library: [
|
library: [
|
||||||
{
|
{
|
||||||
...Utilities.createFolder({ id: bucketName, name: "Data" }),
|
...Utilities.createFolder({ id: bucketName, name: "Data" }),
|
||||||
children: [
|
children: [],
|
||||||
await Utilities.addFileFromFilePath({
|
|
||||||
buckets,
|
|
||||||
bucketKey,
|
|
||||||
filePath: "./public/static/social.jpg",
|
|
||||||
}),
|
|
||||||
await Utilities.addFileFromFilePath({
|
|
||||||
buckets,
|
|
||||||
bucketKey,
|
|
||||||
filePath: "./public/static/cube_000.jpg",
|
|
||||||
}),
|
|
||||||
await Utilities.addFileFromFilePath({
|
|
||||||
buckets,
|
|
||||||
bucketKey,
|
|
||||||
filePath: "./public/static/cube_f7f7f7.jpg",
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -115,7 +115,7 @@ export default class ApplicationPage extends React.Component {
|
|||||||
body: data,
|
body: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(`/_/storage/${file.name}`, options);
|
const response = await fetch(`/api/data/${file.name}`, options);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
if (json && json.success) {
|
if (json && json.success) {
|
||||||
|
0
public/static/files/.gitkeep
Normal file
0
public/static/files/.gitkeep
Normal file
@ -116,8 +116,11 @@ export default class SceneFile extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const fileName = this.props.file.file;
|
console.log(this.props.file);
|
||||||
const fileURL = `data:image/png;base64,${this.props.file.file_data}`;
|
const { file } = this.props;
|
||||||
|
|
||||||
|
const fileName = `${file.name}`;
|
||||||
|
const fileURL = ``;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div css={STYLES_FLEX}>
|
<div css={STYLES_FLEX}>
|
||||||
|
Loading…
Reference in New Issue
Block a user