diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
| commit | 0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch) | |
| tree | 40874799472fa07416f17b50a398ac33b7771905 /src/tools | |
| parent | update deps (diff) | |
| download | sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2 sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip | |
refactoring
Resolve #7779
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/accept-migration.ts | 25 | ||||
| -rw-r--r-- | src/tools/add-emoji.ts | 30 | ||||
| -rw-r--r-- | src/tools/demote-admin.ts | 32 | ||||
| -rw-r--r-- | src/tools/mark-admin.ts | 32 | ||||
| -rw-r--r-- | src/tools/refresh-question.ts | 14 | ||||
| -rw-r--r-- | src/tools/resync-remote-user.ts | 30 | ||||
| -rw-r--r-- | src/tools/show-signin-history.ts | 56 |
7 files changed, 0 insertions, 219 deletions
diff --git a/src/tools/accept-migration.ts b/src/tools/accept-migration.ts deleted file mode 100644 index 2e54fc129f..0000000000 --- a/src/tools/accept-migration.ts +++ /dev/null @@ -1,25 +0,0 @@ -// 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); - }); -}); diff --git a/src/tools/add-emoji.ts b/src/tools/add-emoji.ts deleted file mode 100644 index 9ffe7dfa81..0000000000 --- a/src/tools/add-emoji.ts +++ /dev/null @@ -1,30 +0,0 @@ -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); -}); diff --git a/src/tools/demote-admin.ts b/src/tools/demote-admin.ts deleted file mode 100644 index d7c6d1cec2..0000000000 --- a/src/tools/demote-admin.ts +++ /dev/null @@ -1,32 +0,0 @@ -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); -}); diff --git a/src/tools/mark-admin.ts b/src/tools/mark-admin.ts deleted file mode 100644 index 62ed0f09ee..0000000000 --- a/src/tools/mark-admin.ts +++ /dev/null @@ -1,32 +0,0 @@ -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); -}); diff --git a/src/tools/refresh-question.ts b/src/tools/refresh-question.ts deleted file mode 100644 index 98a3c2865f..0000000000 --- a/src/tools/refresh-question.ts +++ /dev/null @@ -1,14 +0,0 @@ -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); -}); diff --git a/src/tools/resync-remote-user.ts b/src/tools/resync-remote-user.ts deleted file mode 100644 index bc43e250cb..0000000000 --- a/src/tools/resync-remote-user.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { initDb } from '@/db/postgre'; -import { parseAcct } from '@/misc/acct'; - -async function main(acct: string): Promise<any> { - await initDb(); - const { resolveUser } = await import('@/remote/resolve-user'); - - const { username, host } = parseAcct(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); -}); diff --git a/src/tools/show-signin-history.ts b/src/tools/show-signin-history.ts deleted file mode 100644 index ad92316314..0000000000 --- a/src/tools/show-signin-history.ts +++ /dev/null @@ -1,56 +0,0 @@ -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); -}); |