firefish/packages/backend/src/server/api/endpoints/meta.ts

541 lines
12 KiB
TypeScript
Raw Normal View History

import JSON5 from "json5";
import { IsNull, MoreThan } from "typeorm";
2023-01-13 04:40:33 +00:00
import config from "@/config/index.js";
import { fetchMeta } from "backend-rs";
2023-01-13 04:40:33 +00:00
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";
2016-12-28 22:49:51 +00:00
2018-10-08 16:01:48 +00:00
export const meta = {
2023-01-13 04:40:33 +00:00
tags: ["meta"],
refactor: APIエンドポイントファイルの定義を良い感じにする (#8154) * Fix API Schema Error * Delete SimpleSchema/SimpleObj and Move schemas to dedicated files * Userのスキーマを分割してみる * define packMany type * add , * Ensure enum schema and Make "as const" put once * test? * Revert "test?" This reverts commit 97dc9bfa70851bfb7d1cf38e883f8df20fb78b79. * Revert "Fix API Schema Error" This reverts commit 21b6176d974ed8e3eb73723ad21a105c5d297323. * :v: * clean up * test? * wip * wip * better schema def * :v: * fix * add minLength property * wip * wip * wip * anyOf/oneOf/allOfに対応? ~ relation.ts * refactor! * Define MinimumSchema * wip * wip * anyOf/oneOf/allOfが動作するようにUnionSchemaTypeを修正 * anyOf/oneOf/allOfが動作するようにUnionSchemaTypeを修正 * Update packages/backend/src/misc/schema.ts Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * fix * array oneOfをより正確な型に * array oneOfをより正確な型に * wip * :v: * なんかもういろいろ * remove * very good schema * api schema * wip * refactor: awaitAllの型定義を変えてみる * fix * specify types in awaitAll * specify types in awaitAll * :v: * wip * ... * :v: * AllowDateはやめておく * 不必要なoptional: false, nullable: falseを廃止 * Packedが展開されないように * 続packed * wip * define note type * wip * UserDetailedをMeDetailedかUserDetailedNotMeかを区別できるように * wip * wip * wip specify user type of other schemas * ok * convertSchemaToOpenApiSchemaを改修 * convertSchemaToOpenApiSchemaを改修 * Fix * fix * :v: * wip * 分割代入ではなくallOfで定義するように Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
2022-01-18 13:27:10 +00:00
requireCredential: false,
2018-10-08 16:01:48 +00:00
2019-02-24 18:21:54 +00:00
res: {
2023-01-13 04:40:33 +00:00
type: "object",
optional: false,
nullable: false,
2019-02-24 18:21:54 +00:00
properties: {
maintainerName: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
maintainerEmail: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
2019-02-24 18:21:54 +00:00
version: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
2021-12-09 14:58:30 +00:00
example: config.version,
2019-02-24 18:21:54 +00:00
},
name: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
2019-02-24 18:21:54 +00:00
},
uri: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
format: "url",
2023-07-02 22:18:30 +00:00
example: "https://firefish.example.com",
},
description: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
2019-02-24 18:21:54 +00:00
},
langs: {
2023-01-13 04:40:33 +00:00
type: "array",
optional: false,
nullable: false,
items: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
2021-12-09 14:58:30 +00:00
},
},
tosUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
moreUrls: {
type: "object",
optional: false,
nullable: false,
},
repositoryUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
default: "https://firefish.dev/firefish/firefish",
},
feedbackUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
default: "https://firefish.dev/firefish/firefish/issues",
},
2022-03-01 14:58:01 +00:00
defaultDarkTheme: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
2022-03-01 14:58:01 +00:00
},
defaultLightTheme: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
2022-03-01 14:58:01 +00:00
},
disableRegistration: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
disableLocalTimeline: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
2022-07-29 04:28:13 +00:00
disableRecommendedTimeline: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
2022-07-29 04:28:13 +00:00
},
disableGlobalTimeline: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
enableGuestTimeline: {
type: "boolean",
optional: false,
nullable: false,
},
driveCapacityPerLocalUserMb: {
2023-01-13 04:40:33 +00:00
type: "number",
optional: false,
nullable: false,
},
driveCapacityPerRemoteUserMb: {
2023-01-13 04:40:33 +00:00
type: "number",
optional: false,
nullable: false,
},
2024-04-13 00:59:11 +00:00
antennaLimit: {
type: "number",
optional: false,
nullable: false,
},
cacheRemoteFiles: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
markLocalFilesNsfwByDefault: {
type: "boolean",
optional: false,
nullable: false,
},
emailRequiredForSignup: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
enableHcaptcha: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
hcaptchaSiteKey: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
enableRecaptcha: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
recaptchaSiteKey: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
swPublickey: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
mascotImageUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
default: "/static-assets/badges/info.webp",
},
bannerUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
},
errorImageUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
default: "/static-assets/badges/error.webp",
},
iconUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
maxNoteTextLength: {
2023-01-13 04:40:33 +00:00
type: "number",
optional: false,
nullable: false,
},
maxCaptionTextLength: {
type: "number",
optional: false,
nullable: false,
},
emojis: {
2023-01-13 04:40:33 +00:00
type: "array",
optional: false,
nullable: false,
2019-02-24 18:21:54 +00:00
items: {
2023-01-13 04:40:33 +00:00
type: "object",
optional: false,
nullable: false,
2019-02-24 18:21:54 +00:00
properties: {
id: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
format: "id",
2019-02-24 18:21:54 +00:00
},
aliases: {
2023-01-13 04:40:33 +00:00
type: "array",
optional: false,
nullable: false,
items: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
2021-12-09 14:58:30 +00:00
},
2019-02-24 18:21:54 +00:00
},
category: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
host: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
description: "The local host is represented with `null`.",
},
url: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
format: "url",
2021-12-09 14:58:30 +00:00
},
},
},
2019-02-24 18:21:54 +00:00
},
ads: {
2023-01-13 04:40:33 +00:00
type: "array",
optional: false,
nullable: false,
items: {
2023-01-13 04:40:33 +00:00
type: "object",
optional: false,
nullable: false,
properties: {
place: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
},
url: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
format: "url",
},
imageUrl: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: false,
format: "url",
},
2021-12-09 14:58:30 +00:00
},
},
},
requireSetup: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
2021-12-09 14:58:30 +00:00
example: false,
2019-02-24 18:21:54 +00:00
},
enableEmail: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
2019-02-24 18:21:54 +00:00
},
enableServiceWorker: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
translatorAvailable: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
proxyAccountName: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: false,
nullable: true,
},
features: {
2023-01-13 04:40:33 +00:00
type: "object",
optional: true,
nullable: false,
properties: {
registration: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
localTimeLine: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
2022-07-29 04:49:36 +00:00
recommendedTimeLine: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
2022-07-29 04:28:13 +00:00
},
globalTimeLine: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
2023-06-06 23:19:13 +00:00
searchFilters: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
hcaptcha: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
recaptcha: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
objectStorage: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
serviceWorker: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: false,
nullable: false,
},
miauth: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: true,
nullable: false,
2021-12-09 14:58:30 +00:00
default: true,
},
2021-12-09 14:58:30 +00:00
},
},
secureMode: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: true,
nullable: false,
default: false,
},
privateMode: {
2023-01-13 04:40:33 +00:00
type: "boolean",
optional: true,
nullable: false,
default: false,
},
defaultReaction: {
2023-01-13 04:40:33 +00:00
type: "string",
optional: "false",
nullable: false,
default: "⭐",
},
donationLink: {
type: "string",
optional: "true",
nullable: true,
},
enableServerMachineStats: {
type: "boolean",
optional: "true",
nullable: false,
default: false,
},
2021-12-09 14:58:30 +00:00
},
},
refactor: APIエンドポイントファイルの定義を良い感じにする (#8154) * Fix API Schema Error * Delete SimpleSchema/SimpleObj and Move schemas to dedicated files * Userのスキーマを分割してみる * define packMany type * add , * Ensure enum schema and Make "as const" put once * test? * Revert "test?" This reverts commit 97dc9bfa70851bfb7d1cf38e883f8df20fb78b79. * Revert "Fix API Schema Error" This reverts commit 21b6176d974ed8e3eb73723ad21a105c5d297323. * :v: * clean up * test? * wip * wip * better schema def * :v: * fix * add minLength property * wip * wip * wip * anyOf/oneOf/allOfに対応? ~ relation.ts * refactor! * Define MinimumSchema * wip * wip * anyOf/oneOf/allOfが動作するようにUnionSchemaTypeを修正 * anyOf/oneOf/allOfが動作するようにUnionSchemaTypeを修正 * Update packages/backend/src/misc/schema.ts Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * fix * array oneOfをより正確な型に * array oneOfをより正確な型に * wip * :v: * なんかもういろいろ * remove * very good schema * api schema * wip * refactor: awaitAllの型定義を変えてみる * fix * specify types in awaitAll * specify types in awaitAll * :v: * wip * ... * :v: * AllowDateはやめておく * 不必要なoptional: false, nullable: falseを廃止 * Packedが展開されないように * 続packed * wip * define note type * wip * UserDetailedをMeDetailedかUserDetailedNotMeかを区別できるように * wip * wip * wip specify user type of other schemas * ok * convertSchemaToOpenApiSchemaを改修 * convertSchemaToOpenApiSchemaを改修 * Fix * fix * :v: * wip * 分割代入ではなくallOfで定義するように Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
2022-01-18 13:27:10 +00:00
} as const;
2018-10-08 16:01:48 +00:00
export const paramDef = {
2023-01-13 04:40:33 +00:00
type: "object",
properties: {
2023-01-13 04:40:33 +00:00
detail: { type: "boolean", default: true },
},
required: [],
} as const;
export default define(meta, paramDef, async (ps, me) => {
const instance = await fetchMeta(false);
2017-11-15 00:47:47 +00:00
const emojis = await Emojis.find({
where: {
host: IsNull(),
},
order: {
2023-01-13 04:40:33 +00:00
category: "ASC",
name: "ASC",
},
cache: {
2023-01-13 04:40:33 +00:00
id: "meta_emojis",
milliseconds: 3600000, // 1 hour
2021-12-09 14:58:30 +00:00
},
});
2018-11-02 14:23:01 +00:00
const ads = await Ads.find({
where: {
2021-12-09 14:58:30 +00:00
expiresAt: MoreThan(new Date()),
},
});
const response: any = {
Use PostgreSQL instead of MongoDB (#4572) * wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * :v: * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * :pizza: * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * :v: * clean up * docs * Update push.ts * wip * Update api.ts * wip * :v: * Update make-pagination-query.ts * :v: * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * :art: * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * :v: * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * :art: * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * :v: * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * :sushi: * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * :clock4: * Fix bug * Add test * Add test * rename * Fix bug
2019-04-07 12:50:36 +00:00
maintainerName: instance.maintainerName,
maintainerEmail: instance.maintainerEmail,
version: config.version,
name: instance.name,
uri: config.url,
description: instance.description,
langs: instance.langs,
tosUrl: instance.tosUrl,
moreUrls: instance.moreUrls,
repositoryUrl: instance.repositoryUrl,
feedbackUrl: instance.feedbackUrl,
secureMode: instance.secureMode,
privateMode: instance.privateMode,
disableRegistration: instance.disableRegistration,
disableLocalTimeline: instance.disableLocalTimeline,
2022-07-29 04:28:13 +00:00
disableRecommendedTimeline: instance.disableRecommendedTimeline,
2019-01-16 05:54:14 +00:00
disableGlobalTimeline: instance.disableGlobalTimeline,
enableGuestTimeline: instance.enableGuestTimeline,
driveCapacityPerLocalUserMb: instance.localDriveCapacityMb,
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
2024-04-13 00:59:11 +00:00
antennaLimit: instance.antennaLimit,
emailRequiredForSignup: instance.emailRequiredForSignup,
2020-04-28 05:29:33 +00:00
enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey,
2018-11-07 03:09:24 +00:00
enableRecaptcha: instance.enableRecaptcha,
recaptchaSiteKey: instance.recaptchaSiteKey,
2018-12-19 19:08:13 +00:00
swPublickey: instance.swPublicKey,
themeColor: instance.themeColor,
2019-01-03 18:52:50 +00:00
mascotImageUrl: instance.mascotImageUrl,
bannerUrl: instance.bannerUrl,
2018-12-11 12:17:57 +00:00
errorImageUrl: instance.errorImageUrl,
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため
maxCaptionTextLength: MAX_CAPTION_TEXT_LENGTH,
emojis: instance.privateMode && !me ? [] : await Emojis.packMany(emojis),
// クライアントの手間を減らすためあらかじめJSONに変換しておく
defaultLightTheme: instance.defaultLightTheme
? JSON.stringify(JSON5.parse(instance.defaultLightTheme))
: null,
defaultDarkTheme: instance.defaultDarkTheme
? JSON.stringify(JSON5.parse(instance.defaultDarkTheme))
: null,
2023-01-13 04:40:33 +00:00
ads:
instance.privateMode && !me
? []
: ads.map((ad) => ({
id: ad.id,
url: ad.url,
place: ad.place,
ratio: ad.ratio,
imageUrl: ad.imageUrl,
})),
enableEmail: instance.enableEmail,
2018-11-16 17:13:01 +00:00
enableServiceWorker: instance.enableServiceWorker,
2020-08-28 23:56:32 +00:00
2023-04-30 01:09:51 +00:00
translatorAvailable:
instance.deeplAuthKey != null || instance.libreTranslateApiUrl != null,
defaultReaction: instance.defaultReaction,
donationLink: instance.donationLink,
enableServerMachineStats: instance.enableServerMachineStats,
enableIdenticonGeneration: instance.enableIdenticonGeneration,
2023-01-13 04:40:33 +00:00
...(ps.detail
? {
pinnedPages: instance.privateMode && !me ? [] : instance.pinnedPages,
pinnedClipId:
instance.privateMode && !me ? [] : instance.pinnedClipId,
cacheRemoteFiles: instance.cacheRemoteFiles,
markLocalFilesNsfwByDefault: instance.markLocalFilesNsfwByDefault,
2023-01-13 04:40:33 +00:00
requireSetup:
(await Users.countBy({
host: IsNull(),
isAdmin: true,
2023-01-13 04:40:33 +00:00
})) === 0,
}
2023-01-13 04:40:33 +00:00
: {}),
};
2018-11-02 14:23:01 +00:00
if (ps.detail) {
if (!instance.privateMode || me) {
2023-01-13 04:40:33 +00:00
const proxyAccount = instance.proxyAccountId
? await Users.pack(instance.proxyAccountId).catch(() => null)
: null;
response.proxyAccountName = proxyAccount ? proxyAccount.username : null;
}
response.features = {
registration: !instance.disableRegistration,
localTimeLine: !instance.disableLocalTimeline,
2022-07-29 04:49:36 +00:00
recommendedTimeline: !instance.disableRecommendedTimeline,
2019-01-16 05:54:14 +00:00
globalTimeLine: !instance.disableGlobalTimeline,
guestTimeline: instance.enableGuestTimeline,
emailRequiredForSignup: instance.emailRequiredForSignup,
2020-04-28 05:29:33 +00:00
hcaptcha: instance.enableHcaptcha,
recaptcha: instance.enableRecaptcha,
2019-05-15 16:07:32 +00:00
objectStorage: instance.useObjectStorage,
2018-12-19 19:08:13 +00:00
serviceWorker: instance.enableServiceWorker,
postEditing: true,
postImports: instance.experimentalFeatures?.postImports || false,
2020-03-29 08:44:14 +00:00
miauth: true,
};
}
return response;
});