remove deprecated plugin login-with-qq

pull/334/head
undefined 3 years ago
parent 20b11829d8
commit 1fed6ff2f1

@ -1,43 +0,0 @@
import 'hydrooj';
import 'hydrooj/src/utils';
declare module 'hydrooj/src/interface' {
interface Lib {
oauth_qq: typeof import('./lib'),
}
}
async function get() {
const { system, token } = global.Hydro.model;
const secret = String.random(8);
const [id, [tokenId]] = await Promise.all([
system.get('login-with-qq.id'),
token.add(token.TYPE_OAUTH, 600, { redirect: this.request.referer, secret }),
]);
const message = `Please send "login ${secret}" to qq account ${id}, and then use the link below:\n /oauth/qq/callback?state=${tokenId}`;
this.response.body = {
code: tokenId, secret, id, message,
};
}
async function callback({ state }) {
const { token } = global.Hydro.model;
const { InvalidTokenError } = global.Hydro.error;
const s = await token.get(state, token.TYPE_OAUTH);
if (!s || !s.email) throw new InvalidTokenError(state);
const ret = {
_id: s.email,
email: s.email,
bio: '',
uname: [s.username],
};
this.response.redirect = s.redirect;
await token.del(s._id, token.TYPE_OAUTH);
return ret;
}
global.Hydro.lib.oauth_qq = {
text: 'Login with QQ',
callback,
get,
};

@ -1 +0,0 @@
Login with QQ: 使用 QQ 登录

@ -1,15 +0,0 @@
{
"name": "@hydrooj/login-with-qq",
"version": "0.1.0",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
"preferUnplugged": true,
"dependencies": {
"ws": "^8.5.0"
},
"devDependencies": {
"@types/ws": "^8.5.3"
}
}

@ -1,44 +0,0 @@
import WebSocket from 'ws';
import { } from 'hydrooj';
import * as bus from 'hydrooj/src/service/bus';
declare module 'hydrooj' {
interface SystemKeys {
'login-with-qq.id': string,
'login-with-qq.url': string,
'login-with-qq.token': string,
}
}
export async function postInit() {
const { system, token } = global.Hydro.model;
const [url, accessToken] = system.getMany(['login-with-qq.url', 'login-with-qq.token']);
if (!url) return;
const headers: Record<string, string> = {};
if (accessToken) headers.Authorization = `Bearer ${accessToken}`;
const socket = new WebSocket(url, { headers });
socket.on('error', console.error);
socket.on('message', async (message) => {
const payload = JSON.parse(message.toString());
if (payload.post_type !== 'message') return;
if (payload.message.startsWith('login ')) {
const secret = payload.message.split(' ')[1];
await token.coll.updateOne(
{ secret, tokenType: token.TYPE_OAUTH },
{
$set: {
email: `${payload.sender.user_id}@qq.com`,
username: payload.sender.nickname,
},
},
);
}
});
await new Promise((resolve) => {
socket.once('open', () => {
resolve(null);
});
});
}
bus.once('app/started', postInit);

@ -1,15 +0,0 @@
url:
type: text
category: system
desc: cqhttp ws api url
name: url
token:
type: text
category: system
desc: cqhttp token
name: token
id:
type: text
category: system
desc: QQ account id
name: id
Loading…
Cancel
Save