external user recommendation

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

View file

@ -159,3 +159,10 @@ drive:
# Summaly proxy # Summaly proxy
# summalyProxy: "http://example.com" # 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; google_maps_api_key: string;
clusterLimit?: number; 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 User, { pack, ILocalUser } from '../../../../models/user';
import { getFriendIds } from '../../common/get-friends'; import { getFriendIds } from '../../common/get-friends';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import * as request from 'request'
import { ILocalUser } from '../../../../models/user'
import config from '../../../../config'
export const meta = { export const meta = {
desc: { desc: {
@ -15,6 +18,38 @@ export const meta = {
}; };
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { 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 // Get 'limit' parameter
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
@ -55,4 +90,5 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>
await pack(user, me, { detail: true })))); await pack(user, me, { detail: true }))));
}
}); });