From 387045082cbb6002008bc88b50b0c6caa42748f0 Mon Sep 17 00:00:00 2001 From: Martina Date: Fri, 11 Jun 2021 12:25:58 -0700 Subject: [PATCH] adding Logging function and converting console.log to Logging.log --- common/browser-websockets.js | 21 ++--- common/custom-events.js | 4 - common/file-utilities.js | 10 +-- common/hooks.js | 9 ++- .../node-logging.js => common/logging.js | 13 ++-- common/user-behaviors.js | 1 - components/core/Application.js | 13 ++-- components/core/CarouselSidebar.js | 2 +- components/core/DataView.js | 1 - components/core/Link.js | 3 +- components/core/SearchModal.js | 12 +-- components/core/SlateLayout.js | 1 - components/core/SlateMediaObjectPreview.js | 4 +- components/sidebars/SidebarFileStorageDeal.js | 3 - components/stats/CreateChart.js | 1 - components/system/components/ListEditor.js | 5 +- components/system/components/Table.js | 3 +- components/system/components/Tag.js | 5 +- .../components/fragments/GlobalTooltip.js | 13 ---- .../system/modules/FilecoinDealsList.js | 2 - node_common/array-utilities.js | 3 +- .../data/methods/delete-files-by-ids.js | 6 -- node_common/data/methods/get-activity.js | 4 +- .../data/methods/get-api-keys-by-user-id.js | 4 +- node_common/data/methods/get-every-file.js | 3 +- node_common/data/methods/get-every-slate.js | 3 +- node_common/data/methods/get-every-user.js | 3 +- node_common/data/methods/get-explore.js | 4 +- .../data/methods/get-followers-by-user-id.js | 7 +- .../data/methods/get-following-by-user-id.js | 7 +- .../data/methods/get-likes-by-user-id.js | 3 +- .../data/methods/get-slates-by-user-id.js | 3 +- .../methods/get-subscribers-by-slate-id.js | 3 +- .../methods/get-subscriptions-by-user-id.js | 3 +- .../data/methods/update-files-public.js | 4 +- node_common/data/utilities.js | 6 +- node_common/managers/emails.js | 3 +- node_common/managers/search.js | 11 +-- node_common/managers/viewer.js | 17 +--- node_common/middleware.js | 3 +- node_common/monitor.js | 77 +++---------------- node_common/nodejs-websocket.js | 11 ++- node_common/social.js | 7 +- node_common/utilities.js | 19 +++-- pages/_/test.js | 4 - pages/api/addresses/send.js | 3 +- pages/api/data/archive.js | 22 +++--- pages/api/data/create.js | 3 - pages/api/sign-in.js | 6 +- pages/api/twitter/authenticate.js | 3 +- pages/api/twitter/request-token.js | 3 +- pages/api/users/get-serialized.js | 2 +- pages/api/users/get-version.js | 5 +- pages/api/users/update.js | 5 +- pages/api/verifications/twitter/create.js | 3 +- scenes/SceneAuth/hooks.js | 3 +- scenes/SceneFilesFolder.js | 2 - scripts/adjust.js | 10 ++- scripts/delete-user.js | 15 ++-- scripts/drop-database.js | 10 ++- scripts/files-migration.js | 77 ++++++++++--------- scripts/memory-burn.js | 67 ++++++++-------- scripts/privacy-and-counts-migration.js | 20 ++--- scripts/repost-migration.js | 15 ++-- scripts/seed-database.js | 10 ++- scripts/setup-database.js | 10 ++- scripts/worker-analytics.js | 15 ++-- scripts/worker-heavy-stones.js | 27 +++---- server.js | 11 ++- 69 files changed, 297 insertions(+), 394 deletions(-) rename node_common/node-logging.js => common/logging.js (57%) diff --git a/common/browser-websockets.js b/common/browser-websockets.js index 66cb02b0..204a3d64 100644 --- a/common/browser-websockets.js +++ b/common/browser-websockets.js @@ -1,5 +1,6 @@ import * as Window from "~/common/window"; import * as Strings from "~/common/strings"; +import * as Logging from "~/common/logging"; let pingTimeout = null; let client = null; @@ -16,10 +17,10 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () => return null; } - console.log(`${resource}: init`); + Logging.log(`${resource}: init`); if (client) { - console.log("ERROR: Already has websocket client"); + Error.log("ERROR: Already has websocket client"); return client; } @@ -39,7 +40,7 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () => return null; } - console.log(`${resource}: ping`); + Logging.log(`${resource}: ping`); clearTimeout(pingTimeout); pingTimeout = setTimeout(() => { @@ -63,7 +64,7 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () => type = response.type; data = response.data; } catch (e) { - console.log(e); + Logging.error(e); } if (!data) { @@ -89,7 +90,7 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () => } else { setTimeout(() => { client = null; - console.log(`Auto reconnecting dropped websocket`); + Logging.log("Auto reconnecting dropped websocket"); init({ resource, viewer, onUpdate }); }, 1000); } @@ -97,7 +98,7 @@ export const init = ({ resource = "", viewer, onUpdate, onNewActiveUser = () => return null; } - console.log(`${resource}: closed`); + Logging.log(`${resource}: closed`); clearTimeout(pingTimeout); }); @@ -118,7 +119,7 @@ export const deleteClient = async () => { } if (!client) { - console.log("WEBSOCKET: NOTHING TO DELETE"); + Logging.log("WEBSOCKET: NOTHING TO DELETE"); return null; } @@ -128,7 +129,7 @@ export const deleteClient = async () => { client = null; await Window.delay(0); - console.log("WEBSOCKET: TERMINATED"); + Logging.log("WEBSOCKET: TERMINATED"); return client; }; @@ -138,10 +139,10 @@ export const checkWebsocket = async () => { return; } if (!savedResource || !savedViewer || !savedOnUpdate) { - console.log("no saved resources from previous, so not connecting a websocket"); + Logging.log("No saved resources from previous, so not connecting a websocket"); return; } - console.log("reconnecting dropped websocket"); + Logging.log("Reconnecting dropped websocket"); init({ resource: savedResource, viewer: savedViewer, onUpdate: savedOnUpdate }); await Window.delay(2000); return; diff --git a/common/custom-events.js b/common/custom-events.js index d5959e9d..e83457f4 100644 --- a/common/custom-events.js +++ b/common/custom-events.js @@ -4,8 +4,6 @@ export const dispatchCustomEvent = ({ name, detail }) => { }; export const hasError = (response) => { - console.log("insdie has error"); - console.log(response); if (!response) { dispatchCustomEvent({ name: "create-alert", @@ -15,7 +13,6 @@ export const hasError = (response) => { }, }, }); - console.log(response); return true; } else if (response.error) { dispatchCustomEvent({ @@ -26,7 +23,6 @@ export const hasError = (response) => { }, }, }); - console.log(response); return true; } return false; diff --git a/common/file-utilities.js b/common/file-utilities.js index 50f7d55a..9f6ec177 100644 --- a/common/file-utilities.js +++ b/common/file-utilities.js @@ -5,6 +5,7 @@ import * as Credentials from "~/common/credentials"; import * as Strings from "~/common/strings"; import * as Validations from "~/common/validations"; import * as Events from "~/common/custom-events"; +import * as Logging from "~/common/logging"; import { encode } from "blurhash"; @@ -85,7 +86,7 @@ export const upload = async ({ file, context, bucketName, routes, excludeFromLib XHR.open("post", path, true); XHR.setRequestHeader("authorization", getCookie(Credentials.session.key)); XHR.onerror = (event) => { - console.log(event); + Logging.error(event); XHR.abort(); }; @@ -98,7 +99,7 @@ export const upload = async ({ file, context, bucketName, routes, excludeFromLib } if (event.lengthComputable) { - console.log("FILE UPLOAD PROGRESS", event); + Logging.log("FILE UPLOAD PROGRESS", event); context.setState({ fileLoading: { ...context.state.fileLoading, @@ -117,7 +118,7 @@ export const upload = async ({ file, context, bucketName, routes, excludeFromLib window.removeEventListener(`cancel-${file.lastModified}-${file.name}`, () => XHR.abort()); XHR.onloadend = (event) => { - console.log("FILE UPLOAD END", event); + Logging.log("FILE UPLOAD END", event); try { return resolve(JSON.parse(event.target.response)); } catch (e) { @@ -126,7 +127,6 @@ export const upload = async ({ file, context, bucketName, routes, excludeFromLib }); } }; - console.log(formData); XHR.send(formData); }); @@ -177,7 +177,7 @@ export const upload = async ({ file, context, bucketName, routes, excludeFromLib let blurhash = await encodeImageToBlurhash(url); item.data.blurhash = blurhash; } catch (e) { - console.log(e); + Logging.error(e); } } diff --git a/common/hooks.js b/common/hooks.js index e60ef38c..0e713860 100644 --- a/common/hooks.js +++ b/common/hooks.js @@ -1,4 +1,5 @@ import * as React from "react"; +import * as Logging from "~/common/logging"; export const useMounted = () => { const isMounted = React.useRef(true); @@ -60,7 +61,7 @@ export const useForm = ({ setInternal((prev) => ({ ...prev, isValidating: true })); errors = await validate(state.values, {}); } catch (e) { - console.log("validation", e); + Logging.error(e); } finally { setInternal((prev) => ({ ...prev, isValidating: false })); setState((prev) => ({ @@ -102,7 +103,7 @@ export const useForm = ({ errors = await validate(state.values, { ...state.errors }); if (_hasError(errors)) return; } catch (e) { - console.log("validation", e); + Logging.error(e); } finally { setInternal((prev) => ({ ...prev, isValidating: false })); setState((prev) => ({ ...prev, errors })); @@ -115,7 +116,7 @@ export const useForm = ({ try { await onSubmit(state.values); } catch (e) { - console.log("submitting", e); + Logging.error(e); } finally { setInternal((prev) => ({ ...prev, isSubmitting: false })); } @@ -125,7 +126,7 @@ export const useForm = ({ e.preventDefault(); submitAsync() .then() - .catch((e) => console.log(e)); + .catch((e) => Logging.error(e)); }; // Note(Amine): this prop getter will overide the form onSubmit handler diff --git a/node_common/node-logging.js b/common/logging.js similarity index 57% rename from node_common/node-logging.js rename to common/logging.js index 85fcf1f1..1e384910 100644 --- a/node_common/node-logging.js +++ b/common/logging.js @@ -1,8 +1,5 @@ const getTimestamp = () => { - return new Date() - .toISOString() - .replace(/T/, " ") - .replace(/\..+/, ""); + return new Date().toISOString().replace(/T/, " ").replace(/\..+/, ""); }; const getTime = () => { @@ -11,10 +8,10 @@ const getTime = () => { const SLATE = "SLATE "; -export const error = (message) => { - console.log(`\x1b[1m[ \x1b[31m${SLATE}\x1b[0m\x1b[1m ]\x1b[0m ${getTime()} ${message}`); +export const error = (...message) => { + console.log(`\x1b[1m[ \x1b[31m${SLATE}\x1b[0m\x1b[1m ]\x1b[0m ${getTime()} `, ...message); }; -export const log = (message) => { - console.log(`\x1b[1m[ \x1b[32m${SLATE}\x1b[0m\x1b[1m ]\x1b[0m ${getTime()} ${message}`); +export const log = (...message) => { + console.log(`\x1b[1m[ \x1b[32m${SLATE}\x1b[0m\x1b[1m ]\x1b[0m ${getTime()} `, ...message); }; diff --git a/common/user-behaviors.js b/common/user-behaviors.js index af121ab4..d3156bc9 100644 --- a/common/user-behaviors.js +++ b/common/user-behaviors.js @@ -295,7 +295,6 @@ export const removeFromSlate = async ({ slate, ids }) => { //NOTE(martina): save copy includes add to slate now. If it's already in the user's files but not in that slate, it'll skip the adding to files and just add to slate export const saveCopy = async ({ files, slate }) => { - console.log("user behaviors save copy"); let response = await Actions.saveCopy({ files, slate }); if (Events.hasError(response)) { return false; diff --git a/components/core/Application.js b/components/core/Application.js index 0341997d..eb307c07 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -12,6 +12,7 @@ import * as Store from "~/common/store"; import * as Websockets from "~/common/browser-websockets"; import * as UserBehaviors from "~/common/user-behaviors"; import * as Events from "~/common/custom-events"; +import * as Logging from "~/common/logging"; // NOTE(jim): // Scenes each have an ID and can be navigated to with _handleAction @@ -207,7 +208,6 @@ export default class ApplicationPage extends React.Component { if (callback) { callback(); } - console.log(this.state.viewer); } ); return; @@ -218,7 +218,6 @@ export default class ApplicationPage extends React.Component { viewer: { ...this.state.viewer, ...viewer }, }, () => { - console.log(this.state.viewer); if (callback) { callback(); } @@ -244,7 +243,7 @@ export default class ApplicationPage extends React.Component { } if (this.props.resources && !Strings.isEmpty(this.props.resources.pubsub)) { if (!this.state.viewer) { - console.log("WEBSOCKET: NOT AUTHENTICATED"); + Logging.error("WEBSOCKET: NOT AUTHENTICATED"); return; } wsclient = Websockets.init({ @@ -276,7 +275,7 @@ export default class ApplicationPage extends React.Component { // only change if necessary. if (this.state.isMobile !== isMobile) { - console.log("changing to mobile?", isMobile); + Logging.log("changing to mobile?", isMobile); this.setState({ isMobile }); } }; @@ -348,7 +347,7 @@ export default class ApplicationPage extends React.Component { routes: this.props.resources, }); } catch (e) { - console.log(e); + Logging.error(e); } if (!response || response.error) { @@ -484,7 +483,7 @@ export default class ApplicationPage extends React.Component { return viewer; } - this.setState({ viewer }, () => console.log(this.state.viewer)); + this.setState({ viewer }); await this._handleSetupWebsocket(); let unseenAnnouncements = []; @@ -578,7 +577,7 @@ export default class ApplicationPage extends React.Component { return window.open(options.value); } - console.log("Error: Failed to _handleAction because TYPE did not match any known actions"); + Logging.error("Error: Failed to _handleAction because TYPE did not match any known actions"); }; _handleNavigateTo = async ({ href, redirect = false, popstate = false }) => { diff --git a/components/core/CarouselSidebar.js b/components/core/CarouselSidebar.js index 4296a220..086ed72c 100644 --- a/components/core/CarouselSidebar.js +++ b/components/core/CarouselSidebar.js @@ -684,7 +684,7 @@ class CarouselSidebar extends React.Component { { this.props.carouselType === "ACTIVITY" ? actions.push( -
+
{ - console.log( + Logging.error( `ERROR: onUpdate is missing from a Link object called with href ${this.props.href}` ); }, diff --git a/components/core/SearchModal.js b/components/core/SearchModal.js index ea50f0ff..b26531d3 100644 --- a/components/core/SearchModal.js +++ b/components/core/SearchModal.js @@ -5,6 +5,7 @@ import * as Actions from "~/common/actions"; import * as Strings from "~/common/strings"; import * as Window from "~/common/window"; import * as Validations from "~/common/validations"; +import * as Logging from "~/common/logging"; import MiniSearch from "minisearch"; import SlateMediaObjectPreview from "~/components/core/SlateMediaObjectPreview"; @@ -448,8 +449,7 @@ const getHref = (result) => { } else if (result.type === "DATA_FILE") { return `/_/data?cid=${result.data.file.cid}`; } else { - console.log("GET HREF FAILED B/C RESULT WAS:"); - console.log(result); + Logging.error("Get href failed because result was:", result); } }; @@ -637,7 +637,6 @@ export class SearchModal extends React.Component { } else if (e.keyCode === 13) { if (results.length > this.state.selectedIndex && this.state.selectedIndex >= 0) { let href = results[this.state.selectedIndex].href; - console.log("key down navigate"); this.props.onAction({ type: "NAVIGATE", href }); } e.preventDefault(); @@ -780,7 +779,6 @@ export class SearchModal extends React.Component { results = results.map((res) => { return { ...res, href: getHref(res) }; }); - console.log(results); this.setState({ results, selectedIndex: 0 }); if (this._optionRoot) { this._optionRoot.scrollTop = 0; @@ -949,11 +947,7 @@ export class SearchModal extends React.Component { _handleSelectIndex = (i) => { if (this.state.selectedIndex === i || this.props.isMobile) { - console.log("handle hide"); this._handleHide(); - } else { - console.log("set state"); - // this.setState({ selectedIndex: i }); } }; @@ -1182,13 +1176,13 @@ export class SearchModal extends React.Component { > {results.map((each, i) => ( this._handleSelectIndex(i)} >
); - if (!file.filename) { - console.log(file); - } + if (Validations.isFontFile(file.filename)) { return (
{ let coordinates = []; let i = {}; - console.log(g); g.map((o, index) => { coordinates.push(o.x); coordinates.push(o.y); diff --git a/components/system/components/ListEditor.js b/components/system/components/ListEditor.js index 62f137df..30eedbbf 100644 --- a/components/system/components/ListEditor.js +++ b/components/system/components/ListEditor.js @@ -123,10 +123,7 @@ export class ListEditor extends React.Component { target: { name: this.props.name, value: this.state.options }, }); } - this.setState({ expand: !this.state.expand }), - () => { - console.log(this.state.expand); - }; + this.setState({ expand: !this.state.expand }); }; _handleDelete = (i) => { diff --git a/components/system/components/Table.js b/components/system/components/Table.js index f9012b17..a5bc7f9f 100644 --- a/components/system/components/Table.js +++ b/components/system/components/Table.js @@ -7,6 +7,7 @@ import * as React from "react"; import * as Constants from "~/common/constants"; import * as SubSystem from "~/components/system/components/fragments/TableComponents"; import * as SVG from "~/common/svg"; +import * as Logging from "~/common/logging"; import { css } from "@emotion/react"; import { P } from "~/components/system/components/Typography"; @@ -83,7 +84,7 @@ const STYLES_TABLE_TOP_ROW = css` export class Table extends React.Component { static defaultProps = { - onAction: () => console.log("No action function set"), + onAction: () => Logging.error("No action function set"), onChange: () => {}, }; diff --git a/components/system/components/Tag.js b/components/system/components/Tag.js index 6b14afad..cff1169b 100644 --- a/components/system/components/Tag.js +++ b/components/system/components/Tag.js @@ -453,11 +453,8 @@ export const Tag = ({ if ((tags || []).find((tag) => tag.toLowerCase() === value.toLowerCase().trim())) { return; } - console.log("inside handle add"); if (onChange) { - console.log("on change exists"); onChange({ target: { name: "tags", value: [...tags, value.trim()] } }); - console.log("after onchange"); setValue(""); } }; @@ -489,7 +486,7 @@ export const Tag = ({ }; const _handleFocus = () => setOpen(true); - // console.log({ suggestions }); + return (
diff --git a/components/system/components/fragments/GlobalTooltip.js b/components/system/components/fragments/GlobalTooltip.js index 98fb50fd..adca8f64 100644 --- a/components/system/components/fragments/GlobalTooltip.js +++ b/components/system/components/fragments/GlobalTooltip.js @@ -104,15 +104,6 @@ export class GlobalTooltip extends React.Component { }; _handleAdd = (e) => { - // if ( - // this.props.allowedTypes && - // !this.props.allowedTypes.includes(e.detail.type) - // ) { - // return; - // } - // console.log("got here"); - // if (!e.detail.bubbleRect.width && !e.detail.bubbleRect.height) return; - // console.log("had width and height"); let tooltips = this.state.tooltips; tooltips[e.detail.id] = { id: e.detail.id, @@ -139,14 +130,11 @@ export class GlobalTooltip extends React.Component { }; _handleShow = async (e) => { - console.log(this.state.tooltips); - console.log(this.state.tooltips[e.detail.id]); if (this.state.tooltips[e.detail.id]) { let tooltips = this.state.tooltips; if (!tooltips[e.detail.id].style) { let anchor = tooltips[e.detail.id].root; let rect = anchor.getBoundingClientRect(); - console.log(rect); let style = this.getOrientation( rect, tooltips[e.detail.id].bubbleRect, @@ -201,7 +189,6 @@ export class TooltipWrapper extends React.Component { componentDidMount = () => { let bubbleRect = this._bubble.getBoundingClientRect(); - console.log(this._bubble); Events.dispatchCustomEvent({ name: "add-tooltip", diff --git a/components/system/modules/FilecoinDealsList.js b/components/system/modules/FilecoinDealsList.js index 97808c71..a1b2adcb 100644 --- a/components/system/modules/FilecoinDealsList.js +++ b/components/system/modules/FilecoinDealsList.js @@ -14,14 +14,12 @@ const STYLES_NESTED_TABLE = css` const NestedTable = (data) => { let values = []; - console.log(Object.entries(data)); for (let entries of Object.entries(data)) { if (entries[0] !== "rootCid") { values.push(
{entries[0]}
); values.push(
{entries[1]}
); } } - console.log(values); return
{values}
; }; diff --git a/node_common/array-utilities.js b/node_common/array-utilities.js index e1e38c4d..d9c09472 100644 --- a/node_common/array-utilities.js +++ b/node_common/array-utilities.js @@ -10,8 +10,7 @@ export const removeDuplicateUserFiles = async ({ files, user }) => { const duplicateCids = duplicateFiles.map((file) => file.cid); const filteredFiles = files.filter((file) => !duplicateCids.includes(file.cid)); - console.log(duplicateFiles); - console.log(filteredFiles); + return { duplicateFiles, filteredFiles }; }; diff --git a/node_common/data/methods/delete-files-by-ids.js b/node_common/data/methods/delete-files-by-ids.js index b02c5d67..fbb47d05 100644 --- a/node_common/data/methods/delete-files-by-ids.js +++ b/node_common/data/methods/delete-files-by-ids.js @@ -6,12 +6,6 @@ export default async ({ ids, ownerId }) => { return await runQuery({ label: "DELETE_FILES_BY_IDS", queryFn: async (DB) => { - console.log("inside delete files by ids"); - // const repostedSlateFiles = await DB.from("slate_files") - // .join("slates", "slates.id", "=", "slate_files.slateId") - // .whereNot("slates.ownerId", "=", ownerId) - // .whereIn("slate_files.fileId", ids) - // .update({ "slate_files.fileId": null }); const repostedSlateFiles = await DB.from("slate_files") .whereIn("id", function () { this.select("slate_files.id") diff --git a/node_common/data/methods/get-activity.js b/node_common/data/methods/get-activity.js index 1f65ab61..6bdb3042 100644 --- a/node_common/data/methods/get-activity.js +++ b/node_common/data/methods/get-activity.js @@ -1,3 +1,5 @@ +import * as Logging from "~/common/logging"; + import { runQuery } from "~/node_common/data/utilities"; export default async ({ @@ -123,7 +125,7 @@ export default async ({ return JSON.parse(JSON.stringify(query)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_ACTIVITY_FOR_USER_ID", }); diff --git a/node_common/data/methods/get-api-keys-by-user-id.js b/node_common/data/methods/get-api-keys-by-user-id.js index 948fb282..e7f081c2 100644 --- a/node_common/data/methods/get-api-keys-by-user-id.js +++ b/node_common/data/methods/get-api-keys-by-user-id.js @@ -1,3 +1,5 @@ +import * as Logging from "~/common/logging"; + import { runQuery } from "~/node_common/data/utilities"; export default async ({ userId }) => { @@ -13,7 +15,7 @@ export default async ({ userId }) => { return JSON.parse(JSON.stringify(query)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_API_KEYS_BY_USER_ID", }); diff --git a/node_common/data/methods/get-every-file.js b/node_common/data/methods/get-every-file.js index 42dcc5e1..53c84d0f 100644 --- a/node_common/data/methods/get-every-file.js +++ b/node_common/data/methods/get-every-file.js @@ -1,3 +1,4 @@ +import * as Logging from "~/common/logging"; import * as Serializers from "~/node_common/serializers"; import { runQuery } from "~/node_common/data/utilities"; @@ -24,7 +25,7 @@ export default async ({ sanitize = false, publicOnly = false } = {}) => { return JSON.parse(JSON.stringify(files)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_EVERY_FILE", }); diff --git a/node_common/data/methods/get-every-slate.js b/node_common/data/methods/get-every-slate.js index 1da91648..6f100243 100644 --- a/node_common/data/methods/get-every-slate.js +++ b/node_common/data/methods/get-every-slate.js @@ -1,3 +1,4 @@ +import * as Logging from "~/common/logging"; import * as Serializers from "~/node_common/serializers"; import * as Constants from "~/node_common/constants"; @@ -53,7 +54,7 @@ export default async ({ sanitize = false, includeFiles = false, publicOnly = fal return JSON.parse(JSON.stringify(slates)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_EVERY_SLATE", }); diff --git a/node_common/data/methods/get-every-user.js b/node_common/data/methods/get-every-user.js index 080b1476..4bb8af79 100644 --- a/node_common/data/methods/get-every-user.js +++ b/node_common/data/methods/get-every-user.js @@ -1,3 +1,4 @@ +import * as Logging from "~/common/logging"; import * as Serializers from "~/node_common/serializers"; import * as Constants from "~/node_common/constants"; @@ -36,7 +37,7 @@ export default async ({ sanitize = false, includeFiles = false } = {}) => { return JSON.parse(JSON.stringify(users)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_EVERY_USER", }); diff --git a/node_common/data/methods/get-explore.js b/node_common/data/methods/get-explore.js index 3e6f6c62..1140111f 100644 --- a/node_common/data/methods/get-explore.js +++ b/node_common/data/methods/get-explore.js @@ -1,3 +1,5 @@ +import * as Logging from "~/common/logging"; + import { runQuery } from "~/node_common/data/utilities"; export default async ({ earliestTimestamp, latestTimestamp }) => { @@ -84,7 +86,7 @@ export default async ({ earliestTimestamp, latestTimestamp }) => { return JSON.parse(JSON.stringify(query)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_EXPLORE", }); diff --git a/node_common/data/methods/get-followers-by-user-id.js b/node_common/data/methods/get-followers-by-user-id.js index 359a0a7c..c065886e 100644 --- a/node_common/data/methods/get-followers-by-user-id.js +++ b/node_common/data/methods/get-followers-by-user-id.js @@ -1,8 +1,9 @@ -import { runQuery } from "~/node_common/data/utilities"; import * as Constants from "~/node_common/constants"; - +import * as Logging from "~/common/logging"; import * as Serializers from "~/node_common/serializers"; +import { runQuery } from "~/node_common/data/utilities"; + export default async ({ userId }) => { return await runQuery({ label: "GET_FOLLOWERS_BY_USER_ID", @@ -24,7 +25,7 @@ export default async ({ userId }) => { return JSON.parse(JSON.stringify(serialized)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_FOLLOWERS_BY_USER_ID", }); diff --git a/node_common/data/methods/get-following-by-user-id.js b/node_common/data/methods/get-following-by-user-id.js index 871eac29..93aa7436 100644 --- a/node_common/data/methods/get-following-by-user-id.js +++ b/node_common/data/methods/get-following-by-user-id.js @@ -1,8 +1,9 @@ -import { runQuery } from "~/node_common/data/utilities"; import * as Constants from "~/node_common/constants"; - +import * as Logging from "~/common/logging"; import * as Serializers from "~/node_common/serializers"; +import { runQuery } from "~/node_common/data/utilities"; + export default async ({ ownerId }) => { return await runQuery({ label: "GET_FOLLOWING_BY_USER_ID", @@ -25,7 +26,7 @@ export default async ({ ownerId }) => { return JSON.parse(JSON.stringify(serialized)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_FOLLOWING_BY_USER_ID", }); diff --git a/node_common/data/methods/get-likes-by-user-id.js b/node_common/data/methods/get-likes-by-user-id.js index 928f3cea..b96d1d7a 100644 --- a/node_common/data/methods/get-likes-by-user-id.js +++ b/node_common/data/methods/get-likes-by-user-id.js @@ -1,5 +1,6 @@ import * as Constants from "~/node_common/constants"; import * as Serializers from "~/node_common/serializers"; +import * as Logging from "~/common/logging"; import { runQuery } from "~/node_common/data/utilities"; @@ -25,7 +26,7 @@ export default async ({ ownerId }) => { return JSON.parse(JSON.stringify(serialized)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_LIKES_BY_USER_ID", }); diff --git a/node_common/data/methods/get-slates-by-user-id.js b/node_common/data/methods/get-slates-by-user-id.js index ba3df5e4..df966702 100644 --- a/node_common/data/methods/get-slates-by-user-id.js +++ b/node_common/data/methods/get-slates-by-user-id.js @@ -1,5 +1,6 @@ import * as Serializers from "~/node_common/serializers"; import * as Constants from "~/node_common/constants"; +import * as Logging from "~/common/logging"; import { runQuery } from "~/node_common/data/utilities"; @@ -72,7 +73,7 @@ export default async ({ ownerId, sanitize = false, includeFiles = false, publicO return JSON.parse(JSON.stringify(query)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_SLATES_BY_USER_ID", }); diff --git a/node_common/data/methods/get-subscribers-by-slate-id.js b/node_common/data/methods/get-subscribers-by-slate-id.js index 9221bd4d..399313f3 100644 --- a/node_common/data/methods/get-subscribers-by-slate-id.js +++ b/node_common/data/methods/get-subscribers-by-slate-id.js @@ -1,5 +1,6 @@ import * as Serializers from "~/node_common/serializers"; import * as Constants from "~/node_common/constants"; +import * as Logging from "~/common/logging"; import { runQuery } from "~/node_common/data/utilities"; @@ -25,7 +26,7 @@ export default async ({ slateId }) => { return JSON.parse(JSON.stringify(serialized)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_SUBSCRIBERS_BY_SLATE_ID", }); diff --git a/node_common/data/methods/get-subscriptions-by-user-id.js b/node_common/data/methods/get-subscriptions-by-user-id.js index 97d184e1..3688b696 100644 --- a/node_common/data/methods/get-subscriptions-by-user-id.js +++ b/node_common/data/methods/get-subscriptions-by-user-id.js @@ -1,5 +1,6 @@ import * as Serializers from "~/node_common/serializers"; import * as Constants from "~/node_common/constants"; +import * as Logging from "~/common/logging"; import { runQuery } from "~/node_common/data/utilities"; @@ -39,7 +40,7 @@ export default async ({ ownerId }) => { return JSON.parse(JSON.stringify(serialized)); }, errorFn: async (e) => { - console.log({ + Logging.error({ error: true, decorator: "GET_SUBSCRIPTIONS_BY_USER_ID", }); diff --git a/node_common/data/methods/update-files-public.js b/node_common/data/methods/update-files-public.js index 1093f6b5..efc779be 100644 --- a/node_common/data/methods/update-files-public.js +++ b/node_common/data/methods/update-files-public.js @@ -1,9 +1,9 @@ +import * as Logging from "~/common/logging"; + import { runQuery } from "~/node_common/data/utilities"; //NOTE(martina): this method is specifically for making *multiple* files from one owner *public*. It will filter out the already public files export default async ({ ids, ownerId }) => { - console.log(ids); - console.log(ownerId); return await runQuery({ label: "UPDATE_FILES_PUBLIC", queryFn: async (DB) => { diff --git a/node_common/data/utilities.js b/node_common/data/utilities.js index 05c5fa26..a4d7f064 100644 --- a/node_common/data/utilities.js +++ b/node_common/data/utilities.js @@ -1,4 +1,4 @@ -import * as NodeLogging from "~/node_common/node-logging"; +import * as Logging from "~/common/logging"; import DB from "~/node_common/database"; @@ -7,10 +7,10 @@ export const runQuery = async ({ queryFn, errorFn, label }) => { try { response = await queryFn(DB); } catch (e) { - NodeLogging.error(`DB:${label}: ${e.message}`); + Logging.error(`DB:${label}: ${e.message}`); response = errorFn(e); } - NodeLogging.log(`DB:${label}`); + Logging.log(`DB:${label}`); return response; }; diff --git a/node_common/managers/emails.js b/node_common/managers/emails.js index 85061a33..2ea0bb06 100644 --- a/node_common/managers/emails.js +++ b/node_common/managers/emails.js @@ -1,3 +1,4 @@ +import * as Logging from "~/common/logging"; import * as Environment from "~/node_common/environment"; import sgMail from "@sendgrid/mail"; @@ -45,7 +46,7 @@ export const sendTemplate = async ({ to, from, templateId, templateData }) => { try { await sgMail.send(msg); } catch (error) { - console.log("SOMETHING", error); + Logging.error(error); return { decorator: "SEND_TEMPLATE_EMAIL_FAILURE", error: true }; } }; diff --git a/node_common/managers/search.js b/node_common/managers/search.js index c5765502..dc02023d 100644 --- a/node_common/managers/search.js +++ b/node_common/managers/search.js @@ -5,7 +5,7 @@ import * as Constants from "~/node_common/constants"; import * as Serializers from "~/node_common/serializers"; import * as Strings from "~/common/strings"; import * as Websocket from "~/node_common/nodejs-websocket"; -import * as NodeLogging from "~/node_common/node-logging"; +import * as Logging from "~/common/logging"; import * as Window from "~/common/window"; import WebSocket from "ws"; @@ -39,10 +39,9 @@ const websocketSend = async (type, data) => { }; export const updateUser = async (user, action) => { - console.log("UPDATE SEARCH for user"); if (!user || !action) return; - NodeLogging.log(`Search is updating user ...`); + Logging.log(`Search is updating user ...`); let data; if (Array.isArray(user)) { @@ -60,10 +59,9 @@ export const updateUser = async (user, action) => { }; export const updateSlate = async (slate, action) => { - console.log("UPDATE SEARCH for slate"); if (!slate || !action) return; - NodeLogging.log(`Search is updating slate ...`); + Logging.log(`Search is updating slate ...`); let data; if (Array.isArray(slate)) { @@ -81,10 +79,9 @@ export const updateSlate = async (slate, action) => { }; export const updateFile = async (file, action) => { - console.log("UPDATE SEARCH for file"); if (!file || !action) return; - NodeLogging.log(`Search is updating file ...`); + Logging.log(`Search is updating file ...`); let data; if (Array.isArray(file)) { diff --git a/node_common/managers/viewer.js b/node_common/managers/viewer.js index 1225b09a..8881fd28 100644 --- a/node_common/managers/viewer.js +++ b/node_common/managers/viewer.js @@ -8,6 +8,7 @@ import * as Strings from "~/common/strings"; import * as Window from "~/common/window"; import * as Websocket from "~/node_common/nodejs-websocket"; import * as Filecoin from "~/common/filecoin"; +import * as Logging from "~/common/logging"; import WebSocket from "ws"; @@ -133,13 +134,6 @@ export const getById = async ({ id }) => { includeFiles: true, }); - // try { - // JSON.stringify(user); - // } catch (e) { - // console.log(user); - // console.log("errored on json.stringify user (1st time)"); - // } - if (!user) { return null; } @@ -231,13 +225,6 @@ export const getById = async ({ id }) => { followers, }; - // try { - // JSON.stringify(viewer); - // } catch (e) { - // console.log(viewer); - // console.log("errored on json.stringify viewer (2nd time)"); - // } - return viewer; }; @@ -297,7 +284,7 @@ export const getDealHistory = async ({ id }) => { }); } } catch (e) { - console.log(e); + Logging.error(e); Social.sendTextileSlackMessage({ file: "/node_common/managers/viewer.js", user, diff --git a/node_common/middleware.js b/node_common/middleware.js index 0852f0ff..b8f79a9d 100644 --- a/node_common/middleware.js +++ b/node_common/middleware.js @@ -3,6 +3,7 @@ import * as Credentials from "~/common/credentials"; import * as Strings from "~/common/strings"; import * as Data from "~/node_common/data"; import * as Powergate from "~/node_common/powergate"; +import * as Logging from "~/common/logging"; import JWT from "jsonwebtoken"; @@ -51,7 +52,7 @@ export const RequireCookieAuthentication = async (req, res, next) => { return res.status(403).json({ decorator: "SERVER_AUTH_USER_NOT_FOUND", error: true }); } } catch (err) { - console.log(err); + Logging.error(err); return res.status(403).json({ decorator: "SERVER_AUTH_USER_ERROR", error: true }); } diff --git a/node_common/monitor.js b/node_common/monitor.js index c47e764a..bf28331c 100644 --- a/node_common/monitor.js +++ b/node_common/monitor.js @@ -1,5 +1,6 @@ import * as Social from "~/node_common/social"; import * as Arrays from "~/common/arrays"; +import * as Logging from "~/common/logging"; //things taht could be combined into this: //update search (searchmanager) @@ -21,29 +22,10 @@ export const error = (location, e) => { const message = `@martina there was an error at ${location}: ${e}`; Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; -// export const upload = ({ user, files: targetFiles }) => { -// const files = Arrays.filterPublic(targetFiles); -// if (!files.length) { -// return; -// } -// try { -// const userURL = getUserURL(user); -// const objectURL = ``; -// const extra = -// files.length > 1 -// ? ` and ${files.length - 1} other file${files.length - 1 > 1 ? "s " : " "}` -// : ""; -// const message = `*${userURL}* uploaded ${objectURL}${extra}`; -// Social.sendSlackMessage(message); -// } catch (e) { -// console.log(e); -// } -// }; - export const upload = ({ user, slate, files: targetFiles }) => { if (slate && !slate.isPublic) return; const files = Arrays.filterPublic(targetFiles); @@ -67,7 +49,7 @@ export const upload = ({ user, slate, files: targetFiles }) => { Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; @@ -86,31 +68,10 @@ export const download = ({ user, files: targetFiles }) => { const message = `*${userURL}* downloaded ${objectURL}${extra}`; Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; -// export const addToSlate = ({ slate, user, files: targetFiles }) => { -// if (!slate.isPublic) return; -// const files = Arrays.filterPublic(targetFiles); -// if (!files.length) { -// return; -// } -// try { -// const userURL = getUserURL(user); -// const objectURL = ``; -// const extra = -// files.length > 1 -// ? ` and ${files.length - 1} other file${files.length - 1 > 1 ? "s " : " "}` -// : ""; -// const message = `*${userURL}* saved ${objectURL}${extra} to https://slate.host/${user.username}/${slate.slatename}`; - -// Social.sendSlackMessage(message); -// } catch (e) { -// console.log(e); -// } -// }; - export const saveCopy = ({ slate, user, files: targetFiles }) => { if (slate && !slate.isPublic) return; const files = Arrays.filterPublic(targetFiles); @@ -134,30 +95,10 @@ export const saveCopy = ({ slate, user, files: targetFiles }) => { Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; -// export const saveCopy = ({ user, files: targetFiles }) => { -// const files = Arrays.filterPublic(targetFiles); -// if (!files.length) { -// return; -// } -// try { -// const userURL = getUserURL(user); -// const objectURL = ``; -// const extra = -// files.length > 1 -// ? ` and ${files.length - 1} other file${files.length - 1 > 1 ? "s " : " "}` -// : ""; -// const message = `*${userURL}* saved ${objectURL}${extra}`; - -// Social.sendSlackMessage(message); -// } catch (e) { -// console.log(e); -// } -// }; - export const createSlate = ({ user, slate }) => { if (!slate.isPublic) return; try { @@ -166,7 +107,7 @@ export const createSlate = ({ user, slate }) => { Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; @@ -177,7 +118,7 @@ export const createUser = ({ user }) => { Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; @@ -190,7 +131,7 @@ export const subscribeUser = ({ user, targetUser }) => { Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; @@ -206,6 +147,6 @@ export const subscribeSlate = ({ user, targetSlate }) => { Social.sendSlackMessage(message); } catch (e) { - console.log(e); + Logging.error(e); } }; diff --git a/node_common/nodejs-websocket.js b/node_common/nodejs-websocket.js index 4c4e5707..1ed2930a 100644 --- a/node_common/nodejs-websocket.js +++ b/node_common/nodejs-websocket.js @@ -1,7 +1,6 @@ import * as Environment from "~/node_common/environment"; -import * as ScriptLogging from "~/node_common/script-logging"; import * as Strings from "~/common/strings"; -import * as NodeLogging from "~/node_common/node-logging"; +import * as Logging from "~/common/logging"; import WebSocket from "ws"; @@ -24,7 +23,7 @@ export const create = () => { clearTimeout(this.pingTimeout); this.pingTimeout = setTimeout(() => { - NodeLogging.log(`Did not receive ping in time. Disconnecting websocket`); + Logging.log(`Did not receive ping in time. Disconnecting websocket`); this.terminate(); }, 30000 + 1000); }); @@ -36,13 +35,13 @@ export const create = () => { ws.on("close", () => { global.websocket = null; setTimeout(() => { - NodeLogging.log(`Auto reconnecting websocket`); + Logging.log(`Auto reconnecting websocket`); create(); }, 1000); - NodeLogging.log(`Websocket disconnected`); + Logging.log(`Websocket disconnected`); }); - NodeLogging.log(`Websocket server started`); + Logging.log(`Websocket server started`); global.websocket = ws; return global.websocket; diff --git a/node_common/social.js b/node_common/social.js index faf36a28..992eb2fc 100644 --- a/node_common/social.js +++ b/node_common/social.js @@ -1,5 +1,6 @@ import * as Environment from "~/node_common/environment"; import * as Strings from "~/common/strings"; +import * as Logging from "~/common/logging"; import { IncomingWebhook } from "@slack/webhook"; @@ -12,8 +13,6 @@ const textileURL = `https://hooks.slack.com/services/${Environment.TEXTILE_SLACK const textileWebhook = new IncomingWebhook(textileURL); export const sendSlackMessage = (message) => { - console.log("Inside send slack message"); - console.log({ slackMessage: message }); if (Strings.isEmpty(Environment.SOCIAL_SLACK_WEBHOOK_KEY)) { return; } @@ -21,7 +20,7 @@ export const sendSlackMessage = (message) => { try { webhook.send({ text: message }); } catch (e) { - console.log({ decorator: "SLACK_MESSAGE_FAILURE", message }); + Logging.error("SLACK_MESSAGE_FAILURE", message); } }; @@ -47,6 +46,6 @@ export const sendTextileSlackMessage = ({ text: `*Source code —* ${slackFileURL} \n*Source client —* ${source} \n*Callsite —* \`${functionName}\`\n*User —* ${userURL}\n\n> ${message}\n\n*Textile error code —* ${code}`, }); } catch (e) { - console.log({ decorator: "SLACK_MESSAGE_FAILURE", message }); + Logging.error("SLACK_MESSAGE_FAILURE", message); } }; diff --git a/node_common/utilities.js b/node_common/utilities.js index 54c366b9..797f82c7 100644 --- a/node_common/utilities.js +++ b/node_common/utilities.js @@ -3,7 +3,7 @@ import * as Strings from "~/common/strings"; import * as Constants from "~/node_common/constants"; import * as Data from "~/node_common/data"; import * as Social from "~/node_common/social"; -import * as NodeLogging from "~/node_common/node-logging"; +import * as Logging from "~/common/logging"; import crypto from "crypto"; import JWT from "jsonwebtoken"; @@ -70,7 +70,7 @@ export const getIdFromCookie = (req) => { const decoded = JWT.verify(token, Environment.JWT_SECRET); id = decoded.id; } catch (e) { - console.log(e.message); + Logging.error(e.message); } } @@ -116,7 +116,7 @@ export const getFilecoinAPIFromUserToken = async ({ user }) => { const filecoin = await Filecoin.withKeyInfo(TEXTILE_KEY_INFO); await filecoin.getToken(identity); - NodeLogging.log(`filecoin init`); + Logging.log(`filecoin init`); return { filecoin, @@ -164,14 +164,14 @@ export const getBucketAPIFromUserToken = async ({ user, bucketName, encrypted = await buckets.getToken(identity); let root = null; - NodeLogging.log(`buckets.getOrCreate() init ${name}`); + Logging.log(`buckets.getOrCreate() init ${name}`); try { - console.log("before buckets get or create"); + Logging.log("before buckets get or create"); const created = await buckets.getOrCreate(name, { encrypted }); - console.log("after buckets get or create"); + Logging.log("after buckets get or create"); root = created.root; } catch (e) { - NodeLogging.log(`buckets.getOrCreate() warning: ${e.message}`); + Logging.log(`buckets.getOrCreate() warning: ${e.message}`); Social.sendTextileSlackMessage({ file: "/node_common/utilities.js", user, @@ -182,12 +182,11 @@ export const getBucketAPIFromUserToken = async ({ user, bucketName, encrypted = } if (!root) { - NodeLogging.error(`buckets.getOrCreate() failed for ${name}`); - console.log(user); + Logging.error(`buckets.getOrCreate() failed for ${name}`); return { buckets: null, bucketKey: null, bucketRoot: null }; } - NodeLogging.log(`buckets.getOrCreate() success for ${name}`); + Logging.log(`buckets.getOrCreate() success for ${name}`); return { buckets, bucketKey: root.key, diff --git a/pages/_/test.js b/pages/_/test.js index 1ff1b191..99a217d4 100644 --- a/pages/_/test.js +++ b/pages/_/test.js @@ -23,7 +23,6 @@ export default class SlateReactSystemPage extends React.Component { }); const json = await response.json(); - console.log(json); } _handleUpload = async (e) => { @@ -43,12 +42,9 @@ export default class SlateReactSystemPage extends React.Component { }); const json = await response.json(); - console.log(json); }; render() { - console.log(System.Constants); - return (
diff --git a/pages/api/addresses/send.js b/pages/api/addresses/send.js index a107738d..d1e67664 100644 --- a/pages/api/addresses/send.js +++ b/pages/api/addresses/send.js @@ -1,6 +1,7 @@ import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; import * as Powergate from "~/node_common/powergate"; +import * as Logging from "~/common/logging"; export default async (req, res) => { const id = Utilities.getIdFromCookie(req); @@ -23,7 +24,7 @@ export default async (req, res) => { try { await PG.ffs.sendFil(req.body.data.source, req.body.data.target, req.body.data.amount); } catch (e) { - console.log(e); + Logging.error(e); return res.status(500).send({ decorator: "SERVER_SEND_FILECOIN_ACTION_FAILURE", error: true }); } diff --git a/pages/api/data/archive.js b/pages/api/data/archive.js index 68fe8145..5c6b9a59 100644 --- a/pages/api/data/archive.js +++ b/pages/api/data/archive.js @@ -2,6 +2,7 @@ import * as Data from "~/node_common/data"; import * as Utilities from "~/node_common/utilities"; import * as Social from "~/node_common/social"; import * as Strings from "~/common/strings"; +import * as Logging from "~/common/logging"; import { v4 as uuid } from "uuid"; import { MAX_BUCKET_COUNT, MIN_ARCHIVE_SIZE_BYTES } from "~/node_common/constants"; @@ -74,7 +75,7 @@ export default async (req, res) => { }); } - console.log(`[ deal ] will make a deal for ${items.items.length} items`); + Logging.log(`[ deal ] will make a deal for ${items.items.length} items`); if (items.items.length < 2) { return res.status(500).send({ decorator: "SERVER_ARCHIVE_NO_FILES", @@ -82,7 +83,7 @@ export default async (req, res) => { }); } - console.log(`[ deal ] deal size: ${Strings.bytesToSize(bucketSizeBytes)}`); + Logging.log(`[ deal ] deal size: ${Strings.bytesToSize(bucketSizeBytes)}`); if (bucketSizeBytes < MIN_ARCHIVE_SIZE_BYTES) { return res.status(500).send({ decorator: "SERVER_ARCHIVE_BUCKET_TOO_SMALL", @@ -113,7 +114,7 @@ export default async (req, res) => { }); } - console.log( + Logging.log( `[ encrypted ] user has ${userBuckets.length} out of ${MAX_BUCKET_COUNT} buckets used.` ); if (userBuckets.length >= MAX_BUCKET_COUNT) { @@ -140,7 +141,7 @@ export default async (req, res) => { ? `encrypted-deal-${uuid()}` : `encrypted-data-${uuid()}`; - console.log(`[ encrypted ] making an ${encryptedBucketName} for this storage deal.`); + Logging.log(`[ encrypted ] making an ${encryptedBucketName} for this storage deal.`); try { const newBucket = await buckets.create(encryptedBucketName, true, items.cid); @@ -160,8 +161,8 @@ export default async (req, res) => { }); } - console.log(`[ encrypted ] ${encryptedBucketName}`); - console.log(`[ encrypted ] ${key}`); + Logging.log(`[ encrypted ] ${encryptedBucketName}`); + Logging.log(`[ encrypted ] ${key}`); } else { const newDealBucketName = `open-deal-${uuid()}`; @@ -183,8 +184,8 @@ export default async (req, res) => { }); } - console.log(`[ normal ] ${newDealBucketName}`); - console.log(`[ normal ] ${key}`); + Logging.log(`[ normal ] ${newDealBucketName}`); + Logging.log(`[ normal ] ${key}`); } // NOTE(jim): Finally make the deal @@ -192,9 +193,8 @@ export default async (req, res) => { let response = {}; let error = {}; try { - console.log(`[ deal-maker ] deal being made for ${key}`); + Logging.log(`[ deal-maker ] deal being made for ${key}`); if (req.body.data && req.body.data.settings) { - console.log(req.body.data.settings); response = await buckets.archive(key, req.body.data.settings); } else { response = await buckets.archive(key); @@ -202,7 +202,7 @@ export default async (req, res) => { } catch (e) { error.message = e.message; error.code = e.code; - console.log(e.message); + Logging.log(e.message); Social.sendTextileSlackMessage({ file: "/pages/api/data/archive.js", diff --git a/pages/api/data/create.js b/pages/api/data/create.js index 13be56a2..4b87e915 100644 --- a/pages/api/data/create.js +++ b/pages/api/data/create.js @@ -55,8 +55,6 @@ export default async (req, res) => { files, user, }); - console.log(filteredFiles); - console.log(duplicateFiles); // if (!newFiles.length) { // return res.status(400).send({ decorator: "SERVER_CREATE_FILE_DUPLICATE", error: true }); @@ -74,7 +72,6 @@ export default async (req, res) => { return res.status(500).send({ decorator: createdFiles.decorator, error: createdFiles.error }); } } - console.log(createdFiles); let added = createdFiles?.length || 0; diff --git a/pages/api/sign-in.js b/pages/api/sign-in.js index e41cade0..60fbe2b8 100644 --- a/pages/api/sign-in.js +++ b/pages/api/sign-in.js @@ -1,8 +1,10 @@ +import * as Logging from "~/common/logging"; import * as Environment from "~/node_common/environment"; import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; import * as Validations from "~/common/validations"; + import { encryptPasswordClient } from "~/common/utilities"; import JWT from "jsonwebtoken"; @@ -27,7 +29,7 @@ export default async (req, res) => { try { user = await Data.getUserByEmail({ email: username }); } catch (e) { - console.log(e); + Logging.error(e); } } else { try { @@ -35,7 +37,7 @@ export default async (req, res) => { username: req.body.data.username.toLowerCase(), }); } catch (e) { - console.log(e); + Logging.error(e); } } diff --git a/pages/api/twitter/authenticate.js b/pages/api/twitter/authenticate.js index 5590034e..5afbfe83 100644 --- a/pages/api/twitter/authenticate.js +++ b/pages/api/twitter/authenticate.js @@ -2,6 +2,7 @@ import * as Environment from "~/node_common/environment"; import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; +import * as Logging from "~/common/logging"; import JWT from "jsonwebtoken"; @@ -51,7 +52,7 @@ export default async (req, res) => { }); twitterUser = JSON.parse(response.data); } catch (err) { - console.log(err); + Logging.error(err); return res.status(500).send({ decorator: "SERVER_TWITTER_OAUTH_FAILED", error: true }); } if (!twitterUser) { diff --git a/pages/api/twitter/request-token.js b/pages/api/twitter/request-token.js index f05c0f0b..ec2db6f1 100644 --- a/pages/api/twitter/request-token.js +++ b/pages/api/twitter/request-token.js @@ -1,6 +1,7 @@ import * as Environment from "~/node_common/environment"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; +import * as Logging from "~/common/logging"; import { createOAuthProvider } from "~/node_common/managers/twitter"; @@ -23,7 +24,7 @@ export default async (req, res) => { await Data.createTwitterToken({ token: authToken, tokenSecret: authSecretToken }); res.json({ authToken }); } catch (e) { - console.log("error", e); + Logging.error("error", e); res.status(500).send({ decorator: "SERVER_TWITTER_REQUEST_TOKEN_FAILED", error: true }); } }; diff --git a/pages/api/users/get-serialized.js b/pages/api/users/get-serialized.js index 06953eaa..d2def9ad 100644 --- a/pages/api/users/get-serialized.js +++ b/pages/api/users/get-serialized.js @@ -39,7 +39,7 @@ export default async (req, res) => { error: true, }); } - console.log("before get slates by user id"); + let slates = await Data.getSlatesByUserId({ ownerId: user.id, includeFiles: true, diff --git a/pages/api/users/get-version.js b/pages/api/users/get-version.js index 1ae5fecd..3dd37c62 100644 --- a/pages/api/users/get-version.js +++ b/pages/api/users/get-version.js @@ -2,6 +2,7 @@ import * as Data from "~/node_common/data"; import * as Validations from "~/common/validations"; import * as Strings from "~/common/strings"; import * as Environment from "~/node_common/environment"; +import * as Logging from "~/common/logging"; export default async (req, res) => { if (!Strings.isEmpty(Environment.ALLOWED_HOST) && req.headers.host !== Environment.ALLOWED_HOST) { @@ -14,7 +15,7 @@ export default async (req, res) => { try { user = await Data.getUserByEmail({ email: username }); } catch (e) { - console.log(e); + Logging.error(e); } } else { try { @@ -22,7 +23,7 @@ export default async (req, res) => { username: req.body.data.username.toLowerCase(), }); } catch (e) { - console.log(e); + Logging.error(e); } } diff --git a/pages/api/users/update.js b/pages/api/users/update.js index 3a0513f5..35af4efd 100644 --- a/pages/api/users/update.js +++ b/pages/api/users/update.js @@ -6,6 +6,7 @@ import * as Validations from "~/common/validations"; import * as Social from "~/node_common/social"; import * as ViewerManager from "~/node_common/managers/viewer"; import * as SearchManager from "~/node_common/managers/search"; +import * as Logging from "~/common/logging"; import BCrypt from "bcrypt"; @@ -73,7 +74,7 @@ export default async (req, res) => { bucketName: "data", }); } catch (e) { - console.log(e); + Logging.error(e); Social.sendTextileSlackMessage({ file: "/pages/api/users/update.js", user, @@ -91,7 +92,7 @@ export default async (req, res) => { req.body.data.config ); } catch (e) { - console.log(e); + Logging.error(e); Social.sendTextileSlackMessage({ file: "/pages/api/users/update.js", user, diff --git a/pages/api/verifications/twitter/create.js b/pages/api/verifications/twitter/create.js index 54dee210..180a12dc 100644 --- a/pages/api/verifications/twitter/create.js +++ b/pages/api/verifications/twitter/create.js @@ -4,6 +4,7 @@ import * as Strings from "~/common/strings"; import * as Environment from "~/node_common/environment"; import * as Utilities from "~/node_common/utilities"; import * as EmailManager from "~/node_common/managers/emails"; +import * as Logging from "~/common/logging"; // NOTE(amine): this endpoint is rate limited in ./server.js, export default async (req, res) => { @@ -71,6 +72,6 @@ export default async (req, res) => { token: verification.sid, }); } catch (e) { - console.log(e); + Logging.error(e); } }; diff --git a/scenes/SceneAuth/hooks.js b/scenes/SceneAuth/hooks.js index 4f220361..3b80a3d5 100644 --- a/scenes/SceneAuth/hooks.js +++ b/scenes/SceneAuth/hooks.js @@ -2,6 +2,7 @@ import * as React from "react"; import * as Actions from "~/common/actions"; import * as Events from "~/common/custom-events"; import * as Utilities from "~/common/utilities"; +import * as Logging from "~/common/logging"; const AUTH_STATE_GRAPH = { initial: { @@ -301,7 +302,7 @@ export const useTwitter = ({ onAuthenticate, goToTwitterSignupScene }) => { goToTwitterSignupScene({ twitterEmail: response.email }); } catch (e) { // TODO failure - console.log("error", e); + Logging.error("error", e); if (popup) popup.close(); setIsLoggingIn(false); } diff --git a/scenes/SceneFilesFolder.js b/scenes/SceneFilesFolder.js index 39c6f13d..77fc0eb5 100644 --- a/scenes/SceneFilesFolder.js +++ b/scenes/SceneFilesFolder.js @@ -165,8 +165,6 @@ export default class SceneFilesFolder extends React.Component { return filtered.publicFiles; } else if (filter === "PRIVATE") { return filtered.privateFiles; - } else { - console.log("unusable privacy param"); } }; diff --git a/scripts/adjust.js b/scripts/adjust.js index 9ca8701a..93278ff0 100644 --- a/scripts/adjust.js +++ b/scripts/adjust.js @@ -1,13 +1,15 @@ +import * as Logging from "~/common/logging"; + import configs from "~/knexfile"; import knex from "knex"; const envConfig = configs["development"]; -console.log(`SETUP: database`, envConfig); +Logging.log(`SETUP: database`, envConfig); const db = knex(envConfig); -console.log(`RUNNING: adjust.js`); +Logging.log(`RUNNING: adjust.js`); const editUsersTable1 = db.schema.table("users", function (table) { table.integer("authVersion").notNullable().defaultTo(1); @@ -44,5 +46,5 @@ Promise.all([editVerificationTable]); // Promise.all([editUsersTable1]); // Promise.all([editUsersTable2, editVerificationTable, editTwitterTokenTable]); -console.log(`FINISHED: adjust.js`); -console.log(` CTRL +C to return to terminal.`); +Logging.log(`FINISHED: adjust.js`); +Logging.log(` CTRL +C to return to terminal.`); diff --git a/scripts/delete-user.js b/scripts/delete-user.js index 2607d8ab..84e10c9e 100644 --- a/scripts/delete-user.js +++ b/scripts/delete-user.js @@ -1,30 +1,31 @@ +import * as Logging from "~/common/logging"; +import * as Data from "~/node_common/data"; + import configs from "~/knexfile"; import knex from "knex"; -import * as Data from "~/node_common/data"; - import { deleteUser } from "~/pages/api/users/delete"; const envConfig = configs["development"]; const db = knex(envConfig); -console.log(`RUNNING: delete-user.js`); +Logging.log(`RUNNING: delete-user.js`); const run = async () => { const user = await Data.getUserByUsername({ username: process.argv[3], }); - console.log(user); + Logging.log(user); if (user) { - console.log(`deleting ${user.username}`); + Logging.log(`deleting ${user.username}`); await deleteUser(user); } - console.log(`FINISHED: delete-user.js`); - console.log(` CTRL +C to return to terminal.`); + Logging.log(`FINISHED: delete-user.js`); + Logging.log(` CTRL +C to return to terminal.`); }; run(); diff --git a/scripts/drop-database.js b/scripts/drop-database.js index e4c16ce0..4b9edbb9 100644 --- a/scripts/drop-database.js +++ b/scripts/drop-database.js @@ -1,13 +1,15 @@ +import * as Logging from "~/common/logging"; + import configs from "~/knexfile"; import knex from "knex"; const envConfig = configs["development"]; -console.log(`SETUP: database`, envConfig); +Logging.log(`SETUP: database`, envConfig); const db = knex(envConfig); -console.log(`RUNNING: drop-database.js`); +Logging.log(`RUNNING: drop-database.js`); Promise.all([ db.schema.dropTable("users"), @@ -25,5 +27,5 @@ Promise.all([ db.schema.dropTable("likes"), ]); -console.log(`FINISHED: drop-database.js`); -console.log(` CTRL +C to return to terminal.`); +Logging.log(`FINISHED: drop-database.js`); +Logging.log(` CTRL +C to return to terminal.`); diff --git a/scripts/files-migration.js b/scripts/files-migration.js index eaad6729..56da205f 100644 --- a/scripts/files-migration.js +++ b/scripts/files-migration.js @@ -2,6 +2,7 @@ import configs from "~/knexfile"; import knex from "knex"; import { v4 as uuid } from "uuid"; +import * as Logging from "~/common/logging"; import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; @@ -11,7 +12,7 @@ const envConfig = configs["development"]; const DB = knex(envConfig); -console.log(`RUNNING: files-migration.js`); +Logging.log(`RUNNING: files-migration.js`); // MARK: - check what parameters are in each table @@ -44,9 +45,9 @@ const printUsersTable = async () => { } } } - console.log({ dataParams: Object.keys(dataParams) }); - console.log({ fileParams: Object.keys(fileParams) }); - console.log({ coverParams: Object.keys(coverParams) }); + Logging.log({ dataParams: Object.keys(dataParams) }); + Logging.log({ fileParams: Object.keys(fileParams) }); + Logging.log({ coverParams: Object.keys(coverParams) }); }; const printSlatesTable = async () => { @@ -78,9 +79,9 @@ const printSlatesTable = async () => { } } } - console.log({ dataParams: Object.keys(dataParams) }); - console.log({ fileParams: Object.keys(fileParams) }); - console.log({ coverParams: Object.keys(coverParams) }); + Logging.log({ dataParams: Object.keys(dataParams) }); + Logging.log({ fileParams: Object.keys(fileParams) }); + Logging.log({ coverParams: Object.keys(coverParams) }); }; // MARK: - add/modify tables @@ -168,7 +169,7 @@ const addTables = async () => { table.uuid("userId").references("id").inTable("users").alter(); }); - console.log("finished adding tables"); + Logging.log("finished adding tables"); }; // MARK: - populate new tables @@ -198,8 +199,8 @@ const migrateUsersTable = async (testing = false) => { cid = file.ipfs; } if (!cid) { - console.log("file does not have cid or ipfs"); - console.log(file); + Logging.log("file does not have cid or ipfs"); + Logging.log(file); return; } let id = file.id.replace("data-", ""); @@ -210,7 +211,7 @@ const migrateUsersTable = async (testing = false) => { //NOTE(martina): to make sure there are no duplicate cids in the user's files if (libraryCids[cid]) { - console.log(`skipped duplicate cid ${cid} in user ${user.username} files`); + Logging.log(`skipped duplicate cid ${cid} in user ${user.username} files`); continue; } libraryCids[cid] = true; @@ -219,7 +220,7 @@ const migrateUsersTable = async (testing = false) => { const hasConflict = conflicts.includes(id); conflicts.push(id); if (hasConflict) { - console.log(`changing id for saved copy ${id} in ${user.username} files`); + Logging.log(`changing id for saved copy ${id} in ${user.username} files`); id = uuid(); } @@ -264,7 +265,7 @@ const migrateUsersTable = async (testing = false) => { newFiles.push(newFile); } if (testing) { - // console.log(newFiles); + // Logging.log(newFiles); } else { await DB.insert(newFiles).into("files"); } @@ -276,11 +277,11 @@ const migrateUsersTable = async (testing = false) => { } } if (count % 100 === 0) { - console.log(`${count} users done`); + Logging.log(`${count} users done`); } count += 1; } - console.log("finished migrating users table"); + Logging.log("finished migrating users table"); }; const migrateSlatesTable = async (testing = false) => { @@ -288,7 +289,7 @@ const migrateSlatesTable = async (testing = false) => { let count = 0; for (let slate of slates) { if (!slate.data.ownerId) { - console.log({ slateMissingOwnerId: slate }); + Logging.log({ slateMissingOwnerId: slate }); continue; } if (slate.data.objects) { @@ -303,7 +304,7 @@ const migrateSlatesTable = async (testing = false) => { for (let file of slate.data.objects) { if (!file.url || !file.ownerId || !file.id) { if (!file.ownerId) { - console.log({ fileMissingOwnerId: file }); + Logging.log({ fileMissingOwnerId: file }); } continue; } @@ -311,7 +312,7 @@ const migrateSlatesTable = async (testing = false) => { //NOTE(martina): make sure there are no duplicated cids in a slate if (slateCids[cid]) { - console.log(`found duplicate file cid ${cid} in slate`); + Logging.log(`found duplicate file cid ${cid} in slate`); continue; } slateCids[cid] = true; @@ -338,7 +339,7 @@ const migrateSlatesTable = async (testing = false) => { !Strings.isEmpty(file.author)) ) { if (!matchingFile.data) { - console.log("Matching file did not have data"); + Logging.log("Matching file did not have data"); continue; } @@ -355,7 +356,7 @@ const migrateSlatesTable = async (testing = false) => { }, }); } else { - console.log({ + Logging.log({ data: { ...matchingFile.data, name: file.title ? file.title.substring(0, 255) : "", @@ -380,18 +381,18 @@ const migrateSlatesTable = async (testing = false) => { } } if (count % 100 === 0) { - console.log(`${count} slates done`); + Logging.log(`${count} slates done`); } // if (testing) { // if (count >= 50) { // return; // } - // console.log(objects); + // Logging.log(objects); // } count += 1; } } - console.log("finished migrating slates table"); + Logging.log("finished migrating slates table"); }; //make a function that double checks correctness: finds any duplicate fileId, ownerId in files. and any duplicate fileid slateid in slate_files @@ -421,7 +422,7 @@ const migrateActivityTable = async (testing = false) => { slateId = event.data.context?.slate?.id; fileId = event.data.context?.file?.id; if (!slateId || !fileId) { - // console.log(event.data); + // Logging.log(event.data); continue; } fileId = fileId.replace("data-", ""); @@ -438,12 +439,12 @@ const migrateActivityTable = async (testing = false) => { createdAt, }).into("activity"); } catch (e) { - console.log(e); + Logging.log(e); } } if (testing) { - console.log({ + Logging.log({ id, ownerId, userId, @@ -458,7 +459,7 @@ const migrateActivityTable = async (testing = false) => { count += 1; } } - console.log("finished migrating activity table"); + Logging.log("finished migrating activity table"); }; // MARK: - adding new fields and reformatting @@ -469,14 +470,14 @@ const modifySlatesTable = async (testing = false) => { const id = slate.id; const ownerId = slate.data.ownerId; if (!ownerId) { - console.log(slate); + Logging.log(slate); continue; } if (!testing) { await DB.from("slates").where("id", id).update({ ownerId, isPublic: slate.data.public }); } } - console.log("finished modify slates table"); + Logging.log("finished modify slates table"); }; const modifyUsersTable = async (testing = false) => { @@ -502,12 +503,12 @@ const modifyUsersTable = async (testing = false) => { if (count === 10) { return; } - console.log(data); + Logging.log(data); } else { await Data.updateUserById({ id, data }); } } - console.log("finished modify users table"); + Logging.log("finished modify users table"); }; // MARK: - deleting original data source @@ -525,7 +526,7 @@ const cleanUsersTable = async () => { onboarding: user.data.onboarding, status: user.data.status, }; - // console.log(data); + // Logging.log(data); await DB.from("users").where("id", id).update({ data }); } }; @@ -551,8 +552,8 @@ const cleanSlatesTable = async () => { preview: slate.data.preview, tags: slate.data.tags, }; - // console.log(layouts?.layout); - // console.log(data); + // Logging.log(layouts?.layout); + // Logging.log(data); await DB.from("slates").where("id", id).update({ data }); } }; @@ -569,11 +570,11 @@ const dropOldTables = async () => { const wipeNewTables = async () => { let numDeleted = await DB("slate_files").del(); - console.log(`${numDeleted} deleted from slate_files`); + Logging.log(`${numDeleted} deleted from slate_files`); numDeleted = await DB("activity").del(); - console.log(`${numDeleted} deleted from activity`); + Logging.log(`${numDeleted} deleted from activity`); numDeleted = await DB("files").del(); - console.log(`${numDeleted} deleted from files`); + Logging.log(`${numDeleted} deleted from files`); }; const runScript = async () => { @@ -603,7 +604,7 @@ const runScript = async () => { // await cleanSlatesTable(); await dropOldTables(); - console.log("Finished running. Hit CTRL + C to quit"); + Logging.log("Finished running. Hit CTRL + C to quit"); }; runScript(); diff --git a/scripts/memory-burn.js b/scripts/memory-burn.js index 09e46d40..7385af11 100644 --- a/scripts/memory-burn.js +++ b/scripts/memory-burn.js @@ -1,3 +1,5 @@ +import * as Logging from "~/common/logging"; + // Source // https://github.com/Data-Wrangling-with-JavaScript/nodejs-memory-test/blob/master/index.js // Small program to test the maximum amount of allocations in multiple blocks. @@ -8,13 +10,13 @@ // Allocate a certain size to test if it can be done. // function alloc(size) { - const numbers = size / 8; - const arr = []; - arr.length = numbers; // Simulate allocation of 'size' bytes. - for (let i = 0; i < numbers; i++) { - arr[i] = i; - } - return arr; + const numbers = size / 8; + const arr = []; + arr.length = numbers; // Simulate allocation of 'size' bytes. + for (let i = 0; i < numbers; i++) { + arr[i] = i; + } + return arr; } // @@ -26,38 +28,33 @@ const allocations = []; // Allocate successively larger sizes, doubling each time until we hit the limit. // function allocToMax() { - console.log("[ starting memory burn ]"); + Logging.log("[ starting memory burn ]"); - const field = "heapUsed"; + const field = "heapUsed"; + const mu = process.memoryUsage(); + Logging.log(mu); + const gbStart = mu[field] / 1024 / 1024 / 1024; + Logging.log(`[ memory burn ] ${Math.round(gbStart * 100) / 100} GB`); + + let allocationStep = 100 * 1024; + + while (true) { + // Allocate memory. + const allocation = alloc(allocationStep); + + // Allocate and keep a reference so the allocated memory isn't garbage collected. + allocations.push(allocation); + + // Check how much memory is now allocated. const mu = process.memoryUsage(); - console.log(mu); - const gbStart = mu[field] / 1024 / 1024 / 1024; - console.log( - `[ memory burn ] ${Math.round(gbStart * 100) / 100} GB` - ); - - let allocationStep = 100 * 1024; - - while (true) { - // Allocate memory. - const allocation = alloc(allocationStep); - - // Allocate and keep a reference so the allocated memory isn't garbage collected. - allocations.push(allocation); - - // Check how much memory is now allocated. - const mu = process.memoryUsage(); - const mbNow = mu[field] / 1024 / 1024 / 1024; - //console.log(`Total allocated ${Math.round(mbNow * 100) / 100} GB`); - console.log( - `[ allocated since start ] ${Math.round((mbNow - gbStart) * 100) / - 100} GB` - ); - - // Infinite loop, never get here. - } + const mbNow = mu[field] / 1024 / 1024 / 1024; + //Logging.log(`Total allocated ${Math.round(mbNow * 100) / 100} GB`); + Logging.log(`[ allocated since start ] ${Math.round((mbNow - gbStart) * 100) / 100} GB`); // Infinite loop, never get here. + } + + // Infinite loop, never get here. } allocToMax(); diff --git a/scripts/privacy-and-counts-migration.js b/scripts/privacy-and-counts-migration.js index dbb01780..85a1f4c5 100644 --- a/scripts/privacy-and-counts-migration.js +++ b/scripts/privacy-and-counts-migration.js @@ -1,7 +1,9 @@ import configs from "~/knexfile"; import knex from "knex"; + import { v4 as uuid } from "uuid"; +import * as Logging from "~/common/logging"; import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; @@ -11,7 +13,7 @@ const envConfig = configs["development"]; const DB = knex(envConfig); -console.log(`RUNNING: files-migration.js`); +Logging.log(`RUNNING: files-migration.js`); const makeFilesPublic = async () => { let publicFiles = await DB.from("files") @@ -31,9 +33,9 @@ const getSlateSubscriberAndFileCount = async () => { subscriberCount = subscriberCount.pop().count; let fileCount = await DB("slate_files").where("slateId", slate.id).count(); fileCount = fileCount.pop().count; - // console.log(slate.id); - // console.log(subscriberCount); - // console.log(fileCount); + // Logging.log(slate.id); + // Logging.log(subscriberCount); + // Logging.log(fileCount); await DB("slates").where("id", slate.id).update({ subscriberCount, @@ -51,10 +53,10 @@ const getUserFollowerAndFileAndSlateCount = async () => { fileCount = fileCount.pop().count; let slateCount = await DB("slates").where({ ownerId: user.id, isPublic: true }).count(); slateCount = slateCount.pop().count; - console.log(user.id); - console.log(followerCount); - console.log(fileCount); - console.log(slateCount); + Logging.log(user.id); + Logging.log(followerCount); + Logging.log(fileCount); + Logging.log(slateCount); // await DB("users").where("id", user.id).update({ // followerCount, // fileCount, @@ -68,7 +70,7 @@ const runScript = async () => { // await getSlateSubscriberAndFileCount(); await getUserFollowerAndFileAndSlateCount(); - console.log("Finished running. Hit CTRL + C to quit"); + Logging.log("Finished running. Hit CTRL + C to quit"); }; runScript(); diff --git a/scripts/repost-migration.js b/scripts/repost-migration.js index 78a7f746..ed533473 100644 --- a/scripts/repost-migration.js +++ b/scripts/repost-migration.js @@ -2,6 +2,7 @@ import configs from "~/knexfile"; import knex from "knex"; import { v4 as uuid } from "uuid"; +import * as Logging from "~/common/logging"; import * as Utilities from "~/node_common/utilities"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; @@ -11,7 +12,7 @@ const envConfig = configs["production"]; const DB = knex(envConfig); -console.log(`RUNNING: files-migration.js`); +Logging.log(`RUNNING: files-migration.js`); const saveCopyReposts = async () => { let repostedFiles = await DB.column( @@ -28,10 +29,10 @@ const saveCopyReposts = async () => { .join("files", "files.id", "=", "slate_files.fileId") .join("users", "users.id", "=", "slates.ownerId") .whereRaw("?? != ??", ["files.ownerId", "slates.ownerId"]); - // console.log(repostedFiles.length); + // Logging.log(repostedFiles.length); for (let item of repostedFiles) { - console.log(item); + Logging.log(item); // continue; let user = { data: item.data }; let { buckets, bucketKey, bucketRoot } = await Utilities.getBucketAPIFromUserToken({ @@ -46,7 +47,7 @@ const saveCopyReposts = async () => { cid: item.cid, }); } catch (e) { - console.log(e); + Logging.log(e); } const duplicateFiles = await Data.getFilesByCids({ @@ -56,7 +57,7 @@ const saveCopyReposts = async () => { if (duplicateFiles.length) { if (!duplicateFiles[0].isPublic && item.isPublic) { - console.log("UPDATE PUBLIC FOR FILE"); + Logging.log("UPDATE PUBLIC FOR FILE"); await DB.from("files").where("id", item.fileId).update({ isPublic: true }); } } else { @@ -83,14 +84,14 @@ const removeReposts = async () => { }) .del() .returning("*"); - console.log(repostedFiles); + Logging.log(repostedFiles); }; const runScript = async () => { await saveCopyReposts(); // await removeReposts(); - console.log("Finished running. Hit CTRL + C to quit"); + Logging.log("Finished running. Hit CTRL + C to quit"); }; runScript(); diff --git a/scripts/seed-database.js b/scripts/seed-database.js index 63eaf264..deaa7a86 100644 --- a/scripts/seed-database.js +++ b/scripts/seed-database.js @@ -1,13 +1,15 @@ import configs from "~/knexfile"; import knex from "knex"; +import * as Logging from "~/common/logging"; + const envConfig = configs["development"]; -console.log(`SETUP: database`, envConfig); +Logging.log(`SETUP: database`, envConfig); const db = knex(envConfig); -console.log(`RUNNING: seed-database.js`); +Logging.log(`RUNNING: seed-database.js`); // -------------------------- // SCRIPTS @@ -180,5 +182,5 @@ Promise.all([ createTwitterTokensTable, ]); -console.log(`FINISHED: seed-database.js`); -console.log(` CTRL +C to return to terminal.`); +Logging.log(`FINISHED: seed-database.js`); +Logging.log(` CTRL +C to return to terminal.`); diff --git a/scripts/setup-database.js b/scripts/setup-database.js index ee128e51..7f9b8529 100644 --- a/scripts/setup-database.js +++ b/scripts/setup-database.js @@ -1,15 +1,17 @@ import configs from "~/knexfile"; import knex from "knex"; +import * as Logging from "~/common/logging"; + const envConfig = configs["development"]; -console.log(`SETUP: database`, envConfig); +Logging.log(`SETUP: database`, envConfig); const db = knex(envConfig); -console.log(`RUNNING: setup-database.js`); +Logging.log(`RUNNING: setup-database.js`); Promise.all([db.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')]); -console.log(`FINISHED: setup-database.js`); -console.log(` CTRL +C to return to terminal.`); +Logging.log(`FINISHED: setup-database.js`); +Logging.log(` CTRL +C to return to terminal.`); diff --git a/scripts/worker-analytics.js b/scripts/worker-analytics.js index 5858ebd1..83b8ab32 100644 --- a/scripts/worker-analytics.js +++ b/scripts/worker-analytics.js @@ -3,11 +3,12 @@ import knex from "knex"; import * as Data from "~/node_common/data"; import * as Strings from "~/common/strings"; +import * as Logging from "~/common/logging"; const envConfig = configs["development"]; const db = knex(envConfig); -console.log(`RUNNING: worker-analytics.js`); +Logging.log(`RUNNING: worker-analytics.js`); function sortObject(obj) { var arr = []; @@ -49,13 +50,13 @@ const run = async () => { userMap = userMap.map((each, index) => { return { ...each, index, value: Strings.bytesToSize(each.value) }; }); - console.log(userMap); - console.log("TOTAL USER COUNT", count); - console.log("TOTAL BYTES", bytes); - console.log("TOTAL BYTES (CONVERTED)", Strings.bytesToSize(bytes)); + Logging.log(userMap); + Logging.log("TOTAL USER COUNT", count); + Logging.log("TOTAL BYTES", bytes); + Logging.log("TOTAL BYTES (CONVERTED)", Strings.bytesToSize(bytes)); }; // run(); -console.log(`FINISHED: worker-analytics.js`); -console.log(` CTRL +C to return to terminal.`); +Logging.log(`FINISHED: worker-analytics.js`); +Logging.log(` CTRL +C to return to terminal.`); diff --git a/scripts/worker-heavy-stones.js b/scripts/worker-heavy-stones.js index 153e18ca..3651cda6 100644 --- a/scripts/worker-heavy-stones.js +++ b/scripts/worker-heavy-stones.js @@ -3,6 +3,7 @@ import knex from "knex"; import fs from "fs-extra"; import "isomorphic-fetch"; +import * as Logging from "~/common/logging"; import * as Environment from "~/node_common/environment"; import * as Data from "~/node_common/data"; import * as Utilities from "~/node_common/utilities"; @@ -36,7 +37,7 @@ const TEXTILE_KEY_INFO = { secret: Environment.TEXTILE_HUB_SECRET, }; -console.log(`RUNNING: worker-heavy-stones.js`); +Logging.log(`RUNNING: worker-heavy-stones.js`); const delay = async (waitMs) => { return await new Promise((resolve) => setTimeout(resolve, waitMs)); @@ -220,9 +221,9 @@ const run = async () => { const dealToSave = storageDeals[d]; Logs.note(`Saving ${dealToSave.dealId} ...`); - console.log(dealToSave); + Logging.log(dealToSave); const existing = await db.select("*").from("deals").where(hasDealId(dealToSave.dealId)); - console.log(existing); + Logging.log(existing); if (existing && !existing.error && existing.length) { Logs.error(`${dealToSave.dealId} is already saved.`); @@ -272,8 +273,8 @@ const run = async () => { // NOTE(jim): Determine open deals try { const { current, history } = await buckets.archives(keyBucket.key); - console.log(current); - console.log(history); + Logging.log(current); + Logging.log(history); } catch (e) { Logs.error(e.message); continue; @@ -312,8 +313,8 @@ const run = async () => { // NOTE(jim): Determine open deals try { const { current, history } = await buckets.archives(keyBucket.key); - console.log(current); - console.log(history); + Logging.log(current); + Logging.log(history); } catch (e) { Logs.error(e.message); continue; @@ -464,8 +465,8 @@ const run = async () => { Logs.task(`Show us the history!`); try { const { current, history } = await buckets.archives(targetBucket.key); - console.log(current); - console.log(history); + Logging.log(current); + Logging.log(history); } catch (e) { Logs.error(e.message); continue; @@ -482,16 +483,16 @@ const run = async () => { } } - console.log("\n"); + Logging.log("\n"); } Logs.task(`total storage per run: ${Strings.bytesToSize(bytes)}`); Logs.task(`total storage per run (with replication x5): ${Strings.bytesToSize(bytes * 5)}`); Logs.task(`creating slate-storage-addresses.json`); - console.log(`${STORAGE_BOT_NAME} finished. \n\n`); - console.log(`FINISHED: worker-heavy-stones.js`); - console.log(` CTRL +C to return to terminal.`); + Logging.log(`${STORAGE_BOT_NAME} finished. \n\n`); + Logging.log(`FINISHED: worker-heavy-stones.js`); + Logging.log(` CTRL +C to return to terminal.`); }; run(); diff --git a/server.js b/server.js index bc3897aa..16168e80 100644 --- a/server.js +++ b/server.js @@ -4,7 +4,7 @@ import * as Utilities from "~/node_common/utilities"; import * as Serializers from "~/node_common/serializers"; import * as ViewerManager from "~/node_common/managers/viewer"; import * as Websocket from "~/node_common/nodejs-websocket"; -import * as NodeLogging from "~/node_common/node-logging"; +import * as Logging from "~/common/logging"; import * as Validations from "~/common/validations"; import * as Window from "~/common/window"; import * as Strings from "~/common/strings"; @@ -208,7 +208,6 @@ app.prepare().then(async () => { if (!redirected) { page.params = req.query; } - console.log({ page }); if (!page) { return handler(req, res, req.url, { @@ -543,14 +542,14 @@ app.prepare().then(async () => { if (e) throw e; Websocket.create(); - NodeLogging.log(`started on http://localhost:${Environment.PORT}`); + Logging.log(`started on http://localhost:${Environment.PORT}`); exploreSlates = await fetchExploreSlates(); const filecoinNumber = new FilecoinNumber("10000", "attoFil"); - console.log(`Testing Values: ${filecoinNumber.toPicoFil()} PICO FIL`); - console.log(`Testing Values: ${filecoinNumber.toAttoFil()} ATTO FIL`); - console.log(`Testing Values: ${filecoinNumber.toFil()} FIL`); + Logging.log(`Testing Values: ${filecoinNumber.toPicoFil()} PICO FIL`); + Logging.log(`Testing Values: ${filecoinNumber.toAttoFil()} ATTO FIL`); + Logging.log(`Testing Values: ${filecoinNumber.toFil()} FIL`); }); });