refactor (backend): port fetch-meta to backend-rs
Co-authored-by: naskya <m@naskya.net>
This commit is contained in:
parent
ceca260c92
commit
b71da18b03
57 changed files with 229 additions and 210 deletions
13
packages/backend-rs/index.d.ts
vendored
13
packages/backend-rs/index.d.ts
vendored
|
@ -136,6 +136,19 @@ export function toPuny(host: string): string
|
|||
export function formatMilliseconds(milliseconds: number): string
|
||||
export function toMastodonId(firefishId: string): string | null
|
||||
export function fromMastodonId(mastodonId: string): string | null
|
||||
export function fetchMeta(useCache: boolean): Promise<Meta>
|
||||
export interface PugArgs {
|
||||
img: string | null
|
||||
title: string
|
||||
instanceName: string
|
||||
desc: string | null
|
||||
icon: string | null
|
||||
splashIcon: string | null
|
||||
themeColor: string | null
|
||||
randomMotd: string
|
||||
privateMode: boolean | null
|
||||
}
|
||||
export function metaToPugArgs(meta: Meta): PugArgs
|
||||
export function nyaify(text: string, lang?: string | undefined | null): string
|
||||
export function hashPassword(password: string): string
|
||||
export function verifyPassword(password: string, hash: string): boolean
|
||||
|
|
|
@ -310,7 +310,7 @@ if (!nativeBinding) {
|
|||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
const { readServerConfig, stringToAcct, acctToString, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, formatMilliseconds, toMastodonId, fromMastodonId, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, AntennaSrcEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, initIdGenerator, getTimestamp, genId, secureRndstr } = nativeBinding
|
||||
const { readServerConfig, stringToAcct, acctToString, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, formatMilliseconds, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, AntennaSrcEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, initIdGenerator, getTimestamp, genId, secureRndstr } = nativeBinding
|
||||
|
||||
module.exports.readServerConfig = readServerConfig
|
||||
module.exports.stringToAcct = stringToAcct
|
||||
|
@ -324,6 +324,8 @@ module.exports.toPuny = toPuny
|
|||
module.exports.formatMilliseconds = formatMilliseconds
|
||||
module.exports.toMastodonId = toMastodonId
|
||||
module.exports.fromMastodonId = fromMastodonId
|
||||
module.exports.fetchMeta = fetchMeta
|
||||
module.exports.metaToPugArgs = metaToPugArgs
|
||||
module.exports.nyaify = nyaify
|
||||
module.exports.hashPassword = hashPassword
|
||||
module.exports.verifyPassword = verifyPassword
|
||||
|
|
83
packages/backend-rs/src/misc/meta.rs
Normal file
83
packages/backend-rs/src/misc/meta.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
use crate::database::db_conn;
|
||||
use crate::model::entity::meta;
|
||||
use rand::prelude::*;
|
||||
use sea_orm::{prelude::*, ActiveValue};
|
||||
use std::sync::Mutex;
|
||||
|
||||
type Meta = meta::Model;
|
||||
|
||||
static CACHE: Mutex<Option<Meta>> = Mutex::new(None);
|
||||
fn update_cache(meta: &Meta) {
|
||||
let _ = CACHE.lock().map(|mut cache| *cache = Some(meta.clone()));
|
||||
}
|
||||
|
||||
#[crate::export]
|
||||
pub async fn fetch_meta(use_cache: bool) -> Result<Meta, DbErr> {
|
||||
// try using cache
|
||||
if use_cache {
|
||||
if let Some(cache) = CACHE.lock().ok().and_then(|cache| cache.clone()) {
|
||||
return Ok(cache);
|
||||
}
|
||||
}
|
||||
|
||||
// try fetching from db
|
||||
let db = db_conn().await?;
|
||||
let meta = meta::Entity::find().one(db).await?;
|
||||
if let Some(meta) = meta {
|
||||
update_cache(&meta);
|
||||
return Ok(meta);
|
||||
}
|
||||
|
||||
// create a new meta object and insert into db
|
||||
let meta = meta::Entity::insert(meta::ActiveModel {
|
||||
id: ActiveValue::Set("x".to_owned()),
|
||||
..Default::default()
|
||||
})
|
||||
.exec_with_returning(db)
|
||||
.await?;
|
||||
update_cache(&meta);
|
||||
Ok(meta)
|
||||
}
|
||||
|
||||
#[crate::export(object)]
|
||||
pub struct PugArgs {
|
||||
pub img: Option<String>,
|
||||
pub title: String,
|
||||
pub instance_name: String,
|
||||
pub desc: Option<String>,
|
||||
pub icon: Option<String>,
|
||||
pub splash_icon: Option<String>,
|
||||
pub theme_color: Option<String>,
|
||||
pub random_motd: String,
|
||||
pub private_mode: Option<bool>,
|
||||
}
|
||||
|
||||
#[crate::export]
|
||||
pub fn meta_to_pug_args(meta: Meta) -> PugArgs {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let splash_icon = meta
|
||||
.custom_splash_icons
|
||||
.choose(&mut rng)
|
||||
.map(|s| s.to_owned())
|
||||
.or_else(|| meta.icon_url.to_owned());
|
||||
|
||||
let random_motd = meta
|
||||
.custom_motd
|
||||
.choose(&mut rng)
|
||||
.map(|s| s.to_owned())
|
||||
.unwrap_or_else(|| "Loading...".to_owned());
|
||||
|
||||
let name = meta.name.unwrap_or_else(|| "Firefish".to_owned());
|
||||
PugArgs {
|
||||
img: meta.banner_url,
|
||||
title: name.clone(),
|
||||
instance_name: name.clone(),
|
||||
desc: meta.description,
|
||||
icon: meta.icon_url,
|
||||
splash_icon,
|
||||
theme_color: meta.theme_color,
|
||||
random_motd,
|
||||
private_mode: meta.private_mode,
|
||||
}
|
||||
}
|
|
@ -3,5 +3,6 @@ pub mod check_word_mute;
|
|||
pub mod convert_host;
|
||||
pub mod format_milliseconds;
|
||||
pub mod mastodon_id;
|
||||
pub mod meta;
|
||||
pub mod nyaify;
|
||||
pub mod password;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import si from "systeminformation";
|
||||
import Xev from "xev";
|
||||
import * as osUtils from "os-utils";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
|
@ -20,7 +20,7 @@ export default function () {
|
|||
ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length || 50));
|
||||
});
|
||||
|
||||
fetchMeta().then((meta) => {
|
||||
fetchMeta(true).then((meta) => {
|
||||
if (!meta.enableServerMachineStats) return;
|
||||
});
|
||||
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
import { db } from "@/db/postgre.js";
|
||||
import { Meta } from "@/models/entities/meta.js";
|
||||
|
||||
let cache: Meta;
|
||||
|
||||
export function metaToPugArgs(meta: Meta): object {
|
||||
let motd = ["Loading..."];
|
||||
if (meta.customMotd.length > 0) {
|
||||
motd = meta.customMotd;
|
||||
}
|
||||
let splashIconUrl = meta.iconUrl;
|
||||
if (meta.customSplashIcons.length > 0) {
|
||||
splashIconUrl =
|
||||
meta.customSplashIcons[
|
||||
Math.floor(Math.random() * meta.customSplashIcons.length)
|
||||
];
|
||||
}
|
||||
|
||||
return {
|
||||
img: meta.bannerUrl,
|
||||
title: meta.name || "Firefish",
|
||||
instanceName: meta.name || "Firefish",
|
||||
desc: meta.description,
|
||||
icon: meta.iconUrl,
|
||||
splashIcon: splashIconUrl,
|
||||
themeColor: meta.themeColor,
|
||||
randomMOTD: motd[Math.floor(Math.random() * motd.length)],
|
||||
privateMode: meta.privateMode,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchMeta(noCache = false): Promise<Meta> {
|
||||
if (!noCache && cache) return cache;
|
||||
|
||||
return await db.transaction(async (transactionalEntityManager) => {
|
||||
// New IDs are prioritized because multiple records may have been created due to past bugs.
|
||||
const metas = await transactionalEntityManager.find(Meta, {
|
||||
order: {
|
||||
id: "DESC",
|
||||
},
|
||||
});
|
||||
|
||||
const meta = metas[0];
|
||||
|
||||
if (meta) {
|
||||
cache = meta;
|
||||
return meta;
|
||||
} else {
|
||||
// If fetchMeta is called at the same time when meta is empty, this part may be called at the same time, so use fail-safe upsert.
|
||||
const saved = await transactionalEntityManager
|
||||
.upsert(
|
||||
Meta,
|
||||
{
|
||||
id: "x",
|
||||
},
|
||||
["id"],
|
||||
)
|
||||
.then((x) =>
|
||||
transactionalEntityManager.findOneByOrFail(Meta, x.identifiers[0]),
|
||||
);
|
||||
|
||||
cache = saved;
|
||||
return saved;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
fetchMeta(true).then((meta) => {
|
||||
cache = meta;
|
||||
});
|
||||
}, 1000 * 10);
|
|
@ -1,9 +1,9 @@
|
|||
import { fetchMeta } from "./fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import type { ILocalUser } from "@/models/entities/user.js";
|
||||
import { Users } from "@/models/index.js";
|
||||
|
||||
export async function fetchProxyAccount(): Promise<ILocalUser | null> {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.proxyAccountId == null) return null;
|
||||
return (await Users.findOneByOrFail({
|
||||
id: meta.proxyAccountId,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { emojiRegex } from "./emoji-regex.js";
|
||||
import { fetchMeta } from "./fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Emojis } from "@/models/index.js";
|
||||
import { toPuny } from "backend-rs";
|
||||
import { IsNull } from "typeorm";
|
||||
|
@ -21,7 +21,7 @@ export async function toDbReaction(
|
|||
reaction?: string | null,
|
||||
reacterHost?: string | null,
|
||||
): Promise<string> {
|
||||
if (!reaction) return (await fetchMeta()).defaultReaction;
|
||||
if (!reaction) return (await fetchMeta(true)).defaultReaction;
|
||||
|
||||
reacterHost = reacterHost == null ? null : toPuny(reacterHost);
|
||||
|
||||
|
@ -45,7 +45,7 @@ export async function toDbReaction(
|
|||
if (emoji) return reacterHost ? `:${name}@${reacterHost}:` : `:${name}:`;
|
||||
}
|
||||
|
||||
return (await fetchMeta()).defaultReaction;
|
||||
return (await fetchMeta(true)).defaultReaction;
|
||||
}
|
||||
|
||||
type DecodedReaction = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import type { Instance } from "@/models/entities/instance.js";
|
||||
import type { Meta } from "@/models/entities/meta.js";
|
||||
|
||||
|
@ -13,7 +13,7 @@ export async function shouldBlockInstance(
|
|||
host: Instance["host"],
|
||||
meta?: Meta,
|
||||
): Promise<boolean> {
|
||||
const { blockedHosts } = meta ?? (await fetchMeta());
|
||||
const { blockedHosts } = meta ?? (await fetchMeta(true));
|
||||
return blockedHosts.some(
|
||||
(blockedHost) => host === blockedHost || host.endsWith(`.${blockedHost}`),
|
||||
);
|
||||
|
@ -30,7 +30,7 @@ export async function shouldSilenceInstance(
|
|||
host: Instance["host"],
|
||||
meta?: Meta,
|
||||
): Promise<boolean> {
|
||||
const { silencedHosts } = meta ?? (await fetchMeta());
|
||||
const { silencedHosts } = meta ?? (await fetchMeta(true));
|
||||
return silencedHosts.some(
|
||||
(silencedHost) =>
|
||||
host === silencedHost || host.endsWith(`.${silencedHost}`),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Brackets } from "typeorm";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Instances } from "@/models/index.js";
|
||||
import type { Instance } from "@/models/entities/instance.js";
|
||||
import { DAY } from "@/const.js";
|
||||
|
@ -19,7 +19,7 @@ export async function skippedInstances(
|
|||
hosts: Instance["host"][],
|
||||
): Promise<Instance["host"][]> {
|
||||
// first check for blocked instances since that info may already be in memory
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const shouldSkip = await Promise.all(
|
||||
hosts.map((host) => shouldBlockInstance(host, meta)),
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import fetch from "node-fetch";
|
||||
import { Converter } from "opencc-js";
|
||||
import { getAgentByUrl } from "@/misc/fetch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import type { PostLanguage } from "@/misc/langmap";
|
||||
import * as deepl from "deepl-node";
|
||||
|
||||
|
@ -26,7 +26,7 @@ export async function translate(
|
|||
from: PostLanguage | null,
|
||||
to: PostLanguage,
|
||||
) {
|
||||
const instance = await fetchMeta();
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
if (instance.deeplAuthKey == null && instance.libreTranslateApiUrl == null) {
|
||||
throw Error("No translator is set up on this server.");
|
||||
|
|
|
@ -5,7 +5,7 @@ import perform from "@/remote/activitypub/perform.js";
|
|||
import Logger from "@/services/logger.js";
|
||||
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
||||
import { Instances } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { toPuny, extractHost } from "backend-rs";
|
||||
import { getApId } from "@/remote/activitypub/type.js";
|
||||
import { fetchInstanceMetadata } from "@/services/fetch-instance-metadata.js";
|
||||
|
@ -41,7 +41,7 @@ export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
|
|||
const host = toPuny(new URL(signature.keyId).hostname);
|
||||
|
||||
// interrupt if blocked
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (await shouldBlockInstance(host, meta)) {
|
||||
return `Blocked request: ${host}`;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { URL } from "url";
|
||||
import httpSignature, { IParsedSignature } from "@peertube/http-signature";
|
||||
import config from "@/config/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { toPuny } from "backend-rs";
|
||||
import DbResolver from "@/remote/activitypub/db-resolver.js";
|
||||
import { getApId } from "@/remote/activitypub/type.js";
|
||||
|
@ -12,7 +12,7 @@ import type { UserPublickey } from "@/models/entities/user-publickey.js";
|
|||
import { verify } from "node:crypto";
|
||||
|
||||
export async function hasSignature(req: IncomingMessage): Promise<string> {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const required = meta.secureMode || meta.privateMode;
|
||||
|
||||
try {
|
||||
|
@ -27,7 +27,7 @@ export async function hasSignature(req: IncomingMessage): Promise<string> {
|
|||
}
|
||||
|
||||
export async function checkFetch(req: IncomingMessage): Promise<number> {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
if (req.headers.host !== config.host) return 400;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { uploadFromUrl } from "@/services/drive/upload-from-url.js";
|
||||
import type { CacheableRemoteUser } from "@/models/entities/user.js";
|
||||
import Resolver from "../resolver.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { apLogger } from "../logger.js";
|
||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||
import { DriveFiles } from "@/models/index.js";
|
||||
|
@ -34,7 +34,7 @@ export async function createImage(
|
|||
|
||||
logger.info(`Creating the Image: ${image.url}`);
|
||||
|
||||
const instance = await fetchMeta();
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
let file = await uploadFromUrl({
|
||||
url: image.url,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import config from "@/config/index.js";
|
||||
import type { ILocalUser } from "@/models/entities/user.js";
|
||||
import { getInstanceActor } from "@/services/instance-actor.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { extractHost, isSelfHost } from "backend-rs";
|
||||
import { apGet } from "./request.js";
|
||||
import type { IObject, ICollection, IOrderedCollection } from "./type.js";
|
||||
|
@ -100,7 +100,7 @@ export default class Resolver {
|
|||
return await this.resolveLocal(value);
|
||||
}
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (await shouldBlockInstance(host, meta)) {
|
||||
throw new Error("Instance is blocked");
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import renderKey from "@/remote/activitypub/renderer/key.js";
|
|||
import { renderPerson } from "@/remote/activitypub/renderer/person.js";
|
||||
import renderEmoji from "@/remote/activitypub/renderer/emoji.js";
|
||||
import { inbox as processInbox } from "@/queue/index.js";
|
||||
import { isSelfHost } from "backend-rs";
|
||||
import { fetchMeta, isSelfHost } from "backend-rs";
|
||||
import {
|
||||
Notes,
|
||||
Users,
|
||||
|
@ -25,7 +25,6 @@ import {
|
|||
getSignatureUser,
|
||||
} from "@/remote/activitypub/check-fetch.js";
|
||||
import { getInstanceActor } from "@/services/instance-actor.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import renderFollow from "@/remote/activitypub/renderer/follow.js";
|
||||
import Featured from "./activitypub/featured.js";
|
||||
import Following from "./activitypub/following.js";
|
||||
|
@ -238,7 +237,7 @@ router.get("/notes/:note", async (ctx, next) => {
|
|||
|
||||
ctx.body = renderActivity(await renderNote(note, false));
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -268,7 +267,7 @@ router.get("/notes/:note/activity", async (ctx) => {
|
|||
}
|
||||
|
||||
ctx.body = renderActivity(await packActivity(note));
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -323,7 +322,7 @@ router.get("/users/:user/publickey", async (ctx) => {
|
|||
|
||||
if (Users.isLocalUser(user)) {
|
||||
ctx.body = renderActivity(renderKey(user, keypair));
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -343,7 +342,7 @@ async function userInfo(ctx: Router.RouterContext, user: User | null) {
|
|||
}
|
||||
|
||||
ctx.body = renderActivity(await renderPerson(user as ILocalUser));
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -426,8 +425,8 @@ router.get("/emojis/:emoji", async (ctx) => {
|
|||
return;
|
||||
}
|
||||
|
||||
ctx.body = renderActivity(await renderEmoji(emoji));
|
||||
const meta = await fetchMeta();
|
||||
ctx.body = renderActivity(renderEmoji(emoji));
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -459,7 +458,7 @@ router.get("/likes/:like", async (ctx) => {
|
|||
}
|
||||
|
||||
ctx.body = renderActivity(await renderLike(reaction, note));
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -497,7 +496,7 @@ router.get(
|
|||
}
|
||||
|
||||
ctx.body = renderActivity(renderFollow(follower, followee));
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
@ -540,7 +539,7 @@ router.get("/follows/:followRequestId", async (ctx: Router.RouterContext) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
|
|
@ -5,7 +5,7 @@ import renderOrderedCollection from "@/remote/activitypub/renderer/ordered-colle
|
|||
import renderNote from "@/remote/activitypub/renderer/note.js";
|
||||
import { Users, Notes, UserNotePinings } from "@/models/index.js";
|
||||
import { checkFetch } from "@/remote/activitypub/check-fetch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { setResponseType } from "../activitypub.js";
|
||||
import type Router from "@koa/router";
|
||||
|
||||
|
@ -57,7 +57,7 @@ export default async (ctx: Router.RouterContext) => {
|
|||
|
||||
ctx.body = renderActivity(rendered);
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ import renderFollowUser from "@/remote/activitypub/renderer/follow-user.js";
|
|||
import { Users, Followings, UserProfiles } from "@/models/index.js";
|
||||
import type { Following } from "@/models/entities/following.js";
|
||||
import { checkFetch } from "@/remote/activitypub/check-fetch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { setResponseType } from "../activitypub.js";
|
||||
import type { FindOptionsWhere } from "typeorm";
|
||||
import type Router from "@koa/router";
|
||||
|
@ -110,7 +110,7 @@ export default async (ctx: Router.RouterContext) => {
|
|||
ctx.body = renderActivity(rendered);
|
||||
setResponseType(ctx);
|
||||
}
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ import renderFollowUser from "@/remote/activitypub/renderer/follow-user.js";
|
|||
import { Users, Followings, UserProfiles } from "@/models/index.js";
|
||||
import type { Following } from "@/models/entities/following.js";
|
||||
import { checkFetch } from "@/remote/activitypub/check-fetch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { setResponseType } from "../activitypub.js";
|
||||
import type { FindOptionsWhere } from "typeorm";
|
||||
import type Router from "@koa/router";
|
||||
|
@ -110,7 +110,7 @@ export default async (ctx: Router.RouterContext) => {
|
|||
ctx.body = renderActivity(rendered);
|
||||
setResponseType(ctx);
|
||||
}
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,7 @@ import * as url from "@/prelude/url.js";
|
|||
import { Users, Notes } from "@/models/index.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { checkFetch } from "@/remote/activitypub/check-fetch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { makePaginationQuery } from "../api/common/make-pagination-query.js";
|
||||
import { setResponseType } from "../activitypub.js";
|
||||
import type Router from "@koa/router";
|
||||
|
@ -117,7 +117,7 @@ export default async (ctx: Router.RouterContext) => {
|
|||
|
||||
setResponseType(ctx);
|
||||
}
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.secureMode || meta.privateMode) {
|
||||
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,7 @@ import type Koa from "koa";
|
|||
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import { UserIps } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import type { IEndpoint } from "./endpoints.js";
|
||||
import authenticate, { AuthenticationError } from "./authenticate.js";
|
||||
import call from "./call.js";
|
||||
|
@ -84,7 +84,7 @@ export default (endpoint: IEndpoint, ctx: Koa.Context) =>
|
|||
|
||||
// Log IP
|
||||
if (user) {
|
||||
fetchMeta().then((meta) => {
|
||||
fetchMeta(true).then((meta) => {
|
||||
if (!meta.enableIpLogging) return;
|
||||
const ip = ctx.ip;
|
||||
const ips = userIpHistories.get(user.id);
|
||||
|
|
|
@ -10,7 +10,7 @@ import endpoints from "./endpoints.js";
|
|||
import compatibility from "./compatibility.js";
|
||||
import { ApiError } from "./error.js";
|
||||
import { apiLogger } from "./logger.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
|
||||
const accessDenied = {
|
||||
message: "Access denied.",
|
||||
|
@ -117,7 +117,7 @@ export default async (
|
|||
}
|
||||
|
||||
// private mode
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (
|
||||
meta.privateMode &&
|
||||
ep.meta.requireCredentialPrivateMode &&
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import config from "@/config/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { MAX_NOTE_TEXT_LENGTH, MAX_CAPTION_TEXT_LENGTH } from "@/const.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
|
@ -466,7 +466,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async () => {
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
|
||||
return {
|
||||
maintainerName: instance.maintainerName,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// import { IsNull } from 'typeorm';
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
export const meta = {
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async () => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const motd = await Promise.all(meta.customMotd.map((x) => x));
|
||||
return motd;
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// import { IsNull } from 'typeorm';
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
export const meta = {
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async () => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const icons = await Promise.all(meta.customSplashIcons.map((x) => x));
|
||||
return icons;
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { DriveFiles } from "@/models/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
|
@ -35,7 +35,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
|
||||
// Calculate drive usage
|
||||
const usage = await DriveFiles.calcDriveUsageOf(user.id);
|
||||
|
|
|
@ -2,7 +2,7 @@ import { addFile } from "@/services/drive/add-file.js";
|
|||
import { DriveFiles } from "@/models/index.js";
|
||||
import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
|
||||
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { MINUTE } from "@/const.js";
|
||||
import define from "@/server/api/define.js";
|
||||
import { apiLogger } from "@/server/api/logger.js";
|
||||
|
@ -96,7 +96,7 @@ export default define(
|
|||
name = null;
|
||||
}
|
||||
|
||||
const instanceMeta = await fetchMeta();
|
||||
const instanceMeta = await fetchMeta(true);
|
||||
|
||||
try {
|
||||
// Create file
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { Instances } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { sqlLikeEscape } from "@/misc/sql-like-escape.js";
|
||||
|
||||
export const meta = {
|
||||
|
@ -101,7 +101,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
}
|
||||
|
||||
if (typeof ps.blocked === "boolean") {
|
||||
const meta = await fetchMeta(true);
|
||||
const meta = await fetchMeta(false);
|
||||
if (ps.blocked) {
|
||||
if (meta.blockedHosts.length === 0) {
|
||||
return [];
|
||||
|
@ -117,7 +117,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
}
|
||||
|
||||
if (typeof ps.silenced === "boolean") {
|
||||
const meta = await fetchMeta(true);
|
||||
const meta = await fetchMeta(false);
|
||||
if (ps.silenced) {
|
||||
if (meta.silencedHosts.length === 0) {
|
||||
return [];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Brackets } from "typeorm";
|
||||
import define from "@/server/api/define.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Notes } from "@/models/index.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { safeForSql } from "@/misc/safe-for-sql.js";
|
||||
|
@ -67,7 +67,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async () => {
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
const hiddenTags = instance.hiddenTags.map((t) => normalizeForSearch(t));
|
||||
|
||||
const now = new Date(); // 5分単位で丸めた現在日時
|
||||
|
|
|
@ -3,7 +3,7 @@ import { createImportPostsJob } from "@/queue/index.js";
|
|||
import { ApiError } from "@/server/api/error.js";
|
||||
import { DriveFiles } from "@/models/index.js";
|
||||
import { DAY } from "@/const.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
secure: true,
|
||||
|
@ -45,7 +45,7 @@ export const paramDef = {
|
|||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const file = await DriveFiles.findOneBy({ id: ps.fileId });
|
||||
|
||||
const instanceMeta = await fetchMeta();
|
||||
const instanceMeta = await fetchMeta(true);
|
||||
if (instanceMeta.experimentalFeatures?.postImports === false)
|
||||
throw new ApiError(meta.errors.importsDisabled);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import JSON5 from "json5";
|
||||
import { IsNull, MoreThan } from "typeorm";
|
||||
import config from "@/config/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Ads, Emojis, Users } from "@/models/index.js";
|
||||
import { MAX_NOTE_TEXT_LENGTH, MAX_CAPTION_TEXT_LENGTH } from "@/const.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -398,7 +398,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
|
||||
const emojis = await Emojis.find({
|
||||
where: {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Notes } from "@/models/index.js";
|
||||
import { activeUsersChart } from "@/services/chart/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -64,7 +64,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
const m = await fetchMeta(true);
|
||||
if (m.disableGlobalTimeline) {
|
||||
if (user == null || !(user.isAdmin || user.isModerator)) {
|
||||
throw new ApiError(meta.errors.gtlDisabled);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Brackets } from "typeorm";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Followings, Notes } from "@/models/index.js";
|
||||
import { activeUsersChart } from "@/services/chart/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -71,7 +71,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
const m = await fetchMeta(true);
|
||||
if (m.disableLocalTimeline && !user.isAdmin && !user.isModerator) {
|
||||
throw new ApiError(meta.errors.stlDisabled);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Brackets } from "typeorm";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Notes } from "@/models/index.js";
|
||||
import { activeUsersChart } from "@/services/chart/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -74,7 +74,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
const m = await fetchMeta(true);
|
||||
if (m.disableLocalTimeline) {
|
||||
if (user == null || !(user.isAdmin || user.isModerator)) {
|
||||
throw new ApiError(meta.errors.ltlDisabled);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Brackets } from "typeorm";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Notes } from "@/models/index.js";
|
||||
import { activeUsersChart } from "@/services/chart/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -74,7 +74,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const m = await fetchMeta();
|
||||
const m = await fetchMeta(true);
|
||||
if (m.disableRecommendedTimeline) {
|
||||
if (user == null || !(user.isAdmin || user.isModerator)) {
|
||||
throw new ApiError(meta.errors.rtlDisabled);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { IsNull } from "typeorm";
|
||||
import { Users } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { stringToAcct } from "backend-rs";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -31,7 +31,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
const users = await Promise.all(
|
||||
meta.pinnedUsers
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// import { IsNull } from 'typeorm';
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
export const meta = {
|
||||
|
@ -27,7 +27,7 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async () => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const instances = await Promise.all(meta.recommendedInstances.map((x) => x));
|
||||
return instances;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as os from "node:os";
|
||||
import si from "systeminformation";
|
||||
import define from "@/server/api/define.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
|
@ -30,7 +30,7 @@ export default define(meta, paramDef, async () => {
|
|||
}
|
||||
}
|
||||
|
||||
const instanceMeta = await fetchMeta();
|
||||
const instanceMeta = await fetchMeta(true);
|
||||
if (!instanceMeta.enableServerMachineStats) {
|
||||
return {
|
||||
machine: "Not specified",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { genId } from "backend-rs";
|
||||
import { SwSubscriptions } from "@/models/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -64,7 +64,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
publickey: ps.publickey,
|
||||
});
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
|
||||
// if already subscribed
|
||||
if (subscription != null) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { publishAdminStream } from "@/services/stream.js";
|
|||
import { AbuseUserReports, UserProfiles, Users } from "@/models/index.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { sendEmail } from "@/services/send-email.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { getUser } from "@/server/api/common/getters.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
@ -86,7 +86,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
],
|
||||
});
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
for (const moderator of moderators) {
|
||||
publishAdminStream(moderator.id, "newAbuseUserReport", {
|
||||
id: report.id,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Entity } from "megalodon";
|
||||
import config from "@/config/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Users, Notes } from "@/models/index.js";
|
||||
import { IsNull } from "typeorm";
|
||||
import { MAX_NOTE_TEXT_LENGTH, FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
||||
|
@ -10,7 +10,7 @@ export async function getInstance(
|
|||
contact: Entity.Account,
|
||||
) {
|
||||
const [meta, totalUsers, totalStatuses] = await Promise.all([
|
||||
fetchMeta(),
|
||||
fetchMeta(true),
|
||||
Users.count({ where: { host: IsNull() } }),
|
||||
Notes.count({ where: { userHost: IsNull() } }),
|
||||
]);
|
||||
|
|
|
@ -4,14 +4,13 @@ import { emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js";
|
|||
import querystring from "node:querystring";
|
||||
import qs from "qs";
|
||||
import { convertTimelinesArgsId, limitToInt } from "./timeline.js";
|
||||
import { fromMastodonId } from "backend-rs";
|
||||
import { fetchMeta, fromMastodonId } from "backend-rs";
|
||||
import {
|
||||
convertAccount,
|
||||
convertAttachment,
|
||||
convertPoll,
|
||||
convertStatus,
|
||||
} from "../converters.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { apiLogger } from "@/server/api/logger.js";
|
||||
import { inspect } from "node:util";
|
||||
|
||||
|
@ -213,7 +212,7 @@ export function apiStatusMastodon(router: Router): void {
|
|||
router.post<{ Params: { id: string } }>(
|
||||
"/v1/statuses/:id/favourite",
|
||||
async (ctx) => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
||||
const accessTokens = ctx.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
|
@ -235,7 +234,7 @@ export function apiStatusMastodon(router: Router): void {
|
|||
router.post<{ Params: { id: string } }>(
|
||||
"/v1/statuses/:id/unfavourite",
|
||||
async (ctx) => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
||||
const accessTokens = ctx.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
import type Koa from "koa";
|
||||
import rndstr from "rndstr";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { verifyHcaptcha, verifyRecaptcha } from "@/misc/captcha.js";
|
||||
import { Users, RegistrationTickets, UserPendings } from "@/models/index.js";
|
||||
import { signup } from "@/server/api/common/signup.js";
|
||||
import config from "@/config/index.js";
|
||||
import { sendEmail } from "@/services/send-email.js";
|
||||
import { genId, hashPassword } from "backend-rs";
|
||||
import { fetchMeta, genId, hashPassword } from "backend-rs";
|
||||
import { validateEmailForAccount } from "@/services/validate-email-for-account.js";
|
||||
|
||||
export default async (ctx: Koa.Context) => {
|
||||
const body = ctx.request.body;
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
|
||||
// Verify *Captcha
|
||||
// ただしテスト時はこの機構は障害となるため無効にする
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import Channel from "../channel.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { checkWordMute } from "backend-rs";
|
||||
import { checkWordMute, fetchMeta } from "backend-rs";
|
||||
import { isInstanceMuted } from "@/misc/is-instance-muted.js";
|
||||
import { isUserRelated } from "@/misc/is-user-related.js";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
|
@ -17,7 +16,7 @@ export default class extends Channel {
|
|||
}
|
||||
|
||||
public async init(params: any) {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.disableGlobalTimeline) {
|
||||
if (this.user == null || !(this.user.isAdmin || this.user.isModerator))
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import Channel from "../channel.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { checkWordMute } from "backend-rs";
|
||||
import { checkWordMute, fetchMeta } from "backend-rs";
|
||||
import { isUserRelated } from "@/misc/is-user-related.js";
|
||||
import { isInstanceMuted } from "@/misc/is-instance-muted.js";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
|
@ -17,7 +16,7 @@ export default class extends Channel {
|
|||
}
|
||||
|
||||
public async init(params: any) {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (
|
||||
meta.disableLocalTimeline &&
|
||||
!this.user!.isAdmin &&
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import Channel from "../channel.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { checkWordMute } from "backend-rs";
|
||||
import { checkWordMute, fetchMeta } from "backend-rs";
|
||||
import { isUserRelated } from "@/misc/is-user-related.js";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
|
||||
|
@ -16,7 +15,7 @@ export default class extends Channel {
|
|||
}
|
||||
|
||||
public async init(params: any) {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.disableLocalTimeline) {
|
||||
if (this.user == null || !(this.user.isAdmin || this.user.isModerator))
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import Channel from "../channel.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { checkWordMute } from "backend-rs";
|
||||
import { checkWordMute, fetchMeta } from "backend-rs";
|
||||
import { isUserRelated } from "@/misc/is-user-related.js";
|
||||
import { isInstanceMuted } from "@/misc/is-instance-muted.js";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
|
@ -17,7 +16,7 @@ export default class extends Channel {
|
|||
}
|
||||
|
||||
public async init(params: any) {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (
|
||||
meta.disableRecommendedTimeline &&
|
||||
!this.user!.isAdmin &&
|
||||
|
@ -37,7 +36,7 @@ export default class extends Channel {
|
|||
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または
|
||||
// チャンネルの投稿ではなく、全体公開のローカルの投稿 または
|
||||
// フォローしているチャンネルの投稿 の場合だけ
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (
|
||||
!(
|
||||
note.user.host != null &&
|
||||
|
|
|
@ -16,7 +16,7 @@ import { IsNull } from "typeorm";
|
|||
import config from "@/config/index.js";
|
||||
import Logger from "@/services/logger.js";
|
||||
import { Users } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { genIdenticon } from "@/misc/gen-identicon.js";
|
||||
import { createTemp } from "@/misc/create-temp.js";
|
||||
import { stringToAcct } from "backend-rs";
|
||||
|
@ -126,7 +126,7 @@ router.get("/avatar/@:acct", async (ctx) => {
|
|||
});
|
||||
|
||||
router.get("/identicon/:x", async (ctx) => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.enableIdenticonGeneration) {
|
||||
const [temp, cleanup] = await createTemp();
|
||||
await genIdenticon(ctx.params.x, fs.createWriteStream(temp));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Router from "@koa/router";
|
||||
import config from "@/config/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { Users, Notes } from "@/models/index.js";
|
||||
import { IsNull, MoreThan } from "typeorm";
|
||||
import { MAX_NOTE_TEXT_LENGTH, MAX_CAPTION_TEXT_LENGTH } from "@/const.js";
|
||||
|
@ -27,7 +27,7 @@ const nodeinfo2 = async () => {
|
|||
const now = Date.now();
|
||||
const [meta, total, activeHalfyear, activeMonth, localPosts] =
|
||||
await Promise.all([
|
||||
fetchMeta(true),
|
||||
fetchMeta(false),
|
||||
Users.count({ where: { host: IsNull() } }),
|
||||
Users.count({
|
||||
where: {
|
||||
|
|
|
@ -10,13 +10,12 @@ import Router from "@koa/router";
|
|||
import send from "koa-send";
|
||||
import favicon from "koa-favicon";
|
||||
import views from "@ladjs/koa-views";
|
||||
import sharp from "sharp";
|
||||
import { createBullBoard } from "@bull-board/api";
|
||||
import { BullAdapter } from "@bull-board/api/bullAdapter.js";
|
||||
import { KoaAdapter } from "@bull-board/koa";
|
||||
|
||||
import { In, IsNull } from "typeorm";
|
||||
import { fetchMeta, metaToPugArgs } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta, metaToPugArgs } from "backend-rs";
|
||||
import config from "@/config/index.js";
|
||||
import {
|
||||
Users,
|
||||
|
@ -326,7 +325,7 @@ const getFeed = async (
|
|||
noRenotes: string,
|
||||
noReplies: string,
|
||||
) => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
if (meta.privateMode) {
|
||||
return;
|
||||
}
|
||||
|
@ -475,7 +474,7 @@ const userPage: Router.Middleware = async (ctx, next) => {
|
|||
}
|
||||
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
const me = profile.fields
|
||||
? profile.fields
|
||||
.filter((filed) => filed.value?.match(/^https?:/))
|
||||
|
@ -524,7 +523,7 @@ router.get("/notes/:note", async (ctx, next) => {
|
|||
const profile = await UserProfiles.findOneByOrFail({
|
||||
userId: note.userId,
|
||||
});
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
await ctx.render("note", {
|
||||
...metaToPugArgs(meta),
|
||||
note: _note,
|
||||
|
@ -558,7 +557,7 @@ router.get("/posts/:note", async (ctx, next) => {
|
|||
if (note) {
|
||||
const _note = await Notes.pack(note);
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
await ctx.render("note", {
|
||||
...metaToPugArgs(meta),
|
||||
note: _note,
|
||||
|
@ -596,7 +595,7 @@ router.get("/@:user/pages/:page", async (ctx, next) => {
|
|||
if (page) {
|
||||
const _page = await Pages.pack(page);
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: page.userId });
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
await ctx.render("page", {
|
||||
...metaToPugArgs(meta),
|
||||
page: _page,
|
||||
|
@ -628,7 +627,7 @@ router.get("/clips/:clip", async (ctx, next) => {
|
|||
if (clip) {
|
||||
const _clip = await Clips.pack(clip);
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: clip.userId });
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
await ctx.render("clip", {
|
||||
...metaToPugArgs(meta),
|
||||
clip: _clip,
|
||||
|
@ -653,7 +652,7 @@ router.get("/gallery/:post", async (ctx, next) => {
|
|||
if (post) {
|
||||
const _post = await GalleryPosts.pack(post);
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: post.userId });
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
await ctx.render("gallery-post", {
|
||||
...metaToPugArgs(meta),
|
||||
post: _post,
|
||||
|
@ -679,7 +678,7 @@ router.get("/channels/:channel", async (ctx, next) => {
|
|||
|
||||
if (channel) {
|
||||
const _channel = await Channels.pack(channel);
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
await ctx.render("channel", {
|
||||
...metaToPugArgs(meta),
|
||||
channel: _channel,
|
||||
|
@ -732,7 +731,7 @@ router.get("/api/v1/streaming", async (ctx) => {
|
|||
|
||||
// Render base html for all requests
|
||||
router.get("(.*)", async (ctx) => {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
await ctx.render("base", {
|
||||
...metaToPugArgs(meta),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type Koa from "koa";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import config from "@/config/index.js";
|
||||
import manifest from "./manifest.json" assert { type: "json" };
|
||||
|
||||
|
@ -8,7 +8,7 @@ export const manifestHandler = async (ctx: Koa.Context) => {
|
|||
//const res = structuredClone(manifest);
|
||||
const res = JSON.parse(JSON.stringify(manifest));
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
const instance = await fetchMeta(false);
|
||||
|
||||
res.short_name = instance.name || "Firefish";
|
||||
res.name = instance.name || "Firefish";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type Koa from "koa";
|
||||
import summaly from "summaly";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import Logger from "@/services/logger.js";
|
||||
import config from "@/config/index.js";
|
||||
import { query } from "@/prelude/url.js";
|
||||
|
@ -22,7 +22,7 @@ export const urlPreviewHandler = async (ctx: Koa.Context) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
logger.info(
|
||||
meta.summalyProxy
|
||||
|
|
|
@ -6,7 +6,7 @@ import type S3 from "aws-sdk/clients/s3.js"; // TODO: migrate to SDK v3
|
|||
import sharp from "sharp";
|
||||
import { IsNull } from "typeorm";
|
||||
import { publishMainStream, publishDriveStream } from "@/services/stream.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { contentDisposition } from "@/misc/content-disposition.js";
|
||||
import { getFileInfo } from "@/misc/get-file-info.js";
|
||||
import {
|
||||
|
@ -77,7 +77,7 @@ async function save(
|
|||
// thunbnail, webpublic を必要なら生成
|
||||
const alts = await generateAlts(path, type, !file.uri);
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
if (meta.useObjectStorage) {
|
||||
//#region ObjectStorage params
|
||||
|
@ -360,7 +360,7 @@ async function upload(
|
|||
if (type === "image/apng") type = "image/png";
|
||||
if (!FILE_TYPE_BROWSERSAFE.includes(type)) type = "application/octet-stream";
|
||||
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
const params = {
|
||||
Bucket: meta.objectStorageBucket,
|
||||
|
@ -495,7 +495,7 @@ export async function addFile({
|
|||
const usage = await DriveFiles.calcDriveUsageOf(user);
|
||||
const u = await Users.findOneBy({ id: user.id });
|
||||
|
||||
const instance = await fetchMeta();
|
||||
const instance = await fetchMeta(true);
|
||||
let driveCapacity =
|
||||
1024 *
|
||||
1024 *
|
||||
|
@ -567,7 +567,7 @@ export async function addFile({
|
|||
: null;
|
||||
|
||||
const folder = await fetchFolder();
|
||||
const instance = await fetchMeta();
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
let file = new DriveFile();
|
||||
file.id = genId();
|
||||
|
|
|
@ -2,7 +2,7 @@ import type { DriveFile } from "@/models/entities/drive-file.js";
|
|||
import { InternalStorage } from "./internal-storage.js";
|
||||
import { DriveFiles } from "@/models/index.js";
|
||||
import { createDeleteObjectStorageFileJob } from "@/queue/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import { getS3 } from "./s3.js";
|
||||
import { v4 as uuid } from "uuid";
|
||||
|
||||
|
@ -82,7 +82,7 @@ async function postProcess(file: DriveFile, isExpired = false) {
|
|||
}
|
||||
|
||||
export async function deleteObjectStorageFile(key: string) {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
const s3 = getS3(meta);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import push from "web-push";
|
||||
import config from "@/config/index.js";
|
||||
import { SwSubscriptions } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
import { getNoteSummary } from "@/misc/get-note-summary.js";
|
||||
|
||||
|
@ -45,7 +45,7 @@ export async function pushNotification<T extends keyof pushNotificationsTypes>(
|
|||
type: T,
|
||||
body: pushNotificationsTypes[T],
|
||||
) {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
if (
|
||||
!meta.enableServiceWorker ||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as nodemailer from "nodemailer";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
import Logger from "@/services/logger.js";
|
||||
import config from "@/config/index.js";
|
||||
import { inspect } from "node:util";
|
||||
|
@ -12,7 +12,7 @@ export async function sendEmail(
|
|||
html: string,
|
||||
text: string,
|
||||
) {
|
||||
const meta = await fetchMeta(true);
|
||||
const meta = await fetchMeta(false);
|
||||
|
||||
const iconUrl = `${config.url}/static-assets/mi-white.png`;
|
||||
const emailSettingUrl = `${config.url}/settings/email`;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { validate as validateEmail } from "deep-email-validator";
|
||||
import { UserProfiles } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { fetchMeta } from "backend-rs";
|
||||
|
||||
export async function validateEmailForAccount(emailAddress: string): Promise<{
|
||||
available: boolean;
|
||||
reason: null | "used" | "format" | "disposable" | "mx" | "smtp";
|
||||
}> {
|
||||
const meta = await fetchMeta();
|
||||
const meta = await fetchMeta(true);
|
||||
|
||||
const exist = await UserProfiles.countBy({
|
||||
emailVerified: true,
|
||||
|
|
Loading…
Reference in a new issue