added endpoint for updating file

This commit is contained in:
Martina 2020-11-15 16:29:13 -08:00 committed by tarafanlin
parent 4cd780391e
commit d5eb844c99
9 changed files with 77 additions and 7 deletions

View File

@ -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) => { export const deleteBucketItems = async (data) => {
return await returnJSON(`/api/data/remove`, { return await returnJSON(`/api/data/remove`, {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,

View File

@ -977,6 +977,7 @@ export default class ApplicationPage extends React.Component {
{scene} {scene}
</ApplicationLayout> </ApplicationLayout>
<System.GlobalCarousel <System.GlobalCarousel
resources={this.props.resources}
viewer={this.state.viewer} viewer={this.state.viewer}
current={ current={
current.target && current.target &&

View File

@ -51,13 +51,9 @@ const STYLES_SIDEBAR = css`
flex-direction: column; flex-direction: column;
align-items: flex-start; align-items: flex-start;
justify-content: space-between; justify-content: space-between;
position: relative;
background-color: rgba(20, 20, 20, 0.8); background-color: rgba(20, 20, 20, 0.8);
${STYLES_NO_VISIBLE_SCROLL}
@supports ( @supports ((-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))) {
(-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))
) {
-webkit-backdrop-filter: blur(75px); -webkit-backdrop-filter: blur(75px);
backdrop-filter: blur(75px); backdrop-filter: blur(75px);
background-color: rgba(150, 150, 150, 0.2); background-color: rgba(150, 150, 150, 0.2);

View File

@ -460,7 +460,6 @@ export default class DataView extends React.Component {
render() { render() {
let numChecked = Object.keys(this.state.checked).length || 0; let numChecked = Object.keys(this.state.checked).length || 0;
console.log(this.props.items.blurhash);
const header = ( const header = (
<div css={STYLES_HEADER_LINE}> <div css={STYLES_HEADER_LINE}>
<TabGroup disabled tabs={["Uploads"]} style={{ margin: 0 }} /> <TabGroup disabled tabs={["Uploads"]} style={{ margin: 0 }} />

View File

@ -99,7 +99,6 @@ export default class SlateMediaObjectPreview extends React.Component {
if (this.props.type && Validations.isPreviewableImage(this.props.type)) { if (this.props.type && Validations.isPreviewableImage(this.props.type)) {
let blurhash = this.props.blurhash && isBlurhashValid(this.props.blurhash); let blurhash = this.props.blurhash && isBlurhashValid(this.props.blurhash);
console.log("check");
if (this.props.centeredImage) { if (this.props.centeredImage) {
return ( return (
<React.Fragment> <React.Fragment>

View File

@ -414,6 +414,7 @@ export class GlobalCarousel extends React.Component {
loading={this.state.loading} loading={this.state.loading}
slates={this.props.slates} slates={this.props.slates}
onAction={this.props.onAction} onAction={this.props.onAction}
resources={this.props.resources}
data={data} data={data}
cid={data.cid} cid={data.cid}
/> />

View File

@ -114,3 +114,15 @@ export const addData = ({ user, files }) => {
skipped: files.length - noRepeats.length, 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
View 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: {},
});
};

View File

@ -105,6 +105,7 @@ export default async (req, res) => {
return { return {
blurhash: each.blurhash, blurhash: each.blurhash,
previewImage: each.previewImage,
cid: cid, cid: cid,
size: each.size, size: each.size,
id: each.id, id: each.id,