diff --git a/pages/api/data/create-link.js b/pages/api/data/create-link.js index 07ac9c72..86073097 100644 --- a/pages/api/data/create-link.js +++ b/pages/api/data/create-link.js @@ -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); diff --git a/pages/api/data/delete.js b/pages/api/data/delete.js index 9e3867ae..2d052ca9 100644 --- a/pages/api/data/delete.js +++ b/pages/api/data/delete.js @@ -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); } } diff --git a/pages/api/data/save-copy.js b/pages/api/data/save-copy.js index 8fa8914b..b64a9c53 100644 --- a/pages/api/data/save-copy.js +++ b/pages/api/data/save-copy.js @@ -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 }; -// }; diff --git a/pages/api/keys/generate.js b/pages/api/keys/generate.js index cd4db90c..381059a5 100644 --- a/pages/api/keys/generate.js +++ b/pages/api/keys/generate.js @@ -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 }); diff --git a/pages/api/slates/update.js b/pages/api/slates/update.js index bbe0dcbc..afe631e1 100644 --- a/pages/api/slates/update.js +++ b/pages/api/slates/update.js @@ -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); } } diff --git a/pages/api/twitter/authenticate.js b/pages/api/twitter/authenticate.js index 5afbfe83..8a8ed562 100644 --- a/pages/api/twitter/authenticate.js +++ b/pages/api/twitter/authenticate.js @@ -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 }, diff --git a/pages/api/users/delete.js b/pages/api/users/delete.js index f4c3660a..d835a98d 100644 --- a/pages/api/users/delete.js +++ b/pages/api/users/delete.js @@ -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 }); diff --git a/pages/api/users/status-update.js b/pages/api/users/status-update.js index 95675372..57ae6cba 100644 --- a/pages/api/users/status-update.js +++ b/pages/api/users/status-update.js @@ -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", diff --git a/pages/api/users/update.js b/pages/api/users/update.js index 058d92a7..2c14dc6a 100644 --- a/pages/api/users/update.js +++ b/pages/api/users/update.js @@ -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"); }