mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 17:44:50 +03:00
added endpoint for updating file
This commit is contained in:
parent
4cd780391e
commit
d5eb844c99
@ -259,6 +259,13 @@ export const addCIDToData = async (data) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const updateData = async (data) => {
|
||||
return await returnJSON(`/api/data/update`, {
|
||||
...DEFAULT_OPTIONS,
|
||||
body: JSON.stringify({ data }),
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteBucketItems = async (data) => {
|
||||
return await returnJSON(`/api/data/remove`, {
|
||||
...DEFAULT_OPTIONS,
|
||||
|
@ -977,6 +977,7 @@ export default class ApplicationPage extends React.Component {
|
||||
{scene}
|
||||
</ApplicationLayout>
|
||||
<System.GlobalCarousel
|
||||
resources={this.props.resources}
|
||||
viewer={this.state.viewer}
|
||||
current={
|
||||
current.target &&
|
||||
|
@ -51,13 +51,9 @@ const STYLES_SIDEBAR = css`
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
background-color: rgba(20, 20, 20, 0.8);
|
||||
${STYLES_NO_VISIBLE_SCROLL}
|
||||
|
||||
@supports (
|
||||
(-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))
|
||||
) {
|
||||
@supports ((-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))) {
|
||||
-webkit-backdrop-filter: blur(75px);
|
||||
backdrop-filter: blur(75px);
|
||||
background-color: rgba(150, 150, 150, 0.2);
|
||||
|
@ -460,7 +460,6 @@ export default class DataView extends React.Component {
|
||||
|
||||
render() {
|
||||
let numChecked = Object.keys(this.state.checked).length || 0;
|
||||
console.log(this.props.items.blurhash);
|
||||
const header = (
|
||||
<div css={STYLES_HEADER_LINE}>
|
||||
<TabGroup disabled tabs={["Uploads"]} style={{ margin: 0 }} />
|
||||
|
@ -99,7 +99,6 @@ export default class SlateMediaObjectPreview extends React.Component {
|
||||
|
||||
if (this.props.type && Validations.isPreviewableImage(this.props.type)) {
|
||||
let blurhash = this.props.blurhash && isBlurhashValid(this.props.blurhash);
|
||||
console.log("check");
|
||||
if (this.props.centeredImage) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
@ -414,6 +414,7 @@ export class GlobalCarousel extends React.Component {
|
||||
loading={this.state.loading}
|
||||
slates={this.props.slates}
|
||||
onAction={this.props.onAction}
|
||||
resources={this.props.resources}
|
||||
data={data}
|
||||
cid={data.cid}
|
||||
/>
|
||||
|
@ -114,3 +114,15 @@ export const addData = ({ user, files }) => {
|
||||
skipped: files.length - noRepeats.length,
|
||||
};
|
||||
};
|
||||
|
||||
export const editItem = ({ user, update }) => {
|
||||
const { library } = user.data;
|
||||
|
||||
for (let i = 0; i < library[0].children.length; i++) {
|
||||
if (library[0].children[i].id === update.id) {
|
||||
library[0].children[i] = { ...library[0].children[i], ...update };
|
||||
break;
|
||||
}
|
||||
}
|
||||
return user.data;
|
||||
};
|
||||
|
54
pages/api/data/update.js
Normal file
54
pages/api/data/update.js
Normal file
@ -0,0 +1,54 @@
|
||||
import * as Data from "~/node_common/data";
|
||||
import * as Utilities from "~/node_common/utilities";
|
||||
import * as LibraryManager from "~/node_common/managers/library";
|
||||
|
||||
export default async (req, res) => {
|
||||
const id = Utilities.getIdFromCookie(req);
|
||||
if (!id) {
|
||||
return res.status(500).send({ decorator: "SERVER_EDIT_DATA", error: true });
|
||||
}
|
||||
|
||||
const user = await Data.getUserById({ id });
|
||||
|
||||
if (!user || user.error) {
|
||||
return res.status(403).send({ decorator: "SERVER_EDIT_DATA_USER_NOT_FOUND", error: true });
|
||||
}
|
||||
|
||||
let newUserData = LibraryManager.editItem({ user, update: req.body.data.update });
|
||||
let response = await Data.updateUserById({
|
||||
id: user.id,
|
||||
data: newUserData,
|
||||
});
|
||||
|
||||
if (!response || response.error) {
|
||||
return res.status(500).send({ decorator: "SERVER_EDIT_DATA_NOT_UPDATED", error: true });
|
||||
}
|
||||
|
||||
let slates = await Data.getSlatesByUserId({ userId: id });
|
||||
for (let slate of slates) {
|
||||
let edited = false;
|
||||
let objects = slate.data.objects.map((obj) => {
|
||||
if (obj.id === req.body.data.update.id) {
|
||||
edited = true;
|
||||
obj = { ...obj, ...req.body.data.update };
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
|
||||
if (edited) {
|
||||
await Data.updateSlateById({
|
||||
id: slate.id,
|
||||
updated_at: new Date(),
|
||||
data: {
|
||||
...slate.data,
|
||||
objects,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(200).send({
|
||||
decorator: "SERVER_EDIT_DATA",
|
||||
data: {},
|
||||
});
|
||||
};
|
@ -105,6 +105,7 @@ export default async (req, res) => {
|
||||
|
||||
return {
|
||||
blurhash: each.blurhash,
|
||||
previewImage: each.previewImage,
|
||||
cid: cid,
|
||||
size: each.size,
|
||||
id: each.id,
|
||||
|
Loading…
Reference in New Issue
Block a user