forked from mirrors/misskey
cleanup: trim trailing whitespace (#11136)
* cleanup: trim trailing whitespace * update(`.editorconfig`) --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
parent
4c879b3a33
commit
d84796588c
161 changed files with 613 additions and 607 deletions
|
@ -2,7 +2,7 @@ version: '3.8'
|
|||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@ indent_size = 2
|
|||
charset = utf-8
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_style = space
|
||||
|
|
|
@ -106,7 +106,7 @@ If your language is not listed in Crowdin, please open an issue.
|
|||
![Crowdin](https://d322cqt584bo4o.cloudfront.net/misskey/localized.svg)
|
||||
|
||||
## Development
|
||||
During development, it is useful to use the
|
||||
During development, it is useful to use the
|
||||
|
||||
```
|
||||
pnpm dev
|
||||
|
@ -150,7 +150,7 @@ Prepare DB/Redis for testing.
|
|||
```
|
||||
docker compose -f packages/backend/test/docker-compose.yml up
|
||||
```
|
||||
Alternatively, prepare an empty (data can be erased) DB and edit `.config/test.yml`.
|
||||
Alternatively, prepare an empty (data can be erased) DB and edit `.config/test.yml`.
|
||||
|
||||
Run all test.
|
||||
```
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<a href="https://misskey-hub.net">
|
||||
<img src="./assets/title_float.svg" alt="Misskey logo" style="border-radius:50%" width="400"/>
|
||||
</a>
|
||||
|
||||
|
||||
**🌎 **[Misskey](https://misskey-hub.net/)** is an open source, decentralized social media platform that's free forever! 🚀**
|
||||
|
||||
|
||||
---
|
||||
|
||||
<a href="https://misskey-hub.net/instances.html">
|
||||
|
@ -21,7 +21,7 @@
|
|||
|
||||
<a href="https://www.patreon.com/syuilo">
|
||||
<img src="https://custom-icon-badges.herokuapp.com/badge/become_a-patron-F96854?logoColor=F96854&style=for-the-badge&logo=patreon&labelColor=363B40" alt="become a patron"/></a>
|
||||
|
||||
|
||||
---
|
||||
|
||||
[![codecov](https://codecov.io/gh/misskey-dev/misskey/branch/develop/graph/badge.svg?token=R6IQZ3QJOL)](https://codecov.io/gh/misskey-dev/misskey)
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
@ -56,7 +56,7 @@ describe('After setup instance', () => {
|
|||
cy.get('[data-cy-signup-rules-notes-agree] [data-cy-switch-toggle]').click();
|
||||
cy.get('[data-cy-signup-rules-continue]').should('not.be.disabled');
|
||||
cy.get('[data-cy-signup-rules-continue]').click();
|
||||
|
||||
|
||||
cy.get('[data-cy-signup-submit]').should('be.disabled');
|
||||
cy.get('[data-cy-signup-username] input').type('alice');
|
||||
cy.get('[data-cy-signup-submit]').should('be.disabled');
|
||||
|
|
|
@ -295,7 +295,7 @@ export class AccountMoveService {
|
|||
* dstユーザーのalsoKnownAsをfetchPersonしていき、本当にmovedToUrlをdstに指定するユーザーが存在するのかを調べる
|
||||
*
|
||||
* @param dst movedToUrlを指定するユーザー
|
||||
* @param check
|
||||
* @param check
|
||||
* @param instant checkがtrueであるユーザーが最初に見つかったら即座にreturnするかどうか
|
||||
* @returns Promise<LocalUser | RemoteUser | null>
|
||||
*/
|
||||
|
|
|
@ -31,16 +31,16 @@ export class AiService {
|
|||
const cpuFlags = await this.getCpuFlags();
|
||||
isSupportedCpu = REQUIRED_CPU_FLAGS.every(required => cpuFlags.includes(required));
|
||||
}
|
||||
|
||||
|
||||
if (!isSupportedCpu) {
|
||||
console.error('This CPU cannot use TensorFlow.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const tf = await import('@tensorflow/tfjs-node');
|
||||
|
||||
|
||||
if (this.model == null) this.model = await nsfw.load(`file://${_dirname}/../../nsfw-model/`, { size: 299 });
|
||||
|
||||
|
||||
const buffer = await fs.promises.readFile(path);
|
||||
const image = await tf.node.decodeImage(buffer, 3) as any;
|
||||
try {
|
||||
|
|
|
@ -99,7 +99,7 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
'MAXLEN', '~', '200',
|
||||
'*',
|
||||
'note', note.id);
|
||||
|
||||
|
||||
this.globalEventService.publishAntennaStream(antenna.id, 'note', note);
|
||||
}
|
||||
|
||||
|
@ -112,16 +112,16 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
public async checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { id: User['id']; username: string; host: string | null; }): Promise<boolean> {
|
||||
if (note.visibility === 'specified') return false;
|
||||
if (note.visibility === 'followers') return false;
|
||||
|
||||
|
||||
if (!antenna.withReplies && note.replyId != null) return false;
|
||||
|
||||
|
||||
if (antenna.src === 'home') {
|
||||
// TODO
|
||||
} else if (antenna.src === 'list') {
|
||||
const listUsers = (await this.userListJoiningsRepository.findBy({
|
||||
userListId: antenna.userListId!,
|
||||
})).map(x => x.userId);
|
||||
|
||||
|
||||
if (!listUsers.includes(note.userId)) return false;
|
||||
} else if (antenna.src === 'users') {
|
||||
const accts = antenna.users.map(x => {
|
||||
|
@ -130,32 +130,32 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
});
|
||||
if (!accts.includes(this.utilityService.getFullApAccount(noteUser.username, noteUser.host).toLowerCase())) return false;
|
||||
}
|
||||
|
||||
|
||||
const keywords = antenna.keywords
|
||||
// Clean up
|
||||
.map(xs => xs.filter(x => x !== ''))
|
||||
.filter(xs => xs.length > 0);
|
||||
|
||||
|
||||
if (keywords.length > 0) {
|
||||
if (note.text == null && note.cw == null) return false;
|
||||
|
||||
const _text = (note.text ?? '') + '\n' + (note.cw ?? '');
|
||||
|
||||
|
||||
const matched = keywords.some(and =>
|
||||
and.every(keyword =>
|
||||
antenna.caseSensitive
|
||||
? _text.includes(keyword)
|
||||
: _text.toLowerCase().includes(keyword.toLowerCase()),
|
||||
));
|
||||
|
||||
|
||||
if (!matched) return false;
|
||||
}
|
||||
|
||||
|
||||
const excludeKeywords = antenna.excludeKeywords
|
||||
// Clean up
|
||||
.map(xs => xs.filter(x => x !== ''))
|
||||
.filter(xs => xs.length > 0);
|
||||
|
||||
|
||||
if (excludeKeywords.length > 0) {
|
||||
if (note.text == null && note.cw == null) return false;
|
||||
|
||||
|
@ -167,16 +167,16 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
? _text.includes(keyword)
|
||||
: _text.toLowerCase().includes(keyword.toLowerCase()),
|
||||
));
|
||||
|
||||
|
||||
if (matched) return false;
|
||||
}
|
||||
|
||||
|
||||
if (antenna.withFile) {
|
||||
if (note.fileIds && note.fileIds.length === 0) return false;
|
||||
}
|
||||
|
||||
|
||||
// TODO: eval expression
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
});
|
||||
this.antennasFetched = true;
|
||||
}
|
||||
|
||||
|
||||
return this.antennas;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ export class CaptchaService {
|
|||
secret,
|
||||
response,
|
||||
});
|
||||
|
||||
|
||||
const res = await this.httpRequestService.send(url, {
|
||||
method: 'POST',
|
||||
body: params.toString(),
|
||||
|
@ -28,14 +28,14 @@ export class CaptchaService {
|
|||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
}, { throwErrorWhenResponseNotOk: false });
|
||||
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`${res.status}`);
|
||||
}
|
||||
|
||||
|
||||
return await res.json() as CaptchaResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async verifyRecaptcha(secret: string, response: string | null | undefined): Promise<void> {
|
||||
if (response == null) {
|
||||
|
@ -73,7 +73,7 @@ export class CaptchaService {
|
|||
if (response == null) {
|
||||
throw new Error('turnstile-failed: no response provided');
|
||||
}
|
||||
|
||||
|
||||
const result = await this.getCaptchaResponse('https://challenges.cloudflare.com/turnstile/v0/siteverify', secret, response).catch(err => {
|
||||
throw new Error(`turnstile-request-failed: ${err}`);
|
||||
});
|
||||
|
|
|
@ -25,27 +25,27 @@ export class CreateSystemUserService {
|
|||
@bindThis
|
||||
public async createSystemUser(username: string): Promise<User> {
|
||||
const password = uuid();
|
||||
|
||||
|
||||
// Generate hash of password
|
||||
const salt = await bcrypt.genSalt(8);
|
||||
const hash = await bcrypt.hash(password, salt);
|
||||
|
||||
|
||||
// Generate secret
|
||||
const secret = generateNativeUserToken();
|
||||
|
||||
|
||||
const keyPair = await genRsaKeyPair(4096);
|
||||
|
||||
|
||||
let account!: User;
|
||||
|
||||
|
||||
// Start transaction
|
||||
await this.db.transaction(async transactionalEntityManager => {
|
||||
const exist = await transactionalEntityManager.findOneBy(User, {
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: IsNull(),
|
||||
});
|
||||
|
||||
|
||||
if (exist) throw new Error('the user is already exists');
|
||||
|
||||
|
||||
account = await transactionalEntityManager.insert(User, {
|
||||
id: this.idService.genId(),
|
||||
createdAt: new Date(),
|
||||
|
@ -58,25 +58,25 @@ export class CreateSystemUserService {
|
|||
isExplorable: false,
|
||||
isBot: true,
|
||||
}).then(x => transactionalEntityManager.findOneByOrFail(User, x.identifiers[0]));
|
||||
|
||||
|
||||
await transactionalEntityManager.insert(UserKeypair, {
|
||||
publicKey: keyPair.publicKey,
|
||||
privateKey: keyPair.privateKey,
|
||||
userId: account.id,
|
||||
});
|
||||
|
||||
|
||||
await transactionalEntityManager.insert(UserProfile, {
|
||||
userId: account.id,
|
||||
autoAcceptFollowed: false,
|
||||
password: hash,
|
||||
});
|
||||
|
||||
|
||||
await transactionalEntityManager.insert(UsedUsername, {
|
||||
createdAt: new Date(),
|
||||
username: username.toLowerCase(),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
return account;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
|||
|
||||
this.globalEventService.publishBroadcastStream('emojiAdded', {
|
||||
emoji: updated,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
|||
}
|
||||
|
||||
this.localEmojisCache.refresh();
|
||||
|
||||
|
||||
this.globalEventService.publishBroadcastStream('emojiUpdated', {
|
||||
emojis: await this.emojiEntityService.packDetailedMany(ids),
|
||||
});
|
||||
|
@ -215,7 +215,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
|||
emojis: await this.emojiEntityService.packDetailedMany(ids),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@bindThis
|
||||
public async setLicenseBulk(ids: Emoji['id'][], license: string | null) {
|
||||
await this.emojisRepository.update({
|
||||
|
|
|
@ -28,11 +28,11 @@ export class DeleteAccountService {
|
|||
|
||||
// 物理削除する前にDelete activityを送信する
|
||||
await this.userSuspendService.doPostSuspend(user).catch(e => {});
|
||||
|
||||
|
||||
this.queueService.createDeleteAccountJob(user, {
|
||||
soft: false,
|
||||
});
|
||||
|
||||
|
||||
await this.usersRepository.update(user.id, {
|
||||
isDeleted: true,
|
||||
});
|
||||
|
|
|
@ -29,12 +29,12 @@ export class EmailService {
|
|||
@bindThis
|
||||
public async sendEmail(to: string, subject: string, html: string, text: string) {
|
||||
const meta = await this.metaService.fetch(true);
|
||||
|
||||
|
||||
const iconUrl = `${this.config.url}/static-assets/mi-white.png`;
|
||||
const emailSettingUrl = `${this.config.url}/settings/email`;
|
||||
|
||||
|
||||
const enableAuth = meta.smtpUser != null && meta.smtpUser !== '';
|
||||
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: meta.smtpHost,
|
||||
port: meta.smtpPort,
|
||||
|
@ -46,7 +46,7 @@ export class EmailService {
|
|||
pass: meta.smtpPass,
|
||||
} : undefined,
|
||||
} as any);
|
||||
|
||||
|
||||
try {
|
||||
// TODO: htmlサニタイズ
|
||||
const info = await transporter.sendMail({
|
||||
|
@ -135,7 +135,7 @@ export class EmailService {
|
|||
</body>
|
||||
</html>`,
|
||||
});
|
||||
|
||||
|
||||
this.logger.info(`Message sent: ${info.messageId}`);
|
||||
} catch (err) {
|
||||
this.logger.error(err as Error);
|
||||
|
@ -149,12 +149,12 @@ export class EmailService {
|
|||
reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp';
|
||||
}> {
|
||||
const meta = await this.metaService.fetch();
|
||||
|
||||
|
||||
const exist = await this.userProfilesRepository.countBy({
|
||||
emailVerified: true,
|
||||
email: emailAddress,
|
||||
});
|
||||
|
||||
|
||||
const validated = meta.enableActiveEmailValidation ? await validateEmail({
|
||||
email: emailAddress,
|
||||
validateRegex: true,
|
||||
|
@ -163,9 +163,9 @@ export class EmailService {
|
|||
validateDisposable: true, // 捨てアドかどうかチェック
|
||||
validateSMTP: false, // 日本だと25ポートが殆どのプロバイダーで塞がれていてタイムアウトになるので
|
||||
}) : { valid: true, reason: null };
|
||||
|
||||
|
||||
const available = exist === 0 && validated.valid;
|
||||
|
||||
|
||||
return {
|
||||
available,
|
||||
reason: available ? null :
|
||||
|
|
|
@ -43,19 +43,19 @@ export class FederatedInstanceService implements OnApplicationShutdown {
|
|||
@bindThis
|
||||
public async fetch(host: string): Promise<Instance> {
|
||||
host = this.utilityService.toPuny(host);
|
||||
|
||||
|
||||
const cached = await this.federatedInstanceCache.get(host);
|
||||
if (cached) return cached;
|
||||
|
||||
|
||||
const index = await this.instancesRepository.findOneBy({ host });
|
||||
|
||||
|
||||
if (index == null) {
|
||||
const i = await this.instancesRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
host,
|
||||
firstRetrievedAt: new Date(),
|
||||
}).then(x => this.instancesRepository.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
|
||||
this.federatedInstanceCache.set(host, i);
|
||||
return i;
|
||||
} else {
|
||||
|
@ -74,7 +74,7 @@ export class FederatedInstanceService implements OnApplicationShutdown {
|
|||
.then((response) => {
|
||||
return response.raw[0];
|
||||
});
|
||||
|
||||
|
||||
this.federatedInstanceCache.set(result.host, result);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ export class FetchInstanceMetadataService {
|
|||
|
||||
@bindThis
|
||||
public async fetchInstanceMetadata(instance: Instance, force = false): Promise<void> {
|
||||
try {
|
||||
|
||||
const host = instance.host;
|
||||
// Acquire mutex to ensure no parallel runs
|
||||
if (!await this.tryLock(host)) return;
|
||||
|
@ -72,13 +74,13 @@ export class FetchInstanceMetadataService {
|
|||
}
|
||||
|
||||
this.logger.info(`Fetching metadata of ${instance.host} ...`);
|
||||
|
||||
|
||||
const [info, dom, manifest] = await Promise.all([
|
||||
this.fetchNodeinfo(instance).catch(() => null),
|
||||
this.fetchDom(instance).catch(() => null),
|
||||
this.fetchManifest(instance).catch(() => null),
|
||||
]);
|
||||
|
||||
|
||||
const [favicon, icon, themeColor, name, description] = await Promise.all([
|
||||
this.fetchFaviconUrl(instance, dom).catch(() => null),
|
||||
this.fetchIconUrl(instance, dom, manifest).catch(() => null),
|
||||
|
@ -86,13 +88,13 @@ export class FetchInstanceMetadataService {
|
|||
this.getSiteName(info, dom, manifest).catch(() => null),
|
||||
this.getDescription(info, dom, manifest).catch(() => null),
|
||||
]);
|
||||
|
||||
|
||||
this.logger.succ(`Successfuly fetched metadata of ${instance.host}`);
|
||||
|
||||
|
||||
const updates = {
|
||||
infoUpdatedAt: new Date(),
|
||||
} as Record<string, any>;
|
||||
|
||||
|
||||
if (info) {
|
||||
updates.softwareName = typeof info.software?.name === 'string' ? info.software.name.toLowerCase() : '?';
|
||||
updates.softwareVersion = info.software?.version;
|
||||
|
@ -100,15 +102,15 @@ export class FetchInstanceMetadataService {
|
|||
updates.maintainerName = info.metadata ? info.metadata.maintainer ? (info.metadata.maintainer.name ?? null) : null : null;
|
||||
updates.maintainerEmail = info.metadata ? info.metadata.maintainer ? (info.metadata.maintainer.email ?? null) : null : null;
|
||||
}
|
||||
|
||||
|
||||
if (name) updates.name = name;
|
||||
if (description) updates.description = description;
|
||||
if (icon || favicon) updates.iconUrl = icon ?? favicon;
|
||||
if (favicon) updates.faviconUrl = favicon;
|
||||
if (themeColor) updates.themeColor = themeColor;
|
||||
|
||||
|
||||
await this.federatedInstanceService.update(instance.id, updates);
|
||||
|
||||
|
||||
this.logger.succ(`Successfuly updated metadata of ${instance.host}`);
|
||||
} catch (e) {
|
||||
this.logger.error(`Failed to update metadata of ${instance.host}: ${e}`);
|
||||
|
@ -120,7 +122,7 @@ export class FetchInstanceMetadataService {
|
|||
@bindThis
|
||||
private async fetchNodeinfo(instance: Instance): Promise<NodeInfo> {
|
||||
this.logger.info(`Fetching nodeinfo of ${instance.host} ...`);
|
||||
|
||||
|
||||
try {
|
||||
const wellknown = await this.httpRequestService.getJson('https://' + instance.host + '/.well-known/nodeinfo')
|
||||
.catch(err => {
|
||||
|
@ -130,33 +132,33 @@ export class FetchInstanceMetadataService {
|
|||
throw err.statusCode ?? err.message;
|
||||
}
|
||||
}) as Record<string, unknown>;
|
||||
|
||||
|
||||
if (wellknown.links == null || !Array.isArray(wellknown.links)) {
|
||||
throw new Error('No wellknown links');
|
||||
}
|
||||
|
||||
|
||||
const links = wellknown.links as any[];
|
||||
|
||||
|
||||
const lnik1_0 = links.find(link => link.rel === 'http://nodeinfo.diaspora.software/ns/schema/1.0');
|
||||
const lnik2_0 = links.find(link => link.rel === 'http://nodeinfo.diaspora.software/ns/schema/2.0');
|
||||
const lnik2_1 = links.find(link => link.rel === 'http://nodeinfo.diaspora.software/ns/schema/2.1');
|
||||
const link = lnik2_1 ?? lnik2_0 ?? lnik1_0;
|
||||
|
||||
|
||||
if (link == null) {
|
||||
throw new Error('No nodeinfo link provided');
|
||||
}
|
||||
|
||||
|
||||
const info = await this.httpRequestService.getJson(link.href)
|
||||
.catch(err => {
|
||||
throw err.statusCode ?? err.message;
|
||||
});
|
||||
|
||||
|
||||
this.logger.succ(`Successfuly fetched nodeinfo of ${instance.host}`);
|
||||
|
||||
|
||||
return info as NodeInfo;
|
||||
} catch (err) {
|
||||
this.logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${err}`);
|
||||
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
@ -164,51 +166,51 @@ export class FetchInstanceMetadataService {
|
|||
@bindThis
|
||||
private async fetchDom(instance: Instance): Promise<DOMWindow['document']> {
|
||||
this.logger.info(`Fetching HTML of ${instance.host} ...`);
|
||||
|
||||
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
||||
const html = await this.httpRequestService.getHtml(url);
|
||||
|
||||
|
||||
const { window } = new JSDOM(html);
|
||||
const doc = window.document;
|
||||
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchManifest(instance: Instance): Promise<Record<string, unknown> | null> {
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
||||
const manifestUrl = url + '/manifest.json';
|
||||
|
||||
|
||||
const manifest = await this.httpRequestService.getJson(manifestUrl) as Record<string, unknown>;
|
||||
|
||||
|
||||
return manifest;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchFaviconUrl(instance: Instance, doc: DOMWindow['document'] | null): Promise<string | null> {
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
||||
if (doc) {
|
||||
// https://github.com/misskey-dev/misskey/pull/8220#issuecomment-1025104043
|
||||
const href = Array.from(doc.getElementsByTagName('link')).reverse().find(link => link.relList.contains('icon'))?.href;
|
||||
|
||||
|
||||
if (href) {
|
||||
return (new URL(href, url)).href;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const faviconUrl = url + '/favicon.ico';
|
||||
|
||||
|
||||
const favicon = await this.httpRequestService.send(faviconUrl, {
|
||||
method: 'HEAD',
|
||||
}, { throwErrorWhenResponseNotOk: false });
|
||||
|
||||
|
||||
if (favicon.ok) {
|
||||
return faviconUrl;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -218,38 +220,38 @@ export class FetchInstanceMetadataService {
|
|||
const url = 'https://' + instance.host;
|
||||
return (new URL(manifest.icons[0].src, url)).href;
|
||||
}
|
||||
|
||||
|
||||
if (doc) {
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
||||
// https://github.com/misskey-dev/misskey/pull/8220#issuecomment-1025104043
|
||||
const links = Array.from(doc.getElementsByTagName('link')).reverse();
|
||||
// https://github.com/misskey-dev/misskey/pull/8220/files/0ec4eba22a914e31b86874f12448f88b3e58dd5a#r796487559
|
||||
const href =
|
||||
const href =
|
||||
[
|
||||
links.find(link => link.relList.contains('apple-touch-icon-precomposed'))?.href,
|
||||
links.find(link => link.relList.contains('apple-touch-icon'))?.href,
|
||||
links.find(link => link.relList.contains('icon'))?.href,
|
||||
]
|
||||
.find(href => href);
|
||||
|
||||
|
||||
if (href) {
|
||||
return (new URL(href, url)).href;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getThemeColor(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
||||
const themeColor = info?.metadata?.themeColor ?? doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') ?? manifest?.theme_color;
|
||||
|
||||
|
||||
if (themeColor) {
|
||||
const color = new tinycolor(themeColor);
|
||||
if (color.isValid()) return color.toHexString();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -262,19 +264,19 @@ export class FetchInstanceMetadataService {
|
|||
return info.metadata.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (doc) {
|
||||
const og = doc.querySelector('meta[property="og:title"]')?.getAttribute('content');
|
||||
|
||||
|
||||
if (og) {
|
||||
return og;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (manifest) {
|
||||
return manifest.name ?? manifest.short_name;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -287,23 +289,23 @@ export class FetchInstanceMetadataService {
|
|||
return info.metadata.description;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (doc) {
|
||||
const meta = doc.querySelector('meta[name="description"]')?.getAttribute('content');
|
||||
if (meta) {
|
||||
return meta;
|
||||
}
|
||||
|
||||
|
||||
const og = doc.querySelector('meta[property="og:description"]')?.getAttribute('content');
|
||||
if (og) {
|
||||
return og;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (manifest) {
|
||||
return manifest.name ?? manifest.short_name;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,20 +161,20 @@ export class FileInfoService {
|
|||
private async detectSensitivity(source: string, mime: string, sensitiveThreshold: number, sensitiveThresholdForPorn: number, analyzeVideo: boolean): Promise<[sensitive: boolean, porn: boolean]> {
|
||||
let sensitive = false;
|
||||
let porn = false;
|
||||
|
||||
|
||||
function judgePrediction(result: readonly predictionType[]): [sensitive: boolean, porn: boolean] {
|
||||
let sensitive = false;
|
||||
let porn = false;
|
||||
|
||||
|
||||
if ((result.find(x => x.className === 'Sexy')?.probability ?? 0) > sensitiveThreshold) sensitive = true;
|
||||
if ((result.find(x => x.className === 'Hentai')?.probability ?? 0) > sensitiveThreshold) sensitive = true;
|
||||
if ((result.find(x => x.className === 'Porn')?.probability ?? 0) > sensitiveThreshold) sensitive = true;
|
||||
|
||||
|
||||
if ((result.find(x => x.className === 'Porn')?.probability ?? 0) > sensitiveThresholdForPorn) porn = true;
|
||||
|
||||
|
||||
return [sensitive, porn];
|
||||
}
|
||||
|
||||
|
||||
if ([
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
|
@ -253,10 +253,10 @@ export class FileInfoService {
|
|||
disposeOutDir();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return [sensitive, porn];
|
||||
}
|
||||
|
||||
|
||||
private async *asyncIterateFrames(cwd: string, command: FFmpeg.FfmpegCommand): AsyncGenerator<string, void> {
|
||||
const watcher = new FSWatcher({
|
||||
cwd,
|
||||
|
@ -295,7 +295,7 @@ export class FileInfoService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@bindThis
|
||||
private exists(path: string): Promise<boolean> {
|
||||
return fs.promises.access(path).then(() => true, () => false);
|
||||
|
|
|
@ -42,21 +42,21 @@ export class HttpRequestService {
|
|||
errorTtl: 30, // 30secs
|
||||
lookup: false, // nativeのdns.lookupにfallbackしない
|
||||
});
|
||||
|
||||
|
||||
this.http = new http.Agent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 30 * 1000,
|
||||
lookup: cache.lookup,
|
||||
} as http.AgentOptions);
|
||||
|
||||
|
||||
this.https = new https.Agent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 30 * 1000,
|
||||
lookup: cache.lookup,
|
||||
} as https.AgentOptions);
|
||||
|
||||
|
||||
const maxSockets = Math.max(256, config.deliverJobConcurrency ?? 128);
|
||||
|
||||
|
||||
this.httpAgent = config.proxy
|
||||
? new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
|
|
|
@ -23,7 +23,7 @@ export class IdService {
|
|||
@bindThis
|
||||
public genId(date?: Date): string {
|
||||
if (!date || (date > new Date())) date = new Date();
|
||||
|
||||
|
||||
switch (this.method) {
|
||||
case 'aid': return genAid(date);
|
||||
case 'meid': return genMeid(date);
|
||||
|
|
|
@ -26,12 +26,12 @@ export class InstanceActorService {
|
|||
public async getInstanceActor(): Promise<LocalUser> {
|
||||
const cached = this.cache.get();
|
||||
if (cached) return cached;
|
||||
|
||||
|
||||
const user = await this.usersRepository.findOneBy({
|
||||
host: IsNull(),
|
||||
username: ACTOR_USERNAME,
|
||||
}) as LocalUser | undefined;
|
||||
|
||||
|
||||
if (user) {
|
||||
this.cache.set(user);
|
||||
return user;
|
||||
|
|
|
@ -56,7 +56,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
@bindThis
|
||||
public async fetch(noCache = false): Promise<Meta> {
|
||||
if (!noCache && this.cache) return this.cache;
|
||||
|
||||
|
||||
return await this.db.transaction(async transactionalEntityManager => {
|
||||
// 過去のバグでレコードが複数出来てしまっている可能性があるので新しいIDを優先する
|
||||
const metas = await transactionalEntityManager.find(Meta, {
|
||||
|
@ -64,9 +64,9 @@ export class MetaService implements OnApplicationShutdown {
|
|||
id: 'DESC',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const meta = metas[0];
|
||||
|
||||
|
||||
if (meta) {
|
||||
this.cache = meta;
|
||||
return meta;
|
||||
|
@ -81,7 +81,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
['id'],
|
||||
)
|
||||
.then((x) => transactionalEntityManager.findOneByOrFail(Meta, x.identifiers[0]));
|
||||
|
||||
|
||||
this.cache = saved;
|
||||
return saved;
|
||||
}
|
||||
|
|
|
@ -27,29 +27,29 @@ export class MfmService {
|
|||
public fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
// some AP servers like Pixelfed use br tags as well as newlines
|
||||
html = html.replace(/<br\s?\/?>\r?\n/gi, '\n');
|
||||
|
||||
|
||||
const dom = parse5.parseFragment(html);
|
||||
|
||||
|
||||
let text = '';
|
||||
|
||||
|
||||
for (const n of dom.childNodes) {
|
||||
analyze(n);
|
||||
}
|
||||
|
||||
|
||||
return text.trim();
|
||||
|
||||
|
||||
function getText(node: TreeAdapter.Node): string {
|
||||
if (treeAdapter.isTextNode(node)) return node.value;
|
||||
if (!treeAdapter.isElementNode(node)) return '';
|
||||
if (node.nodeName === 'br') return '\n';
|
||||
|
||||
|
||||
if (node.childNodes) {
|
||||
return node.childNodes.map(n => getText(n)).join('');
|
||||
}
|
||||
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function appendChildren(childNodes: TreeAdapter.ChildNode[]): void {
|
||||
if (childNodes) {
|
||||
for (const n of childNodes) {
|
||||
|
@ -57,35 +57,35 @@ export class MfmService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function analyze(node: TreeAdapter.Node) {
|
||||
if (treeAdapter.isTextNode(node)) {
|
||||
text += node.value;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Skip comment or document type node
|
||||
if (!treeAdapter.isElementNode(node)) return;
|
||||
|
||||
|
||||
switch (node.nodeName) {
|
||||
case 'br': {
|
||||
text += '\n';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'a':
|
||||
{
|
||||
const txt = getText(node);
|
||||
const rel = node.attrs.find(x => x.name === 'rel');
|
||||
const href = node.attrs.find(x => x.name === 'href');
|
||||
|
||||
|
||||
// ハッシュタグ
|
||||
if (hashtagNames && href && hashtagNames.map(x => x.toLowerCase()).includes(txt.toLowerCase())) {
|
||||
text += txt;
|
||||
// メンション
|
||||
} else if (txt.startsWith('@') && !(rel && rel.value.startsWith('me '))) {
|
||||
const part = txt.split('@');
|
||||
|
||||
|
||||
if (part.length === 2 && href) {
|
||||
//#region ホスト名部分が省略されているので復元する
|
||||
const acct = `${txt}@${(new URL(href.value)).hostname}`;
|
||||
|
@ -116,12 +116,12 @@ export class MfmService {
|
|||
return `[${txt}](${href.value})`;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
text += generateLink();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'h1':
|
||||
{
|
||||
text += '【';
|
||||
|
@ -129,7 +129,7 @@ export class MfmService {
|
|||
text += '】\n';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'b':
|
||||
case 'strong':
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ export class MfmService {
|
|||
text += '**';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'small':
|
||||
{
|
||||
text += '<small>';
|
||||
|
@ -146,7 +146,7 @@ export class MfmService {
|
|||
text += '</small>';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 's':
|
||||
case 'del':
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ export class MfmService {
|
|||
text += '~~';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'i':
|
||||
case 'em':
|
||||
{
|
||||
|
@ -164,7 +164,7 @@ export class MfmService {
|
|||
text += '</i>';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// block code (<pre><code>)
|
||||
case 'pre': {
|
||||
if (node.childNodes.length === 1 && node.childNodes[0].nodeName === 'code') {
|
||||
|
@ -176,7 +176,7 @@ export class MfmService {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// inline code (<code>)
|
||||
case 'code': {
|
||||
text += '`';
|
||||
|
@ -184,7 +184,7 @@ export class MfmService {
|
|||
text += '`';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'blockquote': {
|
||||
const t = getText(node);
|
||||
if (t) {
|
||||
|
@ -193,7 +193,7 @@ export class MfmService {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'p':
|
||||
case 'h2':
|
||||
case 'h3':
|
||||
|
@ -205,7 +205,7 @@ export class MfmService {
|
|||
appendChildren(node.childNodes);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// other block elements
|
||||
case 'div':
|
||||
case 'header':
|
||||
|
@ -219,7 +219,7 @@ export class MfmService {
|
|||
appendChildren(node.childNodes);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default: // includes inline elements
|
||||
{
|
||||
appendChildren(node.childNodes);
|
||||
|
@ -234,48 +234,48 @@ export class MfmService {
|
|||
if (nodes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const { window } = new Window();
|
||||
|
||||
|
||||
const doc = window.document;
|
||||
|
||||
|
||||
function appendChildren(children: mfm.MfmNode[], targetElement: any): void {
|
||||
if (children) {
|
||||
for (const child of children.map(x => (handlers as any)[x.type](x))) targetElement.appendChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const handlers: { [K in mfm.MfmNode['type']]: (node: mfm.NodeType<K>) => any } = {
|
||||
bold: (node) => {
|
||||
const el = doc.createElement('b');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
small: (node) => {
|
||||
const el = doc.createElement('small');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
strike: (node) => {
|
||||
const el = doc.createElement('del');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
italic: (node) => {
|
||||
const el = doc.createElement('i');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
fn: (node) => {
|
||||
const el = doc.createElement('i');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
blockCode: (node) => {
|
||||
const pre = doc.createElement('pre');
|
||||
const inner = doc.createElement('code');
|
||||
|
@ -283,21 +283,21 @@ export class MfmService {
|
|||
pre.appendChild(inner);
|
||||
return pre;
|
||||
},
|
||||
|
||||
|
||||
center: (node) => {
|
||||
const el = doc.createElement('div');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
emojiCode: (node) => {
|
||||
return doc.createTextNode(`\u200B:${node.props.name}:\u200B`);
|
||||
},
|
||||
|
||||
|
||||
unicodeEmoji: (node) => {
|
||||
return doc.createTextNode(node.props.emoji);
|
||||
},
|
||||
|
||||
|
||||
hashtag: (node) => {
|
||||
const a = doc.createElement('a');
|
||||
a.setAttribute('href', `${this.config.url}/tags/${node.props.hashtag}`);
|
||||
|
@ -305,32 +305,32 @@ export class MfmService {
|
|||
a.setAttribute('rel', 'tag');
|
||||
return a;
|
||||
},
|
||||
|
||||
|
||||
inlineCode: (node) => {
|
||||
const el = doc.createElement('code');
|
||||
el.textContent = node.props.code;
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
mathInline: (node) => {
|
||||
const el = doc.createElement('code');
|
||||
el.textContent = node.props.formula;
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
mathBlock: (node) => {
|
||||
const el = doc.createElement('code');
|
||||
el.textContent = node.props.formula;
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
link: (node) => {
|
||||
const a = doc.createElement('a');
|
||||
a.setAttribute('href', node.props.url);
|
||||
appendChildren(node.children, a);
|
||||
return a;
|
||||
},
|
||||
|
||||
|
||||
mention: (node) => {
|
||||
const a = doc.createElement('a');
|
||||
const { username, host, acct } = node.props;
|
||||
|
@ -340,47 +340,47 @@ export class MfmService {
|
|||
a.textContent = acct;
|
||||
return a;
|
||||
},
|
||||
|
||||
|
||||
quote: (node) => {
|
||||
const el = doc.createElement('blockquote');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
text: (node) => {
|
||||
const el = doc.createElement('span');
|
||||
const nodes = node.props.text.split(/\r\n|\r|\n/).map(x => doc.createTextNode(x));
|
||||
|
||||
|
||||
for (const x of intersperse<FIXME | 'br'>('br', nodes)) {
|
||||
el.appendChild(x === 'br' ? doc.createElement('br') : x);
|
||||
}
|
||||
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
|
||||
url: (node) => {
|
||||
const a = doc.createElement('a');
|
||||
a.setAttribute('href', node.props.url);
|
||||
a.textContent = node.props.url;
|
||||
return a;
|
||||
},
|
||||
|
||||
|
||||
search: (node) => {
|
||||
const a = doc.createElement('a');
|
||||
a.setAttribute('href', `https://www.google.com/search?q=${node.props.query}`);
|
||||
a.textContent = node.props.content;
|
||||
return a;
|
||||
},
|
||||
|
||||
|
||||
plain: (node) => {
|
||||
const el = doc.createElement('span');
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
appendChildren(nodes, doc.body);
|
||||
|
||||
|
||||
return `<p>${doc.body.innerHTML}</p>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -672,7 +672,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
|||
// Register to search database
|
||||
this.index(note);
|
||||
}
|
||||
|
||||
|
||||
@bindThis
|
||||
private isSensitive(note: Option, sensitiveWord: string[]): boolean {
|
||||