mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 21:10:20 +01:00
external user recommendation
This commit is contained in:
parent
48e4dc75f4
commit
7019ddbfc7
3 changed files with 84 additions and 35 deletions
|
@ -159,3 +159,10 @@ drive:
|
|||
|
||||
# Summaly proxy
|
||||
# summalyProxy: "http://example.com"
|
||||
|
||||
# User recommendation
|
||||
user_recommendation:
|
||||
external: true
|
||||
engine: http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}}
|
||||
timeout: 300000
|
||||
|
||||
|
|
|
@ -96,6 +96,12 @@ export type Source = {
|
|||
google_maps_api_key: string;
|
||||
|
||||
clusterLimit?: number;
|
||||
|
||||
user_recommendation: {
|
||||
external: boolean;
|
||||
engine: string;
|
||||
timeout: number;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,9 @@ import $ from 'cafy';
|
|||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import Mute from '../../../../models/mute';
|
||||
import * as request from 'request'
|
||||
import { ILocalUser } from '../../../../models/user'
|
||||
import config from '../../../../config'
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -15,6 +18,38 @@ export const meta = {
|
|||
};
|
||||
|
||||
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||
var external = config.user_recommendation.external
|
||||
|
||||
if (external) {
|
||||
var userName = me.username
|
||||
var hostName = config.hostname
|
||||
var limit = params.limit
|
||||
var offset = params.offset
|
||||
var timeout = config.user_recommendation.timeout
|
||||
var engine = config.user_recommendation.engine
|
||||
var url
|
||||
url = engine
|
||||
url = url.replace('{{host}}', hostName)
|
||||
url = url.replace('{{user}}', userName)
|
||||
url = url.replace('{{limit}}', limit)
|
||||
url = url.replace('{{offset}}', offset)
|
||||
request(
|
||||
{
|
||||
url: url,
|
||||
timeout: timeout,
|
||||
json: true,
|
||||
followRedirect: true,
|
||||
followAllRedirects: true
|
||||
},
|
||||
function (error: any, response: any, body: any) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
res(body)
|
||||
} else {
|
||||
res([])
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
@ -55,4 +90,5 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
|
|||
// Serialize
|
||||
res(await Promise.all(users.map(async user =>
|
||||
await pack(user, me, { detail: true }))));
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue