mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-11 22:07:08 +03:00
converted api endpoints to new data structure
This commit is contained in:
parent
3b7a0b89f5
commit
05b12828ef
@ -60,11 +60,11 @@ export default async (req, res) => {
|
||||
|
||||
const filename = Strings.createSlug(data.title);
|
||||
|
||||
const domain = LinkUtilities.getDomainFromURL(url);
|
||||
const linkDomain = LinkUtilities.getDomainFromURL(url);
|
||||
|
||||
const html = await LinkUtilities.fetchEmbed(url);
|
||||
const linkHtml = await LinkUtilities.fetchEmbed(url);
|
||||
|
||||
const iFrameAllowed = await LinkUtilities.testIframe(url);
|
||||
const linkIFrameAllowed = await LinkUtilities.testIframe(url);
|
||||
|
||||
const newFile = {
|
||||
filename,
|
||||
@ -82,9 +82,9 @@ export default async (req, res) => {
|
||||
linkAuthor: data.author,
|
||||
linkImage: data.image?.url,
|
||||
linkFavicon: data.logo?.url,
|
||||
linkDomain: domain,
|
||||
linkHtml: html,
|
||||
linkIFrameAllowed: iFrameAllowed,
|
||||
linkDomain,
|
||||
linkHtml,
|
||||
linkIFrameAllowed,
|
||||
};
|
||||
|
||||
files.push(newFile);
|
||||
|
@ -84,8 +84,8 @@ export default async (req, res) => {
|
||||
let cids = Arrays.mapToCids(files);
|
||||
let coverImageCids = [];
|
||||
for (let obj of objects) {
|
||||
if (obj.data.coverImage?.cid) {
|
||||
coverImageCids.push(obj.data.coverImage.cid);
|
||||
if (obj.coverImage?.cid) {
|
||||
coverImageCids.push(obj.coverImage.cid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,8 @@ export default async (req, res) => {
|
||||
|
||||
filteredFiles = filteredFiles
|
||||
.filter((file) => foundCids.includes(file.cid)) //NOTE(martina): make sure the file being copied exists
|
||||
.map(({ createdAt, downloadCount, saveCount, tags, ...keepAttrs }) => {
|
||||
//NOTE(martina): remove the old file's id, ownerId, createdAt, and privacy so new fields can be used
|
||||
.map(({ createdAt, ownerId, isPublic, downloadCount, saveCount, tags, ...keepAttrs }) => {
|
||||
//NOTE(martina): remove the old file's ownerId, createdAt, counts, tags, and privacy so new fields can be used
|
||||
return { ...keepAttrs, isPublic: slate?.isPublic || false };
|
||||
});
|
||||
|
||||
@ -70,7 +70,7 @@ export default async (req, res) => {
|
||||
continue;
|
||||
}
|
||||
|
||||
const { id, ...rest } = file;
|
||||
const { id, ...rest } = file; //NOTE(martina): remove the old file's id
|
||||
let response = await Utilities.addExistingCIDToData({
|
||||
buckets,
|
||||
key: bucketKey,
|
||||
@ -122,25 +122,3 @@ export default async (req, res) => {
|
||||
data: { added, skipped: files.length - added },
|
||||
});
|
||||
};
|
||||
|
||||
// const addToSlate = async ({ slate, files, user }) => {
|
||||
// let { filteredFiles } = await ArrayUtilities.removeDuplicateSlateFiles({
|
||||
// files,
|
||||
// slate,
|
||||
// });
|
||||
|
||||
// if (!filteredFiles.length) {
|
||||
// return { added: 0 };
|
||||
// }
|
||||
|
||||
// let response = await Data.createSlateFiles({ owner: user, slate, files: filteredFiles });
|
||||
// if (!response || response.error) {
|
||||
// return { decorator: "SERVER_SAVE_COPY_ADD_TO_SLATE_FAILED", added: 0 };
|
||||
// }
|
||||
|
||||
// Monitor.saveCopy({ user, slate, files: filteredFiles });
|
||||
|
||||
// await Data.updateSlateById({ id: slate.id, updatedAt: new Date() });
|
||||
|
||||
// return { added: response.length };
|
||||
// };
|
||||
|
@ -39,9 +39,6 @@ export default async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// keys = await Data.getAPIKeysByUserId({ userId: user.id });
|
||||
// ViewerManager.hydratePartialKeys(keys, user.id);
|
||||
|
||||
ViewerManager.hydratePartial(id, { keys: true });
|
||||
|
||||
return res.status(200).send({ decorator: "SERVER_GENERATE_API_KEY", key });
|
||||
|
@ -50,8 +50,8 @@ export default async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (updates.data.name && updates.data.name !== slate.data.name) {
|
||||
if (!Validations.slatename(slate.data.name)) {
|
||||
if (updates.name && updates.name !== slate.name) {
|
||||
if (!Validations.slatename(slate.name)) {
|
||||
return res.status(400).send({
|
||||
decorator: "SERVER_UPDATE_SLATE_INVALID_NAME",
|
||||
error: true,
|
||||
@ -59,7 +59,7 @@ export default async (req, res) => {
|
||||
}
|
||||
|
||||
const existingSlate = await Data.getSlateByName({
|
||||
slatename: updates.data.name,
|
||||
slatename: updates.name,
|
||||
ownerId: user.id,
|
||||
});
|
||||
|
||||
@ -69,7 +69,7 @@ export default async (req, res) => {
|
||||
error: true,
|
||||
});
|
||||
} else {
|
||||
updates.slatename = Strings.createSlug(updates.data.name);
|
||||
updates.slatename = Strings.createSlug(updates.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,13 +91,8 @@ export default async (req, res) => {
|
||||
await Data.updateUserById({
|
||||
id: userByEmail.id,
|
||||
twitterId: twitterUser.id_str,
|
||||
data: {
|
||||
...userByEmail.data,
|
||||
twitter: {
|
||||
username: twitterUser.screen_name,
|
||||
verified: twitterUser.verified,
|
||||
},
|
||||
},
|
||||
twitterUsername: twitterUser.screen_name,
|
||||
twitterVerified: twitterUser.verified,
|
||||
});
|
||||
const token = JWT.sign(
|
||||
{ id: userByEmail.id, username: userByEmail.username },
|
||||
|
@ -11,17 +11,20 @@ export default async (req, res) => {
|
||||
const { id, user } = userInfo;
|
||||
|
||||
// NOTE(jim): remove their public slates and files from the search cache.
|
||||
let slates = await Data.getSlatesByUserId({ ownerId: user.id, publicOnly: true });
|
||||
let slates = await Data.getSlatesByUserId({ ownerId: id, publicOnly: true });
|
||||
SearchManager.updateSlate(slates, "REMOVE");
|
||||
|
||||
let files = await Data.getFilesByUserId({ id: user.id, publicOnly: true });
|
||||
let files = await Data.getFilesByUserId({ id, publicOnly: true });
|
||||
SearchManager.updateFile(files, "REMOVE");
|
||||
|
||||
//NOTE(migration): may be able to just condense these two parts since they return it from delete anyways
|
||||
// NOTE(jim): delete all of their public and private slates.
|
||||
await Data.deleteSlatesByUserId({ ownerId: user.id });
|
||||
slates = await Data.deleteSlatesByUserId({ ownerId: id });
|
||||
console.log({ slates });
|
||||
|
||||
// NOTE(martina): delete all of their public and private files.
|
||||
await Data.deleteFilesByUserId({ ownerId: user.id });
|
||||
files = await Data.deleteFilesByUserId({ ownerId: id });
|
||||
console.log({ files });
|
||||
|
||||
const defaultData = await Utilities.getBucketAPIFromUserToken({ user });
|
||||
|
||||
|
@ -32,26 +32,6 @@ export default async (req, res) => {
|
||||
error: true,
|
||||
});
|
||||
}
|
||||
} else if (req.body.data?.status) {
|
||||
let status = user.data.status;
|
||||
if (!status) {
|
||||
status = {};
|
||||
}
|
||||
for (let [key, value] of Object.entries(req.body.data.status)) {
|
||||
status[key] = value;
|
||||
}
|
||||
|
||||
updateResponse = await Data.updateUserById({
|
||||
id: user.id,
|
||||
data: { status },
|
||||
});
|
||||
|
||||
if (!updateResponse || updateResponse.error) {
|
||||
return res.status(404).send({
|
||||
decorator: "SERVER_STATUS_UPDATE_FAILED",
|
||||
error: true,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
decorator: "SERVER_STATUS_UPDATE_MUST_PROVIDE_UPDATE",
|
||||
|
@ -115,8 +115,8 @@ export default async (req, res) => {
|
||||
if (unsafeResponse && !unsafeResponse.error) {
|
||||
if (
|
||||
user.username !== unsafeResponse.username ||
|
||||
user.data.name !== unsafeResponse.data.name ||
|
||||
user.data.photo !== unsafeResponse.data.photo
|
||||
user.name !== unsafeResponse.name ||
|
||||
user.photo !== unsafeResponse.photo
|
||||
) {
|
||||
SearchManager.updateUser(unsafeResponse, "EDIT");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user