Remove unused code / routes

This commit is contained in:
Daniel Lugo 2021-07-22 17:34:30 -04:00
parent e2e7c7cfc6
commit 233452e59b
3 changed files with 0 additions and 185 deletions

View file

@ -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

View file

@ -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<any>}
*/
//@returns {Promise<Common.SchemaTypes.User>}
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<any>}
*/
//@returns {Promise<Common.SchemaTypes.User>}
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

View file

@ -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