mirror of
https://example.com
synced 2024-11-22 16:46:38 +09:00
refactor: move misc/convert-host.ts to native-utils
This commit is contained in:
parent
15dabfc878
commit
c1e0186e7b
41 changed files with 161 additions and 91 deletions
|
@ -268,6 +268,12 @@ if (!nativeBinding) {
|
||||||
const {
|
const {
|
||||||
stringToAcct,
|
stringToAcct,
|
||||||
acctToString,
|
acctToString,
|
||||||
|
config,
|
||||||
|
getFullApAccount,
|
||||||
|
isSelfHost,
|
||||||
|
extractHost,
|
||||||
|
toPuny,
|
||||||
|
toPunyOptional,
|
||||||
sqlLikeEscape,
|
sqlLikeEscape,
|
||||||
safeForSql,
|
safeForSql,
|
||||||
formatMilliseconds,
|
formatMilliseconds,
|
||||||
|
@ -281,6 +287,12 @@ const {
|
||||||
|
|
||||||
module.exports.stringToAcct = stringToAcct;
|
module.exports.stringToAcct = stringToAcct;
|
||||||
module.exports.acctToString = acctToString;
|
module.exports.acctToString = acctToString;
|
||||||
|
module.exports.config = config;
|
||||||
|
module.exports.getFullApAccount = getFullApAccount;
|
||||||
|
module.exports.isSelfHost = isSelfHost;
|
||||||
|
module.exports.extractHost = extractHost;
|
||||||
|
module.exports.toPuny = toPuny;
|
||||||
|
module.exports.toPunyOptional = toPunyOptional;
|
||||||
module.exports.sqlLikeEscape = sqlLikeEscape;
|
module.exports.sqlLikeEscape = sqlLikeEscape;
|
||||||
module.exports.safeForSql = safeForSql;
|
module.exports.safeForSql = safeForSql;
|
||||||
module.exports.formatMilliseconds = formatMilliseconds;
|
module.exports.formatMilliseconds = formatMilliseconds;
|
||||||
|
|
3
packages/backend/native-utils/Cargo.lock
generated
3
packages/backend/native-utils/Cargo.lock
generated
|
@ -1436,6 +1436,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"cuid2",
|
"cuid2",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
"idna",
|
||||||
"jsonschema",
|
"jsonschema",
|
||||||
"napi",
|
"napi",
|
||||||
"napi-build",
|
"napi-build",
|
||||||
|
@ -1448,8 +1449,10 @@ dependencies = [
|
||||||
"sea-orm",
|
"sea-orm",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_yaml",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"url",
|
||||||
"utoipa",
|
"utoipa",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ cfg-if = "1.0.0"
|
||||||
chrono = "0.4.31"
|
chrono = "0.4.31"
|
||||||
cuid2 = "0.1.2"
|
cuid2 = "0.1.2"
|
||||||
derive_more = "0.99.17"
|
derive_more = "0.99.17"
|
||||||
|
idna = "0.5.0"
|
||||||
jsonschema = "0.17.1"
|
jsonschema = "0.17.1"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
parse-display = "0.8.2"
|
parse-display = "0.8.2"
|
||||||
|
@ -27,8 +28,10 @@ schemars = { version = "0.8.16", features = ["chrono"] }
|
||||||
sea-orm = { version = "0.12.10", features = ["sqlx-postgres", "runtime-tokio-rustls"] }
|
sea-orm = { version = "0.12.10", features = ["sqlx-postgres", "runtime-tokio-rustls"] }
|
||||||
serde = { version = "1.0.193", features = ["derive"] }
|
serde = { version = "1.0.193", features = ["derive"] }
|
||||||
serde_json = "1.0.108"
|
serde_json = "1.0.108"
|
||||||
|
serde_yaml = "0.9.29"
|
||||||
thiserror = "1.0.52"
|
thiserror = "1.0.52"
|
||||||
tokio = { version = "1.35.1", features = ["full"] }
|
tokio = { version = "1.35.1", features = ["full"] }
|
||||||
|
url = "2.5.0"
|
||||||
utoipa = "4.1.0"
|
utoipa = "4.1.0"
|
||||||
|
|
||||||
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
||||||
|
|
20
packages/backend/native-utils/src/util/config.rs
Normal file
20
packages/backend/native-utils/src/util/config.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde_yaml;
|
||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
/// TODO: add more fields
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi(object))]
|
||||||
|
pub struct Config {
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi)]
|
||||||
|
pub fn config() -> Config {
|
||||||
|
let cwd = env::current_dir().unwrap();
|
||||||
|
let yml = fs::File::open(cwd.join("../../.config/default.yml"))
|
||||||
|
.expect("Failed to open '.config/default.yml'");
|
||||||
|
serde_yaml::from_reader(yml).expect("Failed to parse yaml")
|
||||||
|
}
|
64
packages/backend/native-utils/src/util/convert_host.rs
Normal file
64
packages/backend/native-utils/src/util/convert_host.rs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
use crate::util::config::config;
|
||||||
|
use idna;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi)]
|
||||||
|
pub fn get_full_ap_account(username: String, host: Option<String>) -> String {
|
||||||
|
if host.is_none() {
|
||||||
|
format!("{}@{}", username, extract_host(config().url))
|
||||||
|
} else {
|
||||||
|
format!("{}@{}", username, to_puny(host.unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi)]
|
||||||
|
pub fn is_self_host(host: Option<String>) -> bool {
|
||||||
|
if let Some(x) = host {
|
||||||
|
extract_host(config().url) == to_puny(x)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi)]
|
||||||
|
pub fn extract_host(uri: String) -> String {
|
||||||
|
to_puny(
|
||||||
|
Url::parse(uri.as_str())
|
||||||
|
.expect("Invalid uri")
|
||||||
|
.host_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi)]
|
||||||
|
pub fn to_puny(host: String) -> String {
|
||||||
|
idna::domain_to_ascii(&host).expect("Failed to encode the host to punycode")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "napi", napi_derive::napi)]
|
||||||
|
pub fn to_puny_optional(host: Option<String>) -> Option<String> {
|
||||||
|
host.map(to_puny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod unit_test {
|
||||||
|
use super::{extract_host, to_puny};
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_host_test() {
|
||||||
|
assert_eq!(
|
||||||
|
extract_host("https://git.joinfirefish.org/firefish/firefish.git".to_string()),
|
||||||
|
"git.joinfirefish.org".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_puny_test() {
|
||||||
|
assert_eq!(
|
||||||
|
to_puny("何もかも.owari.shop".to_string()),
|
||||||
|
"xn--u8jyfb5762a.owari.shop".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
pub mod acct;
|
pub mod acct;
|
||||||
|
pub mod config;
|
||||||
|
pub mod convert_host;
|
||||||
pub mod escape_sql;
|
pub mod escape_sql;
|
||||||
pub mod format_milliseconds;
|
pub mod format_milliseconds;
|
||||||
pub mod id;
|
pub mod id;
|
||||||
|
|
|
@ -2,8 +2,7 @@ import type { Antenna } from "@/models/entities/antenna.js";
|
||||||
import type { Note } from "@/models/entities/note.js";
|
import type { Note } from "@/models/entities/note.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
import { Blockings, Followings, UserProfiles } from "@/models/index.js";
|
import { Blockings, Followings, UserProfiles } from "@/models/index.js";
|
||||||
import { getFullApAccount } from "@/misc/convert-host.js";
|
import { getFullApAccount, stringToAcct } from "native-utils/built/index.js";
|
||||||
import { stringToAcct } from "native-utils/built/index.js";
|
|
||||||
import type { Packed } from "@/misc/schema.js";
|
import type { Packed } from "@/misc/schema.js";
|
||||||
import { Cache } from "@/misc/cache.js";
|
import { Cache } from "@/misc/cache.js";
|
||||||
import { getWordHardMute } from "@/misc/check-word-mute.js";
|
import { getWordHardMute } from "@/misc/check-word-mute.js";
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
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)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isSelfHost(host: string) {
|
|
||||||
if (host == null) return true;
|
|
||||||
return toPuny(config.host) === toPuny(host);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function extractDbHost(uri: string) {
|
|
||||||
const url = new URL(uri);
|
|
||||||
return toPuny(url.hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function toPuny(host: string) {
|
|
||||||
return toASCII(host.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
export function toPunyNullable(host: string | null | undefined): string | null {
|
|
||||||
if (host == null) return null;
|
|
||||||
return toASCII(host.toLowerCase());
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@ import { Emojis } from "@/models/index.js";
|
||||||
import type { Emoji } from "@/models/entities/emoji.js";
|
import type { Emoji } from "@/models/entities/emoji.js";
|
||||||
import type { Note } from "@/models/entities/note.js";
|
import type { Note } from "@/models/entities/note.js";
|
||||||
import { Cache } from "./cache.js";
|
import { Cache } from "./cache.js";
|
||||||
import { isSelfHost, toPunyNullable } from "./convert-host.js";
|
import { isSelfHost, toPunyOptional } from "native-utils/built/index.js";
|
||||||
import { decodeReaction } from "./reaction-lib.js";
|
import { decodeReaction } from "./reaction-lib.js";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
import { query } from "@/prelude/url.js";
|
import { query } from "@/prelude/url.js";
|
||||||
|
@ -35,7 +35,7 @@ function normalizeHost(
|
||||||
? null // 自ホスト指定
|
? null // 自ホスト指定
|
||||||
: src || noteUserHost; // 指定されたホスト || ノートなどの所有者のホスト (こっちがリアクションにマッチすることはない)
|
: src || noteUserHost; // 指定されたホスト || ノートなどの所有者のホスト (こっちがリアクションにマッチすることはない)
|
||||||
|
|
||||||
host = toPunyNullable(host);
|
host = toPunyOptional(host);
|
||||||
|
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ function parseEmojiStr(emojiName: string, noteUserHost: string | null) {
|
||||||
const name = match[1];
|
const name = match[1];
|
||||||
|
|
||||||
// ホスト正規化
|
// ホスト正規化
|
||||||
const host = toPunyNullable(normalizeHost(match[2], noteUserHost));
|
const host = toPunyOptional(normalizeHost(match[2], noteUserHost));
|
||||||
|
|
||||||
return { name, host };
|
return { name, host };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { emojiRegex } from "./emoji-regex.js";
|
import { emojiRegex } from "./emoji-regex.js";
|
||||||
import { fetchMeta } from "./fetch-meta.js";
|
import { fetchMeta } from "./fetch-meta.js";
|
||||||
import { Emojis } from "@/models/index.js";
|
import { Emojis } from "@/models/index.js";
|
||||||
import { toPunyNullable } from "./convert-host.js";
|
import { toPunyOptional } from "native-utils/built/index.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
|
|
||||||
export function convertReactions(reactions: Record<string, number>) {
|
export function convertReactions(reactions: Record<string, number>) {
|
||||||
|
@ -23,7 +23,7 @@ export async function toDbReaction(
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (!reaction) return (await fetchMeta()).defaultReaction;
|
if (!reaction) return (await fetchMeta()).defaultReaction;
|
||||||
|
|
||||||
reacterHost = toPunyNullable(reacterHost);
|
reacterHost = toPunyOptional(reacterHost);
|
||||||
|
|
||||||
if (reaction.includes("❤") || reaction.includes("♥️")) return "❤️";
|
if (reaction.includes("❤") || reaction.includes("♥️")) return "❤️";
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { db } from "@/db/postgre.js";
|
import { db } from "@/db/postgre.js";
|
||||||
import { DriveFile } from "@/models/entities/drive-file.js";
|
import { DriveFile } from "@/models/entities/drive-file.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import { awaitAll } from "@/prelude/await-all.js";
|
import { awaitAll } from "@/prelude/await-all.js";
|
||||||
import type { Packed } from "@/misc/schema.js";
|
import type { Packed } from "@/misc/schema.js";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as fs from "node:fs";
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { addFile } from "@/services/drive/add-file.js";
|
import { addFile } from "@/services/drive/add-file.js";
|
||||||
import { format as dateFormat } from "date-fns";
|
import { format as dateFormat } from "date-fns";
|
||||||
import { getFullApAccount } from "@/misc/convert-host.js";
|
import { getFullApAccount } from "native-utils/built/index.js";
|
||||||
import { createTemp } from "@/misc/create-temp.js";
|
import { createTemp } from "@/misc/create-temp.js";
|
||||||
import { Users, Blockings } from "@/models/index.js";
|
import { Users, Blockings } from "@/models/index.js";
|
||||||
import { MoreThan } from "typeorm";
|
import { MoreThan } from "typeorm";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as fs from "node:fs";
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { addFile } from "@/services/drive/add-file.js";
|
import { addFile } from "@/services/drive/add-file.js";
|
||||||
import { format as dateFormat } from "date-fns";
|
import { format as dateFormat } from "date-fns";
|
||||||
import { getFullApAccount } from "@/misc/convert-host.js";
|
import { getFullApAccount } from "native-utils/built/index.js";
|
||||||
import { createTemp } from "@/misc/create-temp.js";
|
import { createTemp } from "@/misc/create-temp.js";
|
||||||
import { Users, Followings, Mutings } from "@/models/index.js";
|
import { Users, Followings, Mutings } from "@/models/index.js";
|
||||||
import { In, MoreThan, Not } from "typeorm";
|
import { In, MoreThan, Not } from "typeorm";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as fs from "node:fs";
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { addFile } from "@/services/drive/add-file.js";
|
import { addFile } from "@/services/drive/add-file.js";
|
||||||
import { format as dateFormat } from "date-fns";
|
import { format as dateFormat } from "date-fns";
|
||||||
import { getFullApAccount } from "@/misc/convert-host.js";
|
import { getFullApAccount } from "native-utils/built/index.js";
|
||||||
import { createTemp } from "@/misc/create-temp.js";
|
import { createTemp } from "@/misc/create-temp.js";
|
||||||
import { Users, Mutings } from "@/models/index.js";
|
import { Users, Mutings } from "@/models/index.js";
|
||||||
import { IsNull, MoreThan } from "typeorm";
|
import { IsNull, MoreThan } from "typeorm";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as fs from "node:fs";
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { addFile } from "@/services/drive/add-file.js";
|
import { addFile } from "@/services/drive/add-file.js";
|
||||||
import { format as dateFormat } from "date-fns";
|
import { format as dateFormat } from "date-fns";
|
||||||
import { getFullApAccount } from "@/misc/convert-host.js";
|
import { getFullApAccount } from "native-utils/built/index.js";
|
||||||
import { createTemp } from "@/misc/create-temp.js";
|
import { createTemp } from "@/misc/create-temp.js";
|
||||||
import { Users, UserLists, UserListJoinings } from "@/models/index.js";
|
import { Users, UserLists, UserListJoinings } from "@/models/index.js";
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import type Bull from "bull";
|
import type Bull from "bull";
|
||||||
|
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { stringToAcct } from "native-utils/built/index.js";
|
|
||||||
import { resolveUser } from "@/remote/resolve-user.js";
|
import { resolveUser } from "@/remote/resolve-user.js";
|
||||||
import { downloadTextFile } from "@/misc/download-text-file.js";
|
import { downloadTextFile } from "@/misc/download-text-file.js";
|
||||||
import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
import { isSelfHost, stringToAcct, toPuny } from "native-utils/built/index.js";
|
||||||
import { Users, DriveFiles } from "@/models/index.js";
|
import { Users, DriveFiles } from "@/models/index.js";
|
||||||
import type { DbUserImportJobData } from "@/queue/types.js";
|
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||||
import block from "@/services/blocking/create.js";
|
import block from "@/services/blocking/create.js";
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import follow from "@/services/following/create.js";
|
import follow from "@/services/following/create.js";
|
||||||
|
|
||||||
import { stringToAcct } from "native-utils/built/index.js";
|
|
||||||
import { resolveUser } from "@/remote/resolve-user.js";
|
import { resolveUser } from "@/remote/resolve-user.js";
|
||||||
import { downloadTextFile } from "@/misc/download-text-file.js";
|
import { downloadTextFile } from "@/misc/download-text-file.js";
|
||||||
import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
import { isSelfHost, stringToAcct, toPuny } from "native-utils/built/index.js";
|
||||||
import { Users, DriveFiles } from "@/models/index.js";
|
import { Users, DriveFiles } from "@/models/index.js";
|
||||||
import type { DbUserImportJobData } from "@/queue/types.js";
|
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import type Bull from "bull";
|
import type Bull from "bull";
|
||||||
|
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { stringToAcct } from "native-utils/built/index.js";
|
|
||||||
import { resolveUser } from "@/remote/resolve-user.js";
|
import { resolveUser } from "@/remote/resolve-user.js";
|
||||||
import { downloadTextFile } from "@/misc/download-text-file.js";
|
import { downloadTextFile } from "@/misc/download-text-file.js";
|
||||||
import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
import { isSelfHost, stringToAcct, toPuny } from "native-utils/built/index.js";
|
||||||
import { Users, DriveFiles, Mutings } from "@/models/index.js";
|
import { Users, DriveFiles, Mutings } from "@/models/index.js";
|
||||||
import type { DbUserImportJobData } from "@/queue/types.js";
|
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import type Bull from "bull";
|
import type Bull from "bull";
|
||||||
|
|
||||||
import { queueLogger } from "../../logger.js";
|
import { queueLogger } from "../../logger.js";
|
||||||
import { stringToAcct } from "native-utils/built/index.js";
|
|
||||||
import { resolveUser } from "@/remote/resolve-user.js";
|
import { resolveUser } from "@/remote/resolve-user.js";
|
||||||
import { pushUserToUserList } from "@/services/user-list/push.js";
|
import { pushUserToUserList } from "@/services/user-list/push.js";
|
||||||
import { downloadTextFile } from "@/misc/download-text-file.js";
|
import { downloadTextFile } from "@/misc/download-text-file.js";
|
||||||
import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
import { isSelfHost, stringToAcct, toPuny } from "native-utils/built/index.js";
|
||||||
import {
|
import {
|
||||||
DriveFiles,
|
DriveFiles,
|
||||||
Users,
|
Users,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instanc
|
||||||
import Logger from "@/services/logger.js";
|
import Logger from "@/services/logger.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import { StatusError } from "@/misc/fetch.js";
|
import { StatusError } from "@/misc/fetch.js";
|
||||||
import { shouldSkipInstance } from "@/misc/skipped-instances.js";
|
import { shouldSkipInstance } from "@/misc/skipped-instances.js";
|
||||||
import type { DeliverJobData } from "@/queue/types.js";
|
import type { DeliverJobData } from "@/queue/types.js";
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Logger from "@/services/logger.js";
|
||||||
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||||
import { toPuny, extractDbHost } from "@/misc/convert-host.js";
|
import { toPuny, extractHost } from "native-utils/built/index.js";
|
||||||
import { getApId } from "@/remote/activitypub/type.js";
|
import { getApId } from "@/remote/activitypub/type.js";
|
||||||
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
||||||
import type { InboxJobData } from "../types.js";
|
import type { InboxJobData } from "../types.js";
|
||||||
|
@ -158,7 +158,7 @@ export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ブロックしてたら中断
|
// ブロックしてたら中断
|
||||||
const ldHost = extractDbHost(authUser.user.uri);
|
const ldHost = extractHost(authUser.user.uri);
|
||||||
if (await shouldBlockInstance(ldHost, meta)) {
|
if (await shouldBlockInstance(ldHost, meta)) {
|
||||||
return `Blocked request: ${ldHost}`;
|
return `Blocked request: ${ldHost}`;
|
||||||
}
|
}
|
||||||
|
@ -169,8 +169,8 @@ export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
|
||||||
|
|
||||||
// activity.idがあればホストが署名者のホストであることを確認する
|
// activity.idがあればホストが署名者のホストであることを確認する
|
||||||
if (typeof activity.id === "string") {
|
if (typeof activity.id === "string") {
|
||||||
const signerHost = extractDbHost(authUser.user.uri!);
|
const signerHost = extractHost(authUser.user.uri!);
|
||||||
const activityIdHost = extractDbHost(activity.id);
|
const activityIdHost = extractHost(activity.id);
|
||||||
if (signerHost !== activityIdHost) {
|
if (signerHost !== activityIdHost) {
|
||||||
return `skip: signerHost(${signerHost}) !== activity.id host(${activityIdHost}`;
|
return `skip: signerHost(${signerHost}) !== activity.id host(${activityIdHost}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { URL } from "url";
|
||||||
import httpSignature, { IParsedSignature } from "@peertube/http-signature";
|
import httpSignature, { IParsedSignature } from "@peertube/http-signature";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import DbResolver from "@/remote/activitypub/db-resolver.js";
|
import DbResolver from "@/remote/activitypub/db-resolver.js";
|
||||||
import { getApId } from "@/remote/activitypub/type.js";
|
import { getApId } from "@/remote/activitypub/type.js";
|
||||||
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
||||||
|
|
|
@ -5,7 +5,7 @@ import type { IAnnounce } from "../../type.js";
|
||||||
import { getApId } from "../../type.js";
|
import { getApId } from "../../type.js";
|
||||||
import { fetchNote, resolveNote } from "../../models/note.js";
|
import { fetchNote, resolveNote } from "../../models/note.js";
|
||||||
import { apLogger } from "../../logger.js";
|
import { apLogger } from "../../logger.js";
|
||||||
import { extractDbHost } from "@/misc/convert-host.js";
|
import { extractHost } from "native-utils/built/index.js";
|
||||||
import { getApLock } from "@/misc/app-lock.js";
|
import { getApLock } from "@/misc/app-lock.js";
|
||||||
import { parseAudience } from "../../audience.js";
|
import { parseAudience } from "../../audience.js";
|
||||||
import { StatusError } from "@/misc/fetch.js";
|
import { StatusError } from "@/misc/fetch.js";
|
||||||
|
@ -30,7 +30,7 @@ export default async function (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interrupt if you block the announcement destination
|
// Interrupt if you block the announcement destination
|
||||||
if (await shouldBlockInstance(extractDbHost(uri))) return;
|
if (await shouldBlockInstance(extractHost(uri))) return;
|
||||||
|
|
||||||
const lock = await getApLock(uri);
|
const lock = await getApLock(uri);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { createNote, fetchNote } from "../../models/note.js";
|
||||||
import type { IObject, ICreate } from "../../type.js";
|
import type { IObject, ICreate } from "../../type.js";
|
||||||
import { getApId } from "../../type.js";
|
import { getApId } from "../../type.js";
|
||||||
import { getApLock } from "@/misc/app-lock.js";
|
import { getApLock } from "@/misc/app-lock.js";
|
||||||
import { extractDbHost } from "@/misc/convert-host.js";
|
import { extractHost } from "native-utils/built/index.js";
|
||||||
import { StatusError } from "@/misc/fetch.js";
|
import { StatusError } from "@/misc/fetch.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,7 +25,7 @@ export default async function (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof note.id === "string") {
|
if (typeof note.id === "string") {
|
||||||
if (extractDbHost(actor.uri) !== extractDbHost(note.id)) {
|
if (extractHost(actor.uri) !== extractHost(note.id)) {
|
||||||
return "skip: host in actor.uri !== note.id";
|
return "skip: host in actor.uri !== note.id";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import block from "./block/index.js";
|
||||||
import flag from "./flag/index.js";
|
import flag from "./flag/index.js";
|
||||||
import move from "./move/index.js";
|
import move from "./move/index.js";
|
||||||
import type { IObject, IActivity } from "../type.js";
|
import type { IObject, IActivity } from "../type.js";
|
||||||
import { extractDbHost } from "@/misc/convert-host.js";
|
import { extractHost } from "native-utils/built/index.js";
|
||||||
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
||||||
|
|
||||||
export async function performActivity(
|
export async function performActivity(
|
||||||
|
@ -71,7 +71,7 @@ async function performOneActivity(
|
||||||
if (actor.isSuspended) return;
|
if (actor.isSuspended) return;
|
||||||
|
|
||||||
if (typeof activity.id !== "undefined") {
|
if (typeof activity.id !== "undefined") {
|
||||||
const host = extractDbHost(getApId(activity));
|
const host = extractHost(getApId(activity));
|
||||||
if (await shouldBlockInstance(host)) return;
|
if (await shouldBlockInstance(host)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { CacheableRemoteUser } from "@/models/entities/user.js";
|
import type { CacheableRemoteUser } from "@/models/entities/user.js";
|
||||||
import type { IRead } from "../type.js";
|
import type { IRead } from "../type.js";
|
||||||
import { getApId } from "../type.js";
|
import { getApId } from "../type.js";
|
||||||
import { isSelfHost, extractDbHost } from "@/misc/convert-host.js";
|
import { isSelfHost, extractHost } from "native-utils/built/index.js";
|
||||||
import { MessagingMessages } from "@/models/index.js";
|
import { MessagingMessages } from "@/models/index.js";
|
||||||
import { readUserMessagingMessage } from "@/server/api/common/read-messaging-message.js";
|
import { readUserMessagingMessage } from "@/server/api/common/read-messaging-message.js";
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ export const performReadActivity = async (
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const id = await getApId(activity.object);
|
const id = await getApId(activity.object);
|
||||||
|
|
||||||
if (!isSelfHost(extractDbHost(id))) {
|
if (!isSelfHost(extractHost(id))) {
|
||||||
return `skip: Read to foreign host (${id})`;
|
return `skip: Read to foreign host (${id})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { extractPollFromQuestion } from "./question.js";
|
||||||
import vote from "@/services/note/polls/vote.js";
|
import vote from "@/services/note/polls/vote.js";
|
||||||
import { apLogger } from "../logger.js";
|
import { apLogger } from "../logger.js";
|
||||||
import { DriveFile } from "@/models/entities/drive-file.js";
|
import { DriveFile } from "@/models/entities/drive-file.js";
|
||||||
import { extractDbHost, toPuny } from "@/misc/convert-host.js";
|
import { extractHost, toPuny } from "native-utils/built/index.js";
|
||||||
import {
|
import {
|
||||||
Emojis,
|
Emojis,
|
||||||
Polls,
|
Polls,
|
||||||
|
@ -54,7 +54,7 @@ import { langmap } from "@/misc/langmap.js";
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
export function validateNote(object: any, uri: string) {
|
export function validateNote(object: any, uri: string) {
|
||||||
const expectHost = extractDbHost(uri);
|
const expectHost = extractHost(uri);
|
||||||
|
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return new Error("invalid Note: object is null");
|
return new Error("invalid Note: object is null");
|
||||||
|
@ -64,9 +64,9 @@ export function validateNote(object: any, uri: string) {
|
||||||
return new Error(`invalid Note: invalid object type ${getApType(object)}`);
|
return new Error(`invalid Note: invalid object type ${getApType(object)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object.id && extractDbHost(object.id) !== expectHost) {
|
if (object.id && extractHost(object.id) !== expectHost) {
|
||||||
return new Error(
|
return new Error(
|
||||||
`invalid Note: id has different host. expected: ${expectHost}, actual: ${extractDbHost(
|
`invalid Note: id has different host. expected: ${expectHost}, actual: ${extractHost(
|
||||||
object.id,
|
object.id,
|
||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
|
@ -74,10 +74,10 @@ export function validateNote(object: any, uri: string) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
object.attributedTo &&
|
object.attributedTo &&
|
||||||
extractDbHost(getOneApId(object.attributedTo)) !== expectHost
|
extractHost(getOneApId(object.attributedTo)) !== expectHost
|
||||||
) {
|
) {
|
||||||
return new Error(
|
return new Error(
|
||||||
`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${extractDbHost(
|
`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${extractHost(
|
||||||
object.attributedTo,
|
object.attributedTo,
|
||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
|
@ -422,11 +422,11 @@ export async function resolveNote(
|
||||||
if (uri == null) throw new Error("missing uri");
|
if (uri == null) throw new Error("missing uri");
|
||||||
|
|
||||||
// Abort if origin host is blocked
|
// Abort if origin host is blocked
|
||||||
if (await shouldBlockInstance(extractDbHost(uri)))
|
if (await shouldBlockInstance(extractHost(uri)))
|
||||||
throw new StatusError(
|
throw new StatusError(
|
||||||
"host blocked",
|
"host blocked",
|
||||||
451,
|
451,
|
||||||
`host ${extractDbHost(uri)} is blocked`,
|
`host ${extractHost(uri)} is blocked`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const lock = await getApLock(uri);
|
const lock = await getApLock(uri);
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { UserNotePining } from "@/models/entities/user-note-pining.js";
|
||||||
import { genId } from "@/misc/gen-id.js";
|
import { genId } from "@/misc/gen-id.js";
|
||||||
import { UserPublickey } from "@/models/entities/user-publickey.js";
|
import { UserPublickey } from "@/models/entities/user-publickey.js";
|
||||||
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import { UserProfile } from "@/models/entities/user-profile.js";
|
import { UserProfile } from "@/models/entities/user-profile.js";
|
||||||
import { toArray } from "@/prelude/array.js";
|
import { toArray } from "@/prelude/array.js";
|
||||||
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { getJson } from "@/misc/fetch.js";
|
||||||
import type { ILocalUser } from "@/models/entities/user.js";
|
import type { ILocalUser } from "@/models/entities/user.js";
|
||||||
import { getInstanceActor } from "@/services/instance-actor.js";
|
import { getInstanceActor } from "@/services/instance-actor.js";
|
||||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||||
import { extractDbHost, isSelfHost } from "@/misc/convert-host.js";
|
import { extractHost, isSelfHost } from "native-utils/built/index.js";
|
||||||
import { signedGet } from "./request.js";
|
import { signedGet } from "./request.js";
|
||||||
import type { IObject, ICollection, IOrderedCollection } from "./type.js";
|
import type { IObject, ICollection, IOrderedCollection } from "./type.js";
|
||||||
import { isCollectionOrOrderedCollection, getApId } from "./type.js";
|
import { isCollectionOrOrderedCollection, getApId } from "./type.js";
|
||||||
|
@ -62,7 +62,7 @@ export default class Resolver {
|
||||||
if (typeof value !== "string") {
|
if (typeof value !== "string") {
|
||||||
apLogger.debug("Object to resolve is not a string");
|
apLogger.debug("Object to resolve is not a string");
|
||||||
if (typeof value.id !== "undefined") {
|
if (typeof value.id !== "undefined") {
|
||||||
const host = extractDbHost(getApId(value));
|
const host = extractHost(getApId(value));
|
||||||
if (await shouldBlockInstance(host)) {
|
if (await shouldBlockInstance(host)) {
|
||||||
throw new Error("instance is blocked");
|
throw new Error("instance is blocked");
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ export default class Resolver {
|
||||||
}
|
}
|
||||||
this.history.add(value);
|
this.history.add(value);
|
||||||
|
|
||||||
const host = extractDbHost(value);
|
const host = extractHost(value);
|
||||||
if (isSelfHost(host)) {
|
if (isSelfHost(host)) {
|
||||||
return await this.resolveLocal(value);
|
return await this.resolveLocal(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { IsNull } from "typeorm";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
import type { User, IRemoteUser } from "@/models/entities/user.js";
|
import type { User, IRemoteUser } from "@/models/entities/user.js";
|
||||||
import { Users } from "@/models/index.js";
|
import { Users } from "@/models/index.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import webFinger from "./webfinger.js";
|
import webFinger from "./webfinger.js";
|
||||||
import { createPerson, updatePerson } from "./activitypub/models/person.js";
|
import { createPerson, updatePerson } from "./activitypub/models/person.js";
|
||||||
import { remoteLogger } from "./logger.js";
|
import { remoteLogger } from "./logger.js";
|
||||||
|
|
|
@ -9,7 +9,7 @@ import renderKey from "@/remote/activitypub/renderer/key.js";
|
||||||
import { renderPerson } from "@/remote/activitypub/renderer/person.js";
|
import { renderPerson } from "@/remote/activitypub/renderer/person.js";
|
||||||
import renderEmoji from "@/remote/activitypub/renderer/emoji.js";
|
import renderEmoji from "@/remote/activitypub/renderer/emoji.js";
|
||||||
import { inbox as processInbox } from "@/queue/index.js";
|
import { inbox as processInbox } from "@/queue/index.js";
|
||||||
import { isSelfHost } from "@/misc/convert-host.js";
|
import { isSelfHost } from "native-utils/built/index.js";
|
||||||
import {
|
import {
|
||||||
Notes,
|
Notes,
|
||||||
Users,
|
Users,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Users, UsedUsernames } from "@/models/index.js";
|
||||||
import { UserProfile } from "@/models/entities/user-profile.js";
|
import { UserProfile } from "@/models/entities/user-profile.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { genId } from "@/misc/gen-id.js";
|
import { genId } from "@/misc/gen-id.js";
|
||||||
import { toPunyNullable } from "@/misc/convert-host.js";
|
import { toPunyOptional } from "native-utils/built/index.js";
|
||||||
import { UserKeypair } from "@/models/entities/user-keypair.js";
|
import { UserKeypair } from "@/models/entities/user-keypair.js";
|
||||||
import { UsedUsername } from "@/models/entities/used-username.js";
|
import { UsedUsername } from "@/models/entities/used-username.js";
|
||||||
import { db } from "@/db/postgre.js";
|
import { db } from "@/db/postgre.js";
|
||||||
|
@ -100,7 +100,7 @@ export async function signup(opts: {
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
username: username,
|
username: username,
|
||||||
usernameLower: username.toLowerCase(),
|
usernameLower: username.toLowerCase(),
|
||||||
host: toPunyNullable(host),
|
host: toPunyOptional(host),
|
||||||
token: secret,
|
token: secret,
|
||||||
isAdmin:
|
isAdmin:
|
||||||
(await Users.countBy({
|
(await Users.countBy({
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import define from "@/server/api/define.js";
|
import define from "@/server/api/define.js";
|
||||||
import { ApiError } from "@/server/api/error.js";
|
import { ApiError } from "@/server/api/error.js";
|
||||||
import { Emojis } from "@/models/index.js";
|
import { Emojis } from "@/models/index.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
|
||||||
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
||||||
import { sqlLikeEscape } from "native-utils/built/index.js";
|
import { sqlLikeEscape, toPuny } from "native-utils/built/index.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ["admin", "emoji"],
|
tags: ["admin", "emoji"],
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import define from "@/server/api/define.js";
|
import define from "@/server/api/define.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import define from "@/server/api/define.js";
|
import define from "@/server/api/define.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ["admin"],
|
tags: ["admin"],
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { createNote } from "@/remote/activitypub/models/note.js";
|
||||||
import DbResolver from "@/remote/activitypub/db-resolver.js";
|
import DbResolver from "@/remote/activitypub/db-resolver.js";
|
||||||
import Resolver from "@/remote/activitypub/resolver.js";
|
import Resolver from "@/remote/activitypub/resolver.js";
|
||||||
import { ApiError } from "@/server/api/error.js";
|
import { ApiError } from "@/server/api/error.js";
|
||||||
import { extractDbHost } from "@/misc/convert-host.js";
|
import { extractHost } from "native-utils/built/index.js";
|
||||||
import { Users, Notes } from "@/models/index.js";
|
import { Users, Notes } from "@/models/index.js";
|
||||||
import type { Note } from "@/models/entities/note.js";
|
import type { Note } from "@/models/entities/note.js";
|
||||||
import type { CacheableLocalUser, User } from "@/models/entities/user.js";
|
import type { CacheableLocalUser, User } from "@/models/entities/user.js";
|
||||||
|
@ -101,7 +101,7 @@ async function fetchAny(
|
||||||
me: CacheableLocalUser | null | undefined,
|
me: CacheableLocalUser | null | undefined,
|
||||||
): Promise<SchemaType<(typeof meta)["res"]> | null> {
|
): Promise<SchemaType<(typeof meta)["res"]> | null> {
|
||||||
// Wait if blocked.
|
// Wait if blocked.
|
||||||
if (await shouldBlockInstance(extractDbHost(uri))) return null;
|
if (await shouldBlockInstance(extractHost(uri))) return null;
|
||||||
|
|
||||||
const dbResolver = new DbResolver();
|
const dbResolver = new DbResolver();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import define from "@/server/api/define.js";
|
import define from "@/server/api/define.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ["federation"],
|
tags: ["federation"],
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { Users, Followings, UserProfiles } from "@/models/index.js";
|
import { Users, Followings, UserProfiles } from "@/models/index.js";
|
||||||
import { toPunyNullable } from "@/misc/convert-host.js";
|
import { toPunyOptional } from "native-utils/built/index.js";
|
||||||
import define from "@/server/api/define.js";
|
import define from "@/server/api/define.js";
|
||||||
import { ApiError } from "@/server/api/error.js";
|
import { ApiError } from "@/server/api/error.js";
|
||||||
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
||||||
|
@ -80,7 +80,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
? { id: ps.userId }
|
? { id: ps.userId }
|
||||||
: {
|
: {
|
||||||
usernameLower: ps.username?.toLowerCase(),
|
usernameLower: ps.username?.toLowerCase(),
|
||||||
host: toPunyNullable(ps.host) ?? IsNull(),
|
host: toPunyOptional(ps.host) ?? IsNull(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { Users, Followings, UserProfiles } from "@/models/index.js";
|
import { Users, Followings, UserProfiles } from "@/models/index.js";
|
||||||
import { toPunyNullable } from "@/misc/convert-host.js";
|
import { toPunyOptional } from "native-utils/built/index.js";
|
||||||
import define from "@/server/api/define.js";
|
import define from "@/server/api/define.js";
|
||||||
import { ApiError } from "@/server/api/error.js";
|
import { ApiError } from "@/server/api/error.js";
|
||||||
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
||||||
|
@ -79,7 +79,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
? { id: ps.userId }
|
? { id: ps.userId }
|
||||||
: {
|
: {
|
||||||
usernameLower: ps.username?.toLowerCase(),
|
usernameLower: ps.username?.toLowerCase(),
|
||||||
host: toPunyNullable(ps.host) ?? IsNull(),
|
host: toPunyOptional(ps.host) ?? IsNull(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import renderNote from "@/remote/activitypub/renderer/note.js";
|
||||||
import renderCreate from "@/remote/activitypub/renderer/create.js";
|
import renderCreate from "@/remote/activitypub/renderer/create.js";
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import { deliver } from "@/queue/index.js";
|
import { deliver } from "@/queue/index.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
|
|
||||||
export async function createMessage(
|
export async function createMessage(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Instance } from "@/models/entities/instance.js";
|
import type { Instance } from "@/models/entities/instance.js";
|
||||||
import { Instances } from "@/models/index.js";
|
import { Instances } from "@/models/index.js";
|
||||||
import { genId } from "@/misc/gen-id.js";
|
import { genId } from "@/misc/gen-id.js";
|
||||||
import { toPuny } from "@/misc/convert-host.js";
|
import { toPuny } from "native-utils/built/index.js";
|
||||||
import { Cache } from "@/misc/cache.js";
|
import { Cache } from "@/misc/cache.js";
|
||||||
|
|
||||||
const cache = new Cache<Instance>("registerOrFetchInstanceDoc", 60 * 60);
|
const cache = new Cache<Instance>("registerOrFetchInstanceDoc", 60 * 60);
|
||||||
|
|
Loading…
Reference in a new issue