2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
2022-02-10 10:47:46 +00:00
|
|
|
|
2023-07-27 05:31:52 +00:00
|
|
|
import RE2 from 're2';
|
2022-02-28 15:07:03 +00:00
|
|
|
|
|
|
|
export class convertHardMutes1644010796173 {
|
2022-02-10 10:47:46 +00:00
|
|
|
name = 'convertHardMutes1644010796173'
|
|
|
|
|
|
|
|
async up(queryRunner) {
|
2022-02-11 12:17:07 +00:00
|
|
|
let entries = await queryRunner.query(`SELECT "userId", "mutedWords" FROM "user_profile" WHERE "userHost" IS NULL`);
|
2022-02-10 10:47:46 +00:00
|
|
|
for(let i = 0; i < entries.length; i++) {
|
|
|
|
let words = entries[i].mutedWords
|
|
|
|
.map(line => {
|
2022-02-11 12:06:38 +00:00
|
|
|
if (typeof line === 'string') return [];
|
2022-02-10 10:47:46 +00:00
|
|
|
const regexp = line.join(" ").match(/^\/(.+)\/(.*)$/);
|
|
|
|
if (regexp) {
|
|
|
|
// convert regexp's
|
|
|
|
try {
|
|
|
|
new RE2(regexp[1], regexp[2]);
|
|
|
|
return `/${regexp[1]}/${regexp[2]}`;
|
|
|
|
} catch (err) {
|
|
|
|
// invalid regex, ignore it
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// remove empty segments
|
|
|
|
return line.filter(x => x !== '');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// remove empty lines
|
|
|
|
.filter(x => !(Array.isArray(x) && x.length === 0));
|
|
|
|
|
|
|
|
await queryRunner.connection.createQueryBuilder()
|
|
|
|
.update('user_profile')
|
|
|
|
.set({
|
|
|
|
mutedWords: words
|
|
|
|
})
|
|
|
|
.where('userId = :id', { id: entries[i].userId })
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async down(queryRunner) {
|
|
|
|
let entries = await queryRunner.query(`SELECT "userId", "mutedWords" FROM "user_profile"`);
|
|
|
|
for(let i = 0; i < entries.length; i++) {
|
|
|
|
let words = entries[i].mutedWords
|
|
|
|
.map(line => {
|
|
|
|
if (Array.isArray(line)) {
|
|
|
|
return line;
|
|
|
|
} else {
|
|
|
|
// do not split regex at spaces again
|
|
|
|
return [line];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// remove empty lines
|
|
|
|
.filter(x => !(Array.isArray(x) && x.length === 0));
|
|
|
|
|
|
|
|
await queryRunner.connection.createQueryBuilder()
|
|
|
|
.update('user_profile')
|
|
|
|
.set({
|
|
|
|
mutedWords: words
|
|
|
|
})
|
|
|
|
.where('userId = :id', { id: entries[i].userId })
|
|
|
|
.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|