iceshrimp-legacy/packages/backend/src/server/api/endpoints/meta.ts

525 lines
11 KiB
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import { IsNull, MoreThan } from "typeorm";
import config from "@/config/index.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
import { Ads, Emojis, Users } from "@/models/index.js";
import { DB_MAX_NOTE_TEXT_LENGTH } from "@/misc/hard-limits.js";
import { MAX_NOTE_TEXT_LENGTH } from "@/const.js";
import define from "../define.js";
2016-12-28 23:49:51 +01:00
2018-10-08 18:01:48 +02:00
export const meta = {
2023-01-13 05:40:33 +01: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 14:27:10 +01:00
requireCredential: false,
2018-10-08 18:01:48 +02:00
2019-02-24 19:21:54 +01:00
res: {
2023-01-13 05:40:33 +01:00
type: "object",
optional: false,
nullable: false,
2019-02-24 19:21:54 +01:00
properties: {
maintainerName: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
maintainerEmail: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
2019-02-24 19:21:54 +01:00
version: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
2021-12-09 15:58:30 +01:00
example: config.version,
2019-02-24 19:21:54 +01:00
},
name: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
2019-02-24 19:21:54 +01:00
},
uri: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
format: "url",
example: "https://calckey.example.com",
},
description: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
2019-02-24 19:21:54 +01:00
},
langs: {
2023-01-13 05:40:33 +01:00
type: "array",
optional: false,
nullable: false,
items: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
2021-12-09 15:58:30 +01:00
},
},
tosUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
repositoryUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
default: "https://codeberg.org/calckey/calckey",
},
feedbackUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
default: "https://codeberg.org/calckey/calckey/issues",
},
2022-03-01 15:58:01 +01:00
defaultDarkTheme: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
2022-03-01 15:58:01 +01:00
},
defaultLightTheme: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
2022-03-01 15:58:01 +01:00
},
disableRegistration: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
disableLocalTimeline: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
2022-07-29 06:28:13 +02:00
disableRecommendedTimeline: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
2022-07-29 06:28:13 +02:00
},
disableGlobalTimeline: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
driveCapacityPerLocalUserMb: {
2023-01-13 05:40:33 +01:00
type: "number",
optional: false,
nullable: false,
},
driveCapacityPerRemoteUserMb: {
2023-01-13 05:40:33 +01:00
type: "number",
optional: false,
nullable: false,
},
cacheRemoteFiles: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
emailRequiredForSignup: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
enableHcaptcha: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
hcaptchaSiteKey: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
enableRecaptcha: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
recaptchaSiteKey: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
swPublickey: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
mascotImageUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
default: "/assets/ai.png",
},
bannerUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
},
errorImageUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
default: "https://xn--931a.moe/aiart/yubitun.png",
},
iconUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
maxNoteTextLength: {
2023-01-13 05:40:33 +01:00
type: "number",
optional: false,
nullable: false,
},
emojis: {
2023-01-13 05:40:33 +01:00
type: "array",
optional: false,
nullable: false,
2019-02-24 19:21:54 +01:00
items: {
2023-01-13 05:40:33 +01:00
type: "object",
optional: false,
nullable: false,
2019-02-24 19:21:54 +01:00
properties: {
id: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
format: "id",
2019-02-24 19:21:54 +01:00
},
aliases: {
2023-01-13 05:40:33 +01:00
type: "array",
optional: false,
nullable: false,
items: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
2021-12-09 15:58:30 +01:00
},
2019-02-24 19:21:54 +01:00
},
category: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
host: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
description: "The local host is represented with `null`.",
},
url: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
format: "url",
2021-12-09 15:58:30 +01:00
},
},
},
2019-02-24 19:21:54 +01:00
},
ads: {
2023-01-13 05:40:33 +01:00
type: "array",
optional: false,
nullable: false,
items: {
2023-01-13 05:40:33 +01:00
type: "object",
optional: false,
nullable: false,
properties: {
place: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
},
url: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
format: "url",
},
imageUrl: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: false,
format: "url",
},
2021-12-09 15:58:30 +01:00
},
},
},
requireSetup: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
2021-12-09 15:58:30 +01:00
example: false,
2019-02-24 19:21:54 +01:00
},
enableEmail: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
2019-02-24 19:21:54 +01:00
},
enableTwitterIntegration: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
enableGithubIntegration: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
enableDiscordIntegration: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
enableServiceWorker: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
translatorAvailable: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
proxyAccountName: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: false,
nullable: true,
},
features: {
2023-01-13 05:40:33 +01:00
type: "object",
optional: true,
nullable: false,
properties: {
registration: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
localTimeLine: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
2022-07-29 06:49:36 +02:00
recommendedTimeLine: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
2022-07-29 06:28:13 +02:00
},
globalTimeLine: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
elasticsearch: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
hcaptcha: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
recaptcha: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
objectStorage: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
twitter: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
github: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
discord: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
serviceWorker: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: false,
nullable: false,
},
miauth: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: true,
nullable: false,
2021-12-09 15:58:30 +01:00
default: true,
},
2021-12-09 15:58:30 +01:00
},
},
secureMode: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: true,
nullable: false,
default: false,
},
privateMode: {
2023-01-13 05:40:33 +01:00
type: "boolean",
optional: true,
nullable: false,
default: false,
},
defaultReaction: {
2023-01-13 05:40:33 +01:00
type: "string",
optional: "false",
nullable: false,
default: "⭐",
},
2021-12-09 15:58:30 +01: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 14:27:10 +01:00
} as const;
2018-10-08 18:01:48 +02:00
export const paramDef = {
2023-01-13 05:40:33 +01:00
type: "object",
properties: {
2023-01-13 05:40:33 +01:00
detail: { type: "boolean", default: true },
},
required: [],
} as const;
export default define(meta, paramDef, async (ps, me) => {
2019-04-24 01:11:19 +02:00
const instance = await fetchMeta(true);
2017-11-15 01:47:47 +01:00
const emojis = await Emojis.find({
where: {
host: IsNull(),
},
order: {
2023-01-13 05:40:33 +01:00
category: "ASC",
name: "ASC",
},
cache: {
2023-01-13 05:40:33 +01:00
id: "meta_emojis",
milliseconds: 3600000, // 1 hour
2021-12-09 15:58:30 +01:00
},
});
2018-11-02 15:23:01 +01:00
const ads = await Ads.find({
where: {
2021-12-09 15:58:30 +01: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 14:50:36 +02: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,
repositoryUrl: instance.repositoryUrl,
feedbackUrl: instance.feedbackUrl,
secureMode: instance.secureMode,
privateMode: instance.privateMode,
disableRegistration: instance.disableRegistration,
disableLocalTimeline: instance.disableLocalTimeline,
2022-07-29 06:28:13 +02:00
disableRecommendedTimeline: instance.disableRecommendedTimeline,
2019-01-16 06:54:14 +01:00
disableGlobalTimeline: instance.disableGlobalTimeline,
driveCapacityPerLocalUserMb: instance.localDriveCapacityMb,
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
emailRequiredForSignup: instance.emailRequiredForSignup,
2020-04-28 07:29:33 +02:00
enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey,
2018-11-07 04:09:24 +01:00
enableRecaptcha: instance.enableRecaptcha,
recaptchaSiteKey: instance.recaptchaSiteKey,
2018-12-19 20:08:13 +01:00
swPublickey: instance.swPublicKey,
themeColor: instance.themeColor,
2019-01-03 19:52:50 +01:00
mascotImageUrl: instance.mascotImageUrl,
bannerUrl: instance.bannerUrl,
2018-12-11 13:17:57 +01:00
errorImageUrl: instance.errorImageUrl,
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため
emojis: instance.privateMode && !me ? [] : await Emojis.packMany(emojis),
2022-03-01 15:58:01 +01:00
defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme,
2023-01-13 05:40:33 +01: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 18:13:01 +01:00
enableTwitterIntegration: instance.enableTwitterIntegration,
enableGithubIntegration: instance.enableGithubIntegration,
enableDiscordIntegration: instance.enableDiscordIntegration,
enableServiceWorker: instance.enableServiceWorker,
2020-08-29 01:56:32 +02:00
translatorAvailable: instance.deeplAuthKey != null,
defaultReaction: instance.defaultReaction,
2023-01-13 05:40:33 +01:00
...(ps.detail
? {
pinnedPages: instance.privateMode && !me ? [] : instance.pinnedPages,
pinnedClipId:
instance.privateMode && !me ? [] : instance.pinnedClipId,
cacheRemoteFiles: instance.cacheRemoteFiles,
requireSetup:
(await Users.countBy({
host: IsNull(),
})) === 0,
}
: {}),
};
2018-11-02 15:23:01 +01:00
if (ps.detail) {
if (!instance.privateMode || me) {
2023-01-13 05:40:33 +01: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 06:49:36 +02:00
recommendedTimeline: !instance.disableRecommendedTimeline,
2019-01-16 06:54:14 +01:00
globalTimeLine: !instance.disableGlobalTimeline,
emailRequiredForSignup: instance.emailRequiredForSignup,
elasticsearch: config.elasticsearch ? true : false,
2020-04-28 07:29:33 +02:00
hcaptcha: instance.enableHcaptcha,
recaptcha: instance.enableRecaptcha,
2019-05-15 18:07:32 +02:00
objectStorage: instance.useObjectStorage,
twitter: instance.enableTwitterIntegration,
github: instance.enableGithubIntegration,
discord: instance.enableDiscordIntegration,
2018-12-19 20:08:13 +01:00
serviceWorker: instance.enableServiceWorker,
2020-03-29 10:44:14 +02:00
miauth: true,
};
}
return response;
});