external user recommendation

This commit is contained in:
Hakaba Hitoyo 2018-10-06 16:03:18 +09:00
parent 48e4dc75f4
commit 7019ddbfc7
3 changed files with 84 additions and 35 deletions

View File

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

View File

@ -96,6 +96,12 @@ export type Source = {
google_maps_api_key: string;
clusterLimit?: number;
user_recommendation: {
external: boolean;
engine: string;
timeout: number;
};
};
/**

View File

@ -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 }))));
}
});