refactor: Use ESM (#8358)
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
This commit is contained in:
14
packages/backend/src/misc/acct.ts
Normal file
14
packages/backend/src/misc/acct.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export type Acct = {
|
||||
username: string;
|
||||
host: string | null;
|
||||
};
|
||||
|
||||
export function parse(acct: string): Acct {
|
||||
if (acct.startsWith('@')) acct = acct.substr(1);
|
||||
const split = acct.split('@', 2);
|
||||
return { username: split[0], host: split[1] || null };
|
||||
}
|
||||
|
||||
export function toString(acct: Acct): string {
|
||||
return acct.host == null ? acct.username : `${acct.username}@${acct.host}`;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { Antennas } from '@/models/index';
|
||||
import { Antenna } from '@/models/entities/antenna';
|
||||
import { subsdcriber } from '../db/redis';
|
||||
import { Antennas } from '@/models/index.js';
|
||||
import { Antenna } from '@/models/entities/antenna.js';
|
||||
import { subsdcriber } from '../db/redis.js';
|
||||
|
||||
let antennasFetched = false;
|
||||
let antennas: Antenna[] = [];
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { redisClient } from '../db/redis';
|
||||
import { promisify } from 'util';
|
||||
import * as redisLock from 'redis-lock';
|
||||
import { redisClient } from '../db/redis.js';
|
||||
import { promisify } from 'node:util';
|
||||
import redisLock from 'redis-lock';
|
||||
|
||||
/**
|
||||
* Retry delay (ms) for lock acquisition
|
||||
|
@ -1,7 +1,7 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { URLSearchParams } from 'url';
|
||||
import { getAgentByUrl } from './fetch';
|
||||
import config from '@/config/index';
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import { getAgentByUrl } from './fetch.js';
|
||||
import config from '@/config/index.js';
|
||||
|
||||
export async function verifyRecaptcha(secret: string, response: string) {
|
||||
const result = await getCaptchaResponse('https://www.recaptcha.net/recaptcha/api/siteverify', secret, response).catch(e => {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Antenna } from '@/models/entities/antenna';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { UserListJoinings, UserGroupJoinings } from '@/models/index';
|
||||
import { getFullApAccount } from './convert-host';
|
||||
import * as Acct from 'misskey-js/built/acct';
|
||||
import { Packed } from './schema';
|
||||
import { Antenna } from '@/models/entities/antenna.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { UserListJoinings, UserGroupJoinings } from '@/models/index.js';
|
||||
import { getFullApAccount } from './convert-host.js';
|
||||
import * as Acct from '@/misc/acct.js';
|
||||
import { Packed } from './schema.js';
|
||||
|
||||
/**
|
||||
* noteUserFollowers / antennaUserFollowing はどちらか一方が指定されていればよい
|
||||
|
@ -1,6 +1,6 @@
|
||||
const RE2 = require('re2');
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { User } from '@/models/entities/user';
|
||||
import RE2 from 're2';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
|
||||
type NoteLike = {
|
||||
userId: Note['userId'];
|
||||
|
@ -1,4 +1,4 @@
|
||||
const cd = require('content-disposition');
|
||||
import cd from 'content-disposition';
|
||||
|
||||
export function contentDisposition(type: 'inline' | 'attachment', filename: string): string {
|
||||
const fallback = filename.replace(/[^\w.-]/g, '_');
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { URL } from 'url';
|
||||
import config from '@/config/index';
|
||||
import { toASCII } from 'punycode/';
|
||||
import { URL } from 'node:url';
|
||||
import config from '@/config/index.js';
|
||||
import { toASCII } from 'punycode';
|
||||
|
||||
export function getFullApAccount(username: string, host: string | null) {
|
||||
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Notes } from '@/models/index';
|
||||
import { Notes } from '@/models/index.js';
|
||||
|
||||
export async function countSameRenotes(userId: string, renoteId: string, excludeNoteId: string | undefined): Promise<number> {
|
||||
// 指定したユーザーの指定したノートのリノートがいくつあるか数える
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createTemp } from './create-temp';
|
||||
import { downloadUrl } from './download-url';
|
||||
import { detectType } from './get-file-info';
|
||||
import { createTemp } from './create-temp.js';
|
||||
import { downloadUrl } from './download-url.js';
|
||||
import { detectType } from './get-file-info.js';
|
||||
|
||||
export async function detectUrlMime(url: string) {
|
||||
const [path, cleanup] = await createTemp();
|
||||
|
@ -1,8 +1,8 @@
|
||||
import * as fs from 'fs';
|
||||
import * as util from 'util';
|
||||
import Logger from '@/services/logger';
|
||||
import { createTemp } from './create-temp';
|
||||
import { downloadUrl } from './download-url';
|
||||
import * as fs from 'node:fs';
|
||||
import * as util from 'node:util';
|
||||
import Logger from '@/services/logger.js';
|
||||
import { createTemp } from './create-temp.js';
|
||||
import { downloadUrl } from './download-url.js';
|
||||
|
||||
const logger = new Logger('download-text-file');
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import * as fs from 'fs';
|
||||
import * as stream from 'stream';
|
||||
import * as util from 'util';
|
||||
import * as fs from 'node:fs';
|
||||
import * as stream from 'node:stream';
|
||||
import * as util from 'node:util';
|
||||
import got, * as Got from 'got';
|
||||
import { httpAgent, httpsAgent, StatusError } from './fetch';
|
||||
import config from '@/config/index';
|
||||
import * as chalk from 'chalk';
|
||||
import Logger from '@/services/logger';
|
||||
import { httpAgent, httpsAgent, StatusError } from './fetch.js';
|
||||
import config from '@/config/index.js';
|
||||
import chalk from 'chalk';
|
||||
import Logger from '@/services/logger.js';
|
||||
import * as IPCIDR from 'ip-cidr';
|
||||
const PrivateIp = require('private-ip');
|
||||
import PrivateIp from 'private-ip';
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
const twemojiRegex = require('twemoji-parser/dist/lib/regex').default;
|
||||
import * as twemoji from 'twemoji-parser/dist/lib/regex.js';
|
||||
const twemojiRegex = twemoji.default;
|
||||
|
||||
export const emojiRegex = new RegExp(`(${twemojiRegex.source})`);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as mfm from 'mfm-js';
|
||||
import { unique } from '@/prelude/array';
|
||||
import { unique } from '@/prelude/array.js';
|
||||
|
||||
export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] {
|
||||
const emojiNodes = mfm.extract(nodes, (node) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as mfm from 'mfm-js';
|
||||
import { unique } from '@/prelude/array';
|
||||
import { unique } from '@/prelude/array.js';
|
||||
|
||||
export function extractHashtags(nodes: mfm.MfmNode[]): string[] {
|
||||
const hashtagNodes = mfm.extract(nodes, (node) => node.type === 'hashtag');
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Meta } from '@/models/entities/meta';
|
||||
import { Meta } from '@/models/entities/meta.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
|
||||
let cache: Meta;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { fetchMeta } from './fetch-meta';
|
||||
import { ILocalUser } from '@/models/entities/user';
|
||||
import { Users } from '@/models/index';
|
||||
import { fetchMeta } from './fetch-meta.js';
|
||||
import { ILocalUser } from '@/models/entities/user.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
|
||||
export async function fetchProxyAccount(): Promise<ILocalUser | null> {
|
||||
const meta = await fetchMeta();
|
||||
|
@ -3,8 +3,8 @@ import * as https from 'https';
|
||||
import CacheableLookup from 'cacheable-lookup';
|
||||
import fetch from 'node-fetch';
|
||||
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
|
||||
import config from '@/config/index';
|
||||
import { URL } from 'url';
|
||||
import config from '@/config/index.js';
|
||||
import { URL } from 'node:url';
|
||||
|
||||
export async function getJson(url: string, accept = 'application/json, */*', timeout = 10000, headers?: Record<string, string>) {
|
||||
const res = await getResponse({
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { ulid } from 'ulid';
|
||||
import { genAid } from './id/aid';
|
||||
import { genMeid } from './id/meid';
|
||||
import { genMeidg } from './id/meidg';
|
||||
import { genObjectId } from './id/object-id';
|
||||
import config from '@/config/index';
|
||||
import { genAid } from './id/aid.js';
|
||||
import { genMeid } from './id/meid.js';
|
||||
import { genMeidg } from './id/meidg.js';
|
||||
import { genObjectId } from './id/object-id.js';
|
||||
import config from '@/config/index.js';
|
||||
|
||||
const metohd = config.id.toLowerCase();
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
* https://en.wikipedia.org/wiki/Identicon
|
||||
*/
|
||||
|
||||
import { WriteStream } from 'node:fs';
|
||||
import * as p from 'pureimage';
|
||||
import * as gen from 'random-seed';
|
||||
import { WriteStream } from 'fs';
|
||||
import gen from 'random-seed';
|
||||
|
||||
const size = 256; // px
|
||||
const n = 5; // resolution
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as crypto from 'crypto';
|
||||
import * as util from 'util';
|
||||
import * as crypto from 'node:crypto';
|
||||
import * as util from 'node:util';
|
||||
|
||||
const generateKeyPair = util.promisify(crypto.generateKeyPair);
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import * as fs from 'fs';
|
||||
import * as crypto from 'crypto';
|
||||
import * as stream from 'stream';
|
||||
import * as util from 'util';
|
||||
import * as fileType from 'file-type';
|
||||
import * as fs from 'node:fs';
|
||||
import * as crypto from 'node:crypto';
|
||||
import * as stream from 'node:stream';
|
||||
import * as util from 'node:util';
|
||||
import fileType from 'file-type';
|
||||
import isSvg from 'is-svg';
|
||||
import * as probeImageSize from 'probe-image-size';
|
||||
import * as sharp from 'sharp';
|
||||
import probeImageSize from 'probe-image-size';
|
||||
import sharp from 'sharp';
|
||||
import { encode } from 'blurhash';
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Packed } from './schema';
|
||||
import { Packed } from './schema.js';
|
||||
|
||||
/**
|
||||
* 投稿を表す文字列を取得します。
|
||||
|
@ -1,7 +1,7 @@
|
||||
// AID
|
||||
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ2の[ノイズ文字列]
|
||||
|
||||
import * as crypto from 'crypto';
|
||||
import * as crypto from 'node:crypto';
|
||||
|
||||
const TIME2000 = 946684800000;
|
||||
let counter = crypto.randomBytes(2).readUInt16LE(0);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Packed } from "./schema";
|
||||
import { Packed } from './schema.js';
|
||||
|
||||
export function isInstanceMuted(note: Packed<'Note'>, mutedInstances: Set<string>): boolean {
|
||||
if (mutedInstances.has(note?.user?.host ?? '')) return true;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
|
||||
export default function(note: Note): boolean {
|
||||
return note.renoteId != null && (note.text != null || note.hasPoll || (note.fileIds != null && note.fileIds.length > 0));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { UserKeypairs } from '@/models/index';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { UserKeypair } from '@/models/entities/user-keypair';
|
||||
import { Cache } from './cache';
|
||||
import { UserKeypairs } from '@/models/index.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { UserKeypair } from '@/models/entities/user-keypair.js';
|
||||
import { Cache } from './cache.js';
|
||||
|
||||
const cache = new Cache<UserKeypair>(Infinity);
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { In } from 'typeorm';
|
||||
import { Emojis } from '@/models/index';
|
||||
import { Emoji } from '@/models/entities/emoji';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { Cache } from './cache';
|
||||
import { isSelfHost, toPunyNullable } from './convert-host';
|
||||
import { decodeReaction } from './reaction-lib';
|
||||
import config from '@/config/index';
|
||||
import { query } from '@/prelude/url';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { Emoji } from '@/models/entities/emoji.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { Cache } from './cache.js';
|
||||
import { isSelfHost, toPunyNullable } from './convert-host.js';
|
||||
import { decodeReaction } from './reaction-lib.js';
|
||||
import config from '@/config/index.js';
|
||||
import { query } from '@/prelude/url.js';
|
||||
|
||||
const cache = new Cache<Emoji | null>(1000 * 60 * 60 * 12);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* eslint-disable key-spacing */
|
||||
import { emojiRegex } from './emoji-regex';
|
||||
import { fetchMeta } from './fetch-meta';
|
||||
import { Emojis } from '@/models/index';
|
||||
import { toPunyNullable } from './convert-host';
|
||||
import { emojiRegex } from './emoji-regex.js';
|
||||
import { fetchMeta } from './fetch-meta.js';
|
||||
import { Emojis } from '@/models/index.js';
|
||||
import { toPunyNullable } from './convert-host.js';
|
||||
|
||||
const legacies: Record<string, string> = {
|
||||
'like': '👍',
|
||||
|
@ -6,29 +6,29 @@ import {
|
||||
packedMeDetailedSchema,
|
||||
packedUserDetailedSchema,
|
||||
packedUserSchema,
|
||||
} from '@/models/schema/user';
|
||||
import { packedNoteSchema } from '@/models/schema/note';
|
||||
import { packedUserListSchema } from '@/models/schema/user-list';
|
||||
import { packedAppSchema } from '@/models/schema/app';
|
||||
import { packedMessagingMessageSchema } from '@/models/schema/messaging-message';
|
||||
import { packedNotificationSchema } from '@/models/schema/notification';
|
||||
import { packedDriveFileSchema } from '@/models/schema/drive-file';
|
||||
import { packedDriveFolderSchema } from '@/models/schema/drive-folder';
|
||||
import { packedFollowingSchema } from '@/models/schema/following';
|
||||
import { packedMutingSchema } from '@/models/schema/muting';
|
||||
import { packedBlockingSchema } from '@/models/schema/blocking';
|
||||
import { packedNoteReactionSchema } from '@/models/schema/note-reaction';
|
||||
import { packedHashtagSchema } from '@/models/schema/hashtag';
|
||||
import { packedPageSchema } from '@/models/schema/page';
|
||||
import { packedUserGroupSchema } from '@/models/schema/user-group';
|
||||
import { packedNoteFavoriteSchema } from '@/models/schema/note-favorite';
|
||||
import { packedChannelSchema } from '@/models/schema/channel';
|
||||
import { packedAntennaSchema } from '@/models/schema/antenna';
|
||||
import { packedClipSchema } from '@/models/schema/clip';
|
||||
import { packedFederationInstanceSchema } from '@/models/schema/federation-instance';
|
||||
import { packedQueueCountSchema } from '@/models/schema/queue';
|
||||
import { packedGalleryPostSchema } from '@/models/schema/gallery-post';
|
||||
import { packedEmojiSchema } from '@/models/schema/emoji';
|
||||
} from '@/models/schema/user.js';
|
||||
import { packedNoteSchema } from '@/models/schema/note.js';
|
||||
import { packedUserListSchema } from '@/models/schema/user-list.js';
|
||||
import { packedAppSchema } from '@/models/schema/app.js';
|
||||
import { packedMessagingMessageSchema } from '@/models/schema/messaging-message.js';
|
||||
import { packedNotificationSchema } from '@/models/schema/notification.js';
|
||||
import { packedDriveFileSchema } from '@/models/schema/drive-file.js';
|
||||
import { packedDriveFolderSchema } from '@/models/schema/drive-folder.js';
|
||||
import { packedFollowingSchema } from '@/models/schema/following.js';
|
||||
import { packedMutingSchema } from '@/models/schema/muting.js';
|
||||
import { packedBlockingSchema } from '@/models/schema/blocking.js';
|
||||
import { packedNoteReactionSchema } from '@/models/schema/note-reaction.js';
|
||||
import { packedHashtagSchema } from '@/models/schema/hashtag.js';
|
||||
import { packedPageSchema } from '@/models/schema/page.js';
|
||||
import { packedUserGroupSchema } from '@/models/schema/user-group.js';
|
||||
import { packedNoteFavoriteSchema } from '@/models/schema/note-favorite.js';
|
||||
import { packedChannelSchema } from '@/models/schema/channel.js';
|
||||
import { packedAntennaSchema } from '@/models/schema/antenna.js';
|
||||
import { packedClipSchema } from '@/models/schema/clip.js';
|
||||
import { packedFederationInstanceSchema } from '@/models/schema/federation-instance.js';
|
||||
import { packedQueueCountSchema } from '@/models/schema/queue.js';
|
||||
import { packedGalleryPostSchema } from '@/models/schema/gallery-post.js';
|
||||
import { packedEmojiSchema } from '@/models/schema/emoji.js';
|
||||
|
||||
export const refs = {
|
||||
UserLite: packedUserLiteSchema,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as crypto from 'crypto';
|
||||
import * as crypto from 'node:crypto';
|
||||
|
||||
const L_CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
const LU_CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as os from 'os';
|
||||
import * as sysUtils from 'systeminformation';
|
||||
import Logger from '@/services/logger';
|
||||
import * as os from 'node:os';
|
||||
import sysUtils from 'systeminformation';
|
||||
import Logger from '@/services/logger.js';
|
||||
|
||||
export async function showMachineInfo(parentLogger: Logger) {
|
||||
const logger = parentLogger.createSubLogger('machine');
|
||||
|
Reference in New Issue
Block a user