From 233452e59b925798fef81ea1b3f824f45939085b Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 22 Jul 2021 17:34:30 -0400 Subject: [PATCH] Remove unused code / routes --- services/gunDB/contact-api/getters/index.js | 35 ------ services/gunDB/contact-api/getters/user.js | 129 -------------------- src/routes.js | 21 ---- 3 files changed, 185 deletions(-) delete mode 100644 services/gunDB/contact-api/getters/user.js diff --git a/services/gunDB/contact-api/getters/index.js b/services/gunDB/contact-api/getters/index.js index fb3223fe..8d8260fc 100644 --- a/services/gunDB/contact-api/getters/index.js +++ b/services/gunDB/contact-api/getters/index.js @@ -6,7 +6,6 @@ const Common = require('shock-common') const Key = require('../key') const Utils = require('../utils') -const User = require('./user') const { size } = require('lodash') /** @@ -85,39 +84,5 @@ const getMyUser = async () => { return u } -/** - * @param {string} publicKey - */ -const getUserInfo = async publicKey => { - const userInfo = await Utils.tryAndWait( - gun => - new Promise(res => - gun - .user(publicKey) - .get(Key.PROFILE) - .load(res) - ), - v => { - if (typeof v !== 'object') { - return true - } - - if (v === null) { - return true - } - - // load sometimes returns an empty set on the first try - return size(v) === 0 - } - ) - return { - publicKey, - avatar: userInfo.avatar, - displayName: userInfo.displayName - } -} module.exports.getMyUser = getMyUser -module.exports.getUserInfo = getUserInfo - -module.exports.getAnUser = User.getAnUser diff --git a/services/gunDB/contact-api/getters/user.js b/services/gunDB/contact-api/getters/user.js deleted file mode 100644 index f560d65c..00000000 --- a/services/gunDB/contact-api/getters/user.js +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @format - */ -const Common = require('shock-common') -const size = require('lodash/size') - -const Key = require('../key') -const Utils = require('../utils') - -/** - * @param {string} publicKey - * @returns {Promise} - */ -//@returns {Promise} -const getAnUser = async publicKey => { - const oldProfile = await Utils.tryAndWait( - (g, u) => { - const user = u._.sea.pub === publicKey ? u : g.user(publicKey) - - return new Promise(res => user.get(Key.PROFILE).load(res)) - }, - v => typeof v !== 'object' - ) - - const bio = await Utils.tryAndWait( - (g, u) => { - const user = u._.sea.pub === publicKey ? u : g.user(publicKey) - - return user.get(Key.BIO).then() - }, - v => typeof v !== 'string' - ) - - const lastSeenApp = await Utils.tryAndWait( - (g, u) => { - const user = u._.sea.pub === publicKey ? u : g.user(publicKey) - - return user.get(Key.LAST_SEEN_APP).then() - }, - v => typeof v !== 'number' - ) - - const lastSeenNode = await Utils.tryAndWait( - (g, u) => { - const user = u._.sea.pub === publicKey ? u : g.user(publicKey) - - return user.get(Key.LAST_SEEN_NODE).then() - }, - v => typeof v !== 'number' - ) - //@ts-ignore - /** @type {Common.SchemaTypes.User} */ - const u = { - avatar: oldProfile.avatar || null, - // @ts-ignore - bio: bio || null, - displayName: oldProfile.displayName || null, - // @ts-ignore - lastSeenApp: lastSeenApp || 0, - // @ts-ignore - lastSeenNode: lastSeenNode || 0, - // @ts-ignore - publicKey - } - - return u -} - -module.exports.getAnUser = getAnUser - -/** - * @returns {Promise} - */ -//@returns {Promise} -const getMyUser = async () => { - const oldProfile = await Utils.tryAndWait( - (_, user) => new Promise(res => user.get(Key.PROFILE).load(res)), - v => { - if (typeof v !== 'object') { - return true - } - - if (v === null) { - return true - } - - // load sometimes returns an empty set on the first try - return size(v) === 0 - } - ) - - const bio = await Utils.tryAndWait( - (_, user) => user.get(Key.BIO).then(), - v => typeof v !== 'string' - ) - - const lastSeenApp = await Utils.tryAndWait( - (_, user) => user.get(Key.LAST_SEEN_APP).then(), - v => typeof v !== 'number' - ) - - const lastSeenNode = await Utils.tryAndWait( - (_, user) => user.get(Key.LAST_SEEN_NODE).then(), - v => typeof v !== 'number' - ) - - const publicKey = await Utils.tryAndWait( - (_, user) => Promise.resolve(user.is && user.is.pub), - v => typeof v !== 'string' - ) - //@ts-ignore - /** @type {Common.SchemaTypes.User} */ - const u = { - avatar: oldProfile.avatar, - // @ts-ignore - bio, - displayName: oldProfile.displayName, - // @ts-ignore - lastSeenApp, - // @ts-ignore - lastSeenNode, - // @ts-ignore - publicKey - } - - return u -} - -module.exports.getMyUser = getMyUser diff --git a/src/routes.js b/src/routes.js index 44f262c4..09522e7f 100644 --- a/src/routes.js +++ b/src/routes.js @@ -2293,27 +2293,6 @@ module.exports = async ( } }) - app.post(`/api/gun/userInfo`, async (req, res) => { - try { - const { pubs } = req.body - const reqs = pubs.map( - e => - new Promise((res, rej) => { - GunGetters.getUserInfo(e) - .then(r => res(r)) - .catch(e => rej(e)) - }) - ) - const infos = await Promise.all(reqs) - return res.status(200).json({ - pubInfos: infos - }) - } catch (err) { - return res.status(500).json({ - errorMessage: err.message - }) - } - }) ///////////////////////////////// /** * @template P