名称変更とか
This commit is contained in:
parent
57e1ddcd3f
commit
116bade1c9
8 changed files with 54 additions and 18 deletions
4
LICENSE
4
LICENSE
|
@ -1,5 +1,5 @@
|
||||||
Misshaialert
|
Misskey Tools
|
||||||
Copyright (C) 2020 Xeltica
|
Copyright (C) 2020-2021 Xeltica
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Affero General Public License as
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"port": 4000,
|
"port": 4000,
|
||||||
"url": "https://misshaialert.com",
|
"url": "https://misskey.tools",
|
||||||
"db": {
|
"db": {
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 5432,
|
"port": 5432,
|
||||||
|
@ -8,5 +8,9 @@
|
||||||
"pass": "pass",
|
"pass": "pass",
|
||||||
"db": "misshaialert",
|
"db": "misshaialert",
|
||||||
"extra": {}
|
"extra": {}
|
||||||
|
},
|
||||||
|
"admin": {
|
||||||
|
"username": "your_user_name",
|
||||||
|
"host": "your-instance-host"
|
||||||
}
|
}
|
||||||
}
|
}
|
18
src/backend/controllers/admin.ts
Normal file
18
src/backend/controllers/admin.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/**
|
||||||
|
* バージョン情報など、サーバーのメタデータを返すAPI
|
||||||
|
* @author Xeltica
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Get, JsonController } from 'routing-controllers';
|
||||||
|
import { config } from '../../config';
|
||||||
|
|
||||||
|
@JsonController('/admin')
|
||||||
|
export class AdminController {
|
||||||
|
@Get() getAdmin() {
|
||||||
|
const { username, host } = config.admin;
|
||||||
|
return {
|
||||||
|
username, host,
|
||||||
|
acct: `@${username}@${host}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,21 @@ import { User } from '../models/entities/user';
|
||||||
import { Users } from '../models';
|
import { Users } from '../models';
|
||||||
import { DeepPartial } from 'typeorm';
|
import { DeepPartial } from 'typeorm';
|
||||||
import { genToken } from './gen-token';
|
import { genToken } from './gen-token';
|
||||||
|
import { IUser } from '../../common/types/user';
|
||||||
|
import { config } from '../../config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IUser インターフェイスに変換します。
|
||||||
|
*/
|
||||||
|
const packUser = (user: User | undefined): IUser | undefined => {
|
||||||
|
if (!user) return undefined;
|
||||||
|
const { username: adminName, host: adminHost } = config.admin;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
isAdmin: adminName === user.username && adminHost === user.host,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ユーザーを取得します
|
* ユーザーを取得します
|
||||||
|
@ -9,8 +24,8 @@ import { genToken } from './gen-token';
|
||||||
* @param host ホスト名
|
* @param host ホスト名
|
||||||
* @returns ユーザー
|
* @returns ユーザー
|
||||||
*/
|
*/
|
||||||
export const getUser = (username: string, host: string): Promise<User | undefined> => {
|
export const getUser = (username: string, host: string): Promise<IUser | undefined> => {
|
||||||
return Users.findOne({ username, host });
|
return Users.findOne({ username, host }).then(packUser);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +33,7 @@ export const getUser = (username: string, host: string): Promise<User | undefine
|
||||||
* @param user ユーザー
|
* @param user ユーザー
|
||||||
* @returns ミス廃トークン
|
* @returns ミス廃トークン
|
||||||
*/
|
*/
|
||||||
export const updateUsersMisshaiToken = async (user: User | User['id']): Promise<string> => {
|
export const updateUsersToolsToken = async (user: User | User['id']): Promise<string> => {
|
||||||
const u = typeof user === 'number'
|
const u = typeof user === 'number'
|
||||||
? user
|
? user
|
||||||
: user.id;
|
: user.id;
|
||||||
|
@ -33,8 +48,8 @@ export const updateUsersMisshaiToken = async (user: User | User['id']): Promise<
|
||||||
* @param token ミス廃トークン
|
* @param token ミス廃トークン
|
||||||
* @returns ユーザー
|
* @returns ユーザー
|
||||||
*/
|
*/
|
||||||
export const getUserByMisshaiToken = (token: string): Promise<User | undefined> => {
|
export const getUserByToolsToken = (token: string): Promise<User | undefined> => {
|
||||||
return Users.findOne({ misshaiToken: token });
|
return Users.findOne({ misshaiToken: token }).then(packUser);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { v4 as uuid } from 'uuid';
|
||||||
import ms from 'ms';
|
import ms from 'ms';
|
||||||
|
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import { upsertUser, getUser, updateUser, updateUsersMisshaiToken } from './functions/users';
|
import { upsertUser, getUser, updateUser, updateUsersToolsToken } from './functions/users';
|
||||||
import { api } from './services/misskey';
|
import { api } from './services/misskey';
|
||||||
import { die } from './die';
|
import { die } from './die';
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ async function login(ctx: Context, user: Record<string, unknown>, host: string,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const misshaiToken = await updateUsersMisshaiToken(u);
|
const toolsToken = await updateUsersToolsToken(u);
|
||||||
|
|
||||||
await ctx.render('frontend', { token: misshaiToken });
|
await ctx.render('frontend', { token: toolsToken });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ import constant from './const';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import { render } from './render';
|
import { render } from './render';
|
||||||
import { router } from './router';
|
import { router } from './router';
|
||||||
import { getUserByMisshaiToken } from './functions/users';
|
import { getUserByToolsToken } from './functions/users';
|
||||||
|
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
|
|
||||||
export default (): void => {
|
export default (): void => {
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
console.log('Misshaialert v' + constant.version);
|
console.log('Misskey Tools v' + constant.version);
|
||||||
|
|
||||||
console.log('Initializing DB connection...');
|
console.log('Initializing DB connection...');
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ export default (): void => {
|
||||||
if (!authorization || !authorization.startsWith('Bearer ')) return null;
|
if (!authorization || !authorization.startsWith('Bearer ')) return null;
|
||||||
|
|
||||||
const token = authorization.split(' ')[1].trim();
|
const token = authorization.split(' ')[1].trim();
|
||||||
const user = await getUserByMisshaiToken(token);
|
const user = await getUserByToolsToken(token);
|
||||||
return user;
|
return user;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -38,8 +38,6 @@ export default (): void => {
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
app.use(router.allowedMethods());
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
app.keys = ['人類', 'ミス廃化', '計画', 'ここに極まれり', 'フッフッフ...'];
|
|
||||||
|
|
||||||
console.log(`listening port ${config.port}...`);
|
console.log(`listening port ${config.port}...`);
|
||||||
console.log('App launched!');
|
console.log('App launched!');
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import _const from '../const';
|
import _const from '../const';
|
||||||
|
|
||||||
export const ua = `Mozilla/5.0 misshaialertBot/${_const.version} +https://github.com/Xeltica/misshaialert Node/${process.version}`;
|
export const ua = `Mozilla/5.0 MisskeyTools/${_const.version} +https://github.com/Xeltica/MisskeyTools Node/${process.version}`;
|
||||||
|
|
||||||
axios.defaults.headers['User-Agent'] = ua;
|
axios.defaults.headers['User-Agent'] = ua;
|
||||||
axios.defaults.validateStatus = (stat) => stat < 500;
|
axios.defaults.validateStatus = (stat) => stat < 500;
|
||||||
|
|
|
@ -18,5 +18,6 @@ export interface IUser {
|
||||||
prevRating: number;
|
prevRating: number;
|
||||||
rating: number;
|
rating: number;
|
||||||
bannedFromRanking: boolean;
|
bannedFromRanking: boolean;
|
||||||
|
isAdmin?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue