diff --git a/packages/login-with-qq/README.md b/packages/login-with-qq/README.md deleted file mode 100644 index 9cf59d171..000000000 --- a/packages/login-with-qq/README.md +++ /dev/null @@ -1 +0,0 @@ -# Login-With-QQ diff --git a/packages/login-with-qq/lib.ts b/packages/login-with-qq/lib.ts deleted file mode 100644 index f6c130ccd..000000000 --- a/packages/login-with-qq/lib.ts +++ /dev/null @@ -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, -}; diff --git a/packages/login-with-qq/locales/zh.yaml b/packages/login-with-qq/locales/zh.yaml deleted file mode 100644 index 02169e562..000000000 --- a/packages/login-with-qq/locales/zh.yaml +++ /dev/null @@ -1 +0,0 @@ -Login with QQ: 使用 QQ 登录 \ No newline at end of file diff --git a/packages/login-with-qq/package.json b/packages/login-with-qq/package.json deleted file mode 100644 index 8ea1722b6..000000000 --- a/packages/login-with-qq/package.json +++ /dev/null @@ -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 ", - "license": "AGPL-3.0-or-later", - "preferUnplugged": true, - "dependencies": { - "ws": "^8.5.0" - }, - "devDependencies": { - "@types/ws": "^8.5.3" - } -} diff --git a/packages/login-with-qq/service.ts b/packages/login-with-qq/service.ts deleted file mode 100644 index 14d1fb909..000000000 --- a/packages/login-with-qq/service.ts +++ /dev/null @@ -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 = {}; - 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); diff --git a/packages/login-with-qq/setting.yaml b/packages/login-with-qq/setting.yaml deleted file mode 100644 index 2ffa48318..000000000 --- a/packages/login-with-qq/setting.yaml +++ /dev/null @@ -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 \ No newline at end of file