Remove unused follows-related code/routes
This commit is contained in:
parent
a0d602bcab
commit
fe51bcfe1a
3 changed files with 0 additions and 84 deletions
|
|
@ -1,66 +0,0 @@
|
||||||
/**
|
|
||||||
* @format
|
|
||||||
*/
|
|
||||||
const Common = require('shock-common')
|
|
||||||
const Logger = require('../../../../config/log')
|
|
||||||
const size = require('lodash/size')
|
|
||||||
|
|
||||||
const Utils = require('../utils')
|
|
||||||
const Key = require('../key')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Common.Schema.Follow} Follow
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws {TypeError}
|
|
||||||
* @returns {Promise<Record<string, Common.Schema.Follow>>}
|
|
||||||
*/
|
|
||||||
exports.currentFollows = async () => {
|
|
||||||
/**
|
|
||||||
* @type {Record<string, Common.Schema.Follow>}
|
|
||||||
*/
|
|
||||||
const raw = await Utils.tryAndWait(
|
|
||||||
(_, user) =>
|
|
||||||
new Promise(res =>
|
|
||||||
// @ts-expect-error
|
|
||||||
user.get(Key.FOLLOWS).load(res)
|
|
||||||
),
|
|
||||||
v => {
|
|
||||||
if (typeof v !== 'object' || v === null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// load sometimes returns an empty set on the first try
|
|
||||||
if (size(v) === 0) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// sometimes it returns empty sub objects
|
|
||||||
return Object.values(v)
|
|
||||||
.filter(Common.Schema.isObj)
|
|
||||||
.some(obj => size(obj) === 0)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (typeof raw !== 'object' || raw === null) {
|
|
||||||
Logger.error(
|
|
||||||
`Expected user.follows to be an object but instead got: ${JSON.stringify(
|
|
||||||
raw
|
|
||||||
)}`
|
|
||||||
)
|
|
||||||
throw new TypeError('Could not get follows, not an object')
|
|
||||||
}
|
|
||||||
|
|
||||||
const clean = {
|
|
||||||
...raw
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [key, followOrNull] of Object.entries(clean)) {
|
|
||||||
if (!Common.Schema.isFollow(followOrNull)) {
|
|
||||||
delete clean[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return clean
|
|
||||||
}
|
|
||||||
|
|
@ -119,6 +119,5 @@ const getUserInfo = async publicKey => {
|
||||||
|
|
||||||
module.exports.getMyUser = getMyUser
|
module.exports.getMyUser = getMyUser
|
||||||
module.exports.getUserInfo = getUserInfo
|
module.exports.getUserInfo = getUserInfo
|
||||||
module.exports.Follows = require('./follows')
|
|
||||||
|
|
||||||
module.exports.getAnUser = User.getAnUser
|
module.exports.getAnUser = User.getAnUser
|
||||||
|
|
|
||||||
|
|
@ -2327,21 +2327,6 @@ module.exports = async (
|
||||||
* @prop {(string|undefined)=} publicKey
|
* @prop {(string|undefined)=} publicKey
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {RequestHandler<FollowsRouteParams>}
|
|
||||||
*/
|
|
||||||
const apiGunFollowsGet = async (_, res) => {
|
|
||||||
try {
|
|
||||||
const currFollows = await GunGetters.Follows.currentFollows()
|
|
||||||
|
|
||||||
return res.status(200).json(currFollows)
|
|
||||||
} catch (err) {
|
|
||||||
return res.status(500).json({
|
|
||||||
errorMessage: err.message || 'Unknown ERR at GET /api/follows'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {RequestHandler<FollowsRouteParams>}
|
* @type {RequestHandler<FollowsRouteParams>}
|
||||||
*/
|
*/
|
||||||
|
|
@ -2398,8 +2383,6 @@ module.exports = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ap.get('/api/gun/follows/', apiGunFollowsGet)
|
|
||||||
ap.get('/api/gun/follows/:publicKey', apiGunFollowsGet)
|
|
||||||
ap.put(`/api/gun/follows/:publicKey`, apiGunFollowsPut)
|
ap.put(`/api/gun/follows/:publicKey`, apiGunFollowsPut)
|
||||||
ap.delete(`/api/gun/follows/:publicKey`, apiGunFollowsDelete)
|
ap.delete(`/api/gun/follows/:publicKey`, apiGunFollowsDelete)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue