move tools dir into src
This commit is contained in:
25
packages/backend/src/tools/accept-migration.ts
Normal file
25
packages/backend/src/tools/accept-migration.ts
Normal file
@ -0,0 +1,25 @@
|
||||
// ex) node built/tools/accept-migration Yo 1000000000001
|
||||
|
||||
import { createConnection } from 'typeorm';
|
||||
import config from '@/config/index';
|
||||
|
||||
createConnection({
|
||||
type: 'postgres',
|
||||
host: config.db.host,
|
||||
port: config.db.port,
|
||||
username: config.db.user,
|
||||
password: config.db.pass,
|
||||
database: config.db.db,
|
||||
extra: config.db.extra,
|
||||
synchronize: false,
|
||||
dropSchema: false,
|
||||
}).then(c => {
|
||||
c.query(`INSERT INTO migrations(timestamp,name) VALUES (${process.argv[3]}, '${process.argv[2]}${process.argv[3]}');`).then(() => {
|
||||
console.log('done');
|
||||
process.exit(0);
|
||||
}).catch(e => {
|
||||
console.log('ERROR:');
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
30
packages/backend/src/tools/add-emoji.ts
Normal file
30
packages/backend/src/tools/add-emoji.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Emojis } from '@/models/index';
|
||||
import { genId } from '@/misc/gen-id';
|
||||
|
||||
async function main(name: string, url: string, alias?: string): Promise<any> {
|
||||
const aliases = alias != null ? [ alias ] : [];
|
||||
|
||||
await Emojis.save({
|
||||
id: genId(),
|
||||
host: null,
|
||||
name,
|
||||
url,
|
||||
aliases,
|
||||
updatedAt: new Date()
|
||||
});
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const name = args[0];
|
||||
const url = args[1];
|
||||
|
||||
if (!name) throw new Error('require name');
|
||||
if (!url) throw new Error('require url');
|
||||
|
||||
main(name, url).then(() => {
|
||||
console.log('success');
|
||||
process.exit(0);
|
||||
}).catch(e => {
|
||||
console.warn(e);
|
||||
process.exit(1);
|
||||
});
|
32
packages/backend/src/tools/demote-admin.ts
Normal file
32
packages/backend/src/tools/demote-admin.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { initDb } from '../db/postgre';
|
||||
import { getRepository } from 'typeorm';
|
||||
import { User } from '@/models/entities/user';
|
||||
|
||||
async function main(username: string) {
|
||||
if (!username) throw `username required`;
|
||||
username = username.replace(/^@/, '');
|
||||
|
||||
await initDb();
|
||||
const Users = getRepository(User);
|
||||
|
||||
const res = await Users.update({
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: null
|
||||
}, {
|
||||
isAdmin: false
|
||||
});
|
||||
|
||||
if (res.affected !== 1) {
|
||||
throw 'Failed';
|
||||
}
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
main(args[0]).then(() => {
|
||||
console.log('Success');
|
||||
process.exit(0);
|
||||
}).catch(e => {
|
||||
console.error(`Error: ${e.message || e}`);
|
||||
process.exit(1);
|
||||
});
|
32
packages/backend/src/tools/mark-admin.ts
Normal file
32
packages/backend/src/tools/mark-admin.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { initDb } from '../db/postgre';
|
||||
import { getRepository } from 'typeorm';
|
||||
import { User } from '@/models/entities/user';
|
||||
|
||||
async function main(username: string) {
|
||||
if (!username) throw `username required`;
|
||||
username = username.replace(/^@/, '');
|
||||
|
||||
await initDb();
|
||||
const Users = getRepository(User);
|
||||
|
||||
const res = await Users.update({
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: null
|
||||
}, {
|
||||
isAdmin: true
|
||||
});
|
||||
|
||||
if (res.affected !== 1) {
|
||||
throw 'Failed';
|
||||
}
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
main(args[0]).then(() => {
|
||||
console.log('Success');
|
||||
process.exit(0);
|
||||
}).catch(e => {
|
||||
console.error(`Error: ${e.message || e}`);
|
||||
process.exit(1);
|
||||
});
|
14
packages/backend/src/tools/refresh-question.ts
Normal file
14
packages/backend/src/tools/refresh-question.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { updateQuestion } from '@/remote/activitypub/models/question';
|
||||
|
||||
async function main(uri: string): Promise<any> {
|
||||
return await updateQuestion(uri);
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const uri = args[0];
|
||||
|
||||
main(uri).then(result => {
|
||||
console.log(`Done: ${result}`);
|
||||
}).catch(e => {
|
||||
console.warn(e);
|
||||
});
|
30
packages/backend/src/tools/resync-remote-user.ts
Normal file
30
packages/backend/src/tools/resync-remote-user.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { initDb } from '@/db/postgre';
|
||||
import * as Acct from 'misskey-js/built/acct';
|
||||
|
||||
async function main(acct: string): Promise<any> {
|
||||
await initDb();
|
||||
const { resolveUser } = await import('@/remote/resolve-user');
|
||||
|
||||
const { username, host } = Acct.parse(acct);
|
||||
await resolveUser(username, host, {}, true);
|
||||
}
|
||||
|
||||
// get args
|
||||
const args = process.argv.slice(2);
|
||||
let acct = args[0];
|
||||
|
||||
// normalize args
|
||||
acct = acct.replace(/^@/, '');
|
||||
|
||||
// check args
|
||||
if (!acct.match(/^\w+@\w/)) {
|
||||
throw `Invalid acct format. Valid format are user@host`;
|
||||
}
|
||||
|
||||
console.log(`resync ${acct}`);
|
||||
|
||||
main(acct).then(() => {
|
||||
console.log('Done');
|
||||
}).catch(e => {
|
||||
console.warn(e);
|
||||
});
|
56
packages/backend/src/tools/show-signin-history.ts
Normal file
56
packages/backend/src/tools/show-signin-history.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { Users, Signins } from '@/models/index';
|
||||
|
||||
// node built/tools/show-signin-history username
|
||||
// => {Success} {Date} {IPAddrsss}
|
||||
|
||||
// node built/tools/show-signin-history username user-agent,x-forwarded-for
|
||||
// with user-agent and x-forwarded-for
|
||||
|
||||
// node built/tools/show-signin-history username all
|
||||
// with full request headers
|
||||
|
||||
async function main(username: string, headers?: string[]) {
|
||||
const user = await Users.findOne({
|
||||
host: null,
|
||||
usernameLower: username.toLowerCase(),
|
||||
});
|
||||
|
||||
if (user == null) throw new Error('User not found');
|
||||
|
||||
const history = await Signins.find({
|
||||
userId: user.id
|
||||
});
|
||||
|
||||
for (const signin of history) {
|
||||
console.log(`${signin.success ? 'OK' : 'NG'} ${signin.createdAt ? signin.createdAt.toISOString() : 'Unknown'} ${signin.ip}`);
|
||||
|
||||
// headers
|
||||
if (headers != null) {
|
||||
for (const key of Object.keys(signin.headers)) {
|
||||
if (headers.includes('all') || headers.includes(key)) {
|
||||
console.log(` ${key}: ${signin.headers[key]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get args
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
let username = args[0];
|
||||
let headers: string[] | undefined;
|
||||
|
||||
if (args[1] != null) {
|
||||
headers = args[1].split(/,/).map(header => header.toLowerCase());
|
||||
}
|
||||
|
||||
// normalize args
|
||||
username = username.replace(/^@/, '');
|
||||
|
||||
main(username, headers).then(() => {
|
||||
process.exit(0);
|
||||
}).catch(e => {
|
||||
console.warn(e);
|
||||
process.exit(1);
|
||||
});
|
Reference in New Issue
Block a user