mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove /user/search
This commit is contained in:
1 parent
6762e22bae
commit
5c97bbf1ba
8 files changed
+74
-48
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.35.9",
|
"version": "2.36.0",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ registerValue('User', [
|
|||||||
['scope', 'Int'],
|
['scope', 'Int'],
|
||||||
['role', 'String'],
|
['role', 'String'],
|
||||||
['loginat', 'Date'],
|
['loginat', 'Date'],
|
||||||
['regat', 'Date'],
|
['regat', 'Date!'],
|
||||||
['priv', 'Int', 'User Privilege'],
|
['priv', 'Int!', 'User Privilege'],
|
||||||
|
['avatarUrl', 'String'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
registerResolver('Query', 'user(id: Int, uname: String, mail: String)', 'User', (arg, ctx) => {
|
registerResolver('Query', 'user(id: Int, uname: String, mail: String)', 'User', (arg, ctx) => {
|
||||||
@@ -43,12 +44,26 @@ registerResolver('Query', 'user(id: Int, uname: String, mail: String)', 'User',
|
|||||||
}, `Get a user by id, uname, or mail.
|
}, `Get a user by id, uname, or mail.
|
||||||
Returns current user if no argument is provided.`);
|
Returns current user if no argument is provided.`);
|
||||||
|
|
||||||
registerResolver('Query', 'users(ids: [Int], search: String)', '[User]', async (arg, ctx) => {
|
registerResolver('Query', 'users(ids: [Int], search: String, limit: Int, exact: Boolean)', '[User]', async (arg, ctx) => {
|
||||||
if (arg.ids) {
|
if (arg.ids?.length) {
|
||||||
const res = await user.getList(ctx.domainId, arg.ids);
|
const res = await user.getList(ctx.domainId, arg.ids);
|
||||||
return Object.keys(res).map((id) => res[+id]);
|
return Object.keys(res).map((id) => res[+id]);
|
||||||
}
|
}
|
||||||
return arg.search ? await user.getPrefixList(ctx.domainId, arg.search) : [];
|
if (!arg.search) return [];
|
||||||
|
const udoc = await user.getById(ctx.domainId, +arg.search)
|
||||||
|
|| await user.getByUname(ctx.domainId, arg.search)
|
||||||
|
|| await user.getByEmail(ctx.domainId, arg.search);
|
||||||
|
const udocs: User[] = arg.exact
|
||||||
|
? []
|
||||||
|
: await user.getPrefixList(ctx.domainId, arg.search, Math.min(arg.limit || 10, 10));
|
||||||
|
if (udoc && !udocs.find((i) => i._id === udoc._id)) {
|
||||||
|
udocs.pop();
|
||||||
|
udocs.unshift(udoc);
|
||||||
|
}
|
||||||
|
for (const i in udocs) {
|
||||||
|
udocs[i].avatarUrl = avatar(udocs[i].avatar);
|
||||||
|
}
|
||||||
|
return udocs;
|
||||||
}, 'Get a list of user by ids, or search users with the prefix.');
|
}, 'Get a list of user by ids, or search users with the prefix.');
|
||||||
|
|
||||||
class UserLoginHandler extends Handler {
|
class UserLoginHandler extends Handler {
|
||||||
@@ -275,28 +290,6 @@ class UserDeleteHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserSearchHandler extends Handler {
|
|
||||||
@param('q', Types.String)
|
|
||||||
@param('exectMatch', Types.Boolean)
|
|
||||||
async get(domainId: string, q: string, exactMatch = false) {
|
|
||||||
let udoc = await user.getById(domainId, +q);
|
|
||||||
const udocs: User[] = udoc ? [udoc] : [];
|
|
||||||
if (!udocs.length) {
|
|
||||||
udoc = await user.getByUname(domainId, q);
|
|
||||||
if (udoc) udocs.push(udoc);
|
|
||||||
else {
|
|
||||||
udoc = await user.getByEmail(domainId, q);
|
|
||||||
if (udoc) udocs.push(udoc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!exactMatch) udocs.push(...await user.getPrefixList(domainId, q, 20));
|
|
||||||
for (const i in udocs) {
|
|
||||||
udocs[i].avatarUrl = avatar(udocs[i].avatar);
|
|
||||||
}
|
|
||||||
this.response.body = udocs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class OauthHandler extends Handler {
|
class OauthHandler extends Handler {
|
||||||
@param('type', Types.String)
|
@param('type', Types.String)
|
||||||
async get(domainId: string, type: string) {
|
async get(domainId: string, type: string) {
|
||||||
@@ -355,7 +348,6 @@ export async function apply() {
|
|||||||
Route('user_logout', '/logout', UserLogoutHandler, PRIV.PRIV_USER_PROFILE);
|
Route('user_logout', '/logout', UserLogoutHandler, PRIV.PRIV_USER_PROFILE);
|
||||||
Route('user_lostpass', '/lostpass', UserLostPassHandler);
|
Route('user_lostpass', '/lostpass', UserLostPassHandler);
|
||||||
Route('user_lostpass_with_code', '/lostpass/:code', UserLostPassWithCodeHandler);
|
Route('user_lostpass_with_code', '/lostpass/:code', UserLostPassWithCodeHandler);
|
||||||
Route('user_search', '/user/search', UserSearchHandler, PRIV.PRIV_USER_PROFILE);
|
|
||||||
Route('user_delete', '/user/delete', UserDeleteHandler, PRIV.PRIV_USER_PROFILE);
|
Route('user_delete', '/user/delete', UserDeleteHandler, PRIV.PRIV_USER_PROFILE);
|
||||||
Route('user_detail', '/user/:uid', UserDetailHandler);
|
Route('user_detail', '/user/:uid', UserDetailHandler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
import React, { forwardRef } from 'react';
|
import React, { forwardRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import request from 'vj/utils/request';
|
import api, { e } from 'vj/utils/api';
|
||||||
import AutoComplete from './AutoComplete';
|
import AutoComplete from './AutoComplete';
|
||||||
|
|
||||||
// eslint-disable-next-line prefer-arrow-callback
|
// eslint-disable-next-line prefer-arrow-callback
|
||||||
const UserSelectAutoComplete = forwardRef(function UserSelectAutoComplete(props, ref) {
|
const UserSelectAutoComplete = forwardRef(function UserSelectAutoComplete(props, ref) {
|
||||||
const itemsFn = (query) => request.get('/user/search', { q: query });
|
const itemsFn = (query) => api(e`
|
||||||
|
users(search: ${query}) {
|
||||||
|
_id
|
||||||
|
uname
|
||||||
|
avatarUrl
|
||||||
|
}
|
||||||
|
`, ['data', 'users']);
|
||||||
|
|
||||||
const itemText = (user) => user.uname || user;
|
const itemText = (user) => user.uname || user;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
||||||
import list from 'emojis-list';
|
import list from 'emojis-list';
|
||||||
import keyword from 'emojis-keywords';
|
import keyword from 'emojis-keywords';
|
||||||
import request from 'vj/utils/request';
|
import api, { e } from 'vj/utils/api';
|
||||||
import api from 'vj/utils/api';
|
|
||||||
|
|
||||||
const qqEmojies = [
|
const qqEmojies = [
|
||||||
'weixiao',
|
'weixiao',
|
||||||
@@ -168,7 +167,13 @@ monaco.languages.registerCompletionItemProvider('markdown', {
|
|||||||
endColumn: word.endColumn,
|
endColumn: word.endColumn,
|
||||||
};
|
};
|
||||||
if (prefix === '@') {
|
if (prefix === '@') {
|
||||||
const users = await request.get(`/user/search?q=${word.word}`);
|
const users = await api(e`
|
||||||
|
users(search: ${word.word}) {
|
||||||
|
_id
|
||||||
|
uname
|
||||||
|
avatarUrl
|
||||||
|
}
|
||||||
|
`, ['data', 'users']);
|
||||||
return {
|
return {
|
||||||
suggestions: users.map((i) => ({
|
suggestions: users.map((i) => ({
|
||||||
label: `@${i.uname} (UID=${i._id})`,
|
label: `@${i.uname} (UID=${i._id})`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.21.5",
|
"version": "4.21.6",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { NamedPage } from 'vj/misc/Page';
|
import { NamedPage } from 'vj/misc/Page';
|
||||||
import request from 'vj/utils/request';
|
import api, { e } from 'vj/utils/api';
|
||||||
import loadReactRedux from 'vj/utils/loadReactRedux';
|
import loadReactRedux from 'vj/utils/loadReactRedux';
|
||||||
import parseQueryString from 'vj/utils/parseQueryString';
|
import parseQueryString from 'vj/utils/parseQueryString';
|
||||||
|
|
||||||
@@ -79,16 +79,16 @@ const page = new NamedPage('home_messages', () => {
|
|||||||
*/
|
*/
|
||||||
async function loadSendTarget() {
|
async function loadSendTarget() {
|
||||||
const queryString = parseQueryString();
|
const queryString = parseQueryString();
|
||||||
if (!queryString.target) {
|
if (!queryString.target) return;
|
||||||
return;
|
const user = await api(e`
|
||||||
}
|
users(search: ${queryString.target}, exact: true) {
|
||||||
const user = await request.get('/user/search', {
|
_id
|
||||||
q: queryString.target,
|
uname
|
||||||
exact_match: true,
|
avatarUrl
|
||||||
});
|
mail
|
||||||
if (!user || user.length === 0) {
|
}
|
||||||
return;
|
`, ['data', 'users']);
|
||||||
}
|
if (!user?.length) return;
|
||||||
createDialog(user[0]);
|
createDialog(user[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
<span class="icon icon-edit"></span>
|
<span class="icon icon-edit"></span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a class="profile-header__contact-item" href="{{ url('home_messages', query={target_uid:udoc._id}) }}" target="_blank" data-tooltip="{{ _('Send Message') }}">
|
<a class="profile-header__contact-item" href="{{ url('home_messages', query={target:udoc._id}) }}" target="_blank" data-tooltip="{{ _('Send Message') }}">
|
||||||
<span class="icon icon-comment--multiple"></span>
|
<span class="icon icon-comment--multiple"></span>
|
||||||
</a>
|
</a>
|
||||||
{% if udoc['mail'] %}
|
{% if udoc['mail'] %}
|
||||||
|
|||||||
@@ -1,3 +1,26 @@
|
|||||||
import request from './request';
|
import request from './request';
|
||||||
|
|
||||||
export default (q: string) => request.post('/api', { query: q.trim() });
|
export default async (q: string, path: string[] = []) => {
|
||||||
|
let query = q.trim();
|
||||||
|
if (!query.startsWith('query')) query = `query{${query}}`;
|
||||||
|
const res = await request.post('/api', { query });
|
||||||
|
if (res.errors) throw new Error(res.errors[0].message);
|
||||||
|
let cursor = res;
|
||||||
|
for (const p of path) {
|
||||||
|
cursor = cursor[p];
|
||||||
|
if (!cursor) return undefined;
|
||||||
|
}
|
||||||
|
return cursor;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const e = (
|
||||||
|
pieces: TemplateStringsArray,
|
||||||
|
...templates: (string | number)[]
|
||||||
|
) => {
|
||||||
|
let res = '';
|
||||||
|
for (let i = 0; i < pieces.length; i++) {
|
||||||
|
res += pieces[i];
|
||||||
|
if (templates[i]) res += JSON.stringify(templates[i]);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user