From c252c16fc2ead178b9b8a6bf0b3e0dc142d96a21 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 24 Jun 2023 13:00:50 -0700 Subject: [PATCH 1/3] feat: :lock: expand /api/v1/instance/peers to proper endpoint and check for private mode Closes #10358 --- .../backend/src/server/api/compatibility.ts | 10 +++++--- .../api/endpoints/compatibility/peers.ts | 25 +++++++++++++++++++ packages/backend/src/server/api/index.ts | 15 ++--------- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 packages/backend/src/server/api/endpoints/compatibility/peers.ts diff --git a/packages/backend/src/server/api/compatibility.ts b/packages/backend/src/server/api/compatibility.ts index 7e44fa8b2..42be40e10 100644 --- a/packages/backend/src/server/api/compatibility.ts +++ b/packages/backend/src/server/api/compatibility.ts @@ -1,11 +1,13 @@ import type { IEndpoint } from "./endpoints"; -import * as cp___instanceInfo from "./endpoints/compatibility/instance-info.js"; -import * as cp___customEmojis from "./endpoints/compatibility/custom-emojis.js"; +import * as cp___instance_info from "./endpoints/compatibility/instance-info.js"; +import * as cp___custom_emojis from "./endpoints/compatibility/custom-emojis.js"; +import * as ep___instance_peers from "./endpoints/compatibility/peers.js"; const cps = [ - ["v1/instance", cp___instanceInfo], - ["v1/custom_emojis", cp___customEmojis], + ["v1/instance", cp___instance_info], + ["v1/custom_emojis", cp___custom_emojis], + ["v1/instance/peers", ep___instance_peers], ]; const compatibility: IEndpoint[] = cps.map(([name, cp]) => { diff --git a/packages/backend/src/server/api/endpoints/compatibility/peers.ts b/packages/backend/src/server/api/endpoints/compatibility/peers.ts new file mode 100644 index 000000000..30f6e0e93 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/compatibility/peers.ts @@ -0,0 +1,25 @@ +import { Instances } from "@/models/index.js"; +import define from "../../define.js"; + +export const meta = { + tags: ["meta"], + requireCredential: false, + requireCredentialPrivateMode: true, + allowGet: true, + cacheSec: 60, +} as const; + +export const paramDef = { + type: "object", +} as const; + +export default define(meta, paramDef, async (ps) => { + const instances = await Instances.find({ + select: ["host"], + where: { + isSuspended: false, + }, + }); + + return instances.map((instance) => instance.host); +}); diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 3568a27b2..29cfbf93c 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -87,7 +87,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => { const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - let multipartData = await ctx.file; + const multipartData = await ctx.file; if (!multipartData) { ctx.body = { error: "No image" }; ctx.status = 401; @@ -106,7 +106,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => { const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - let multipartData = await ctx.file; + const multipartData = await ctx.file; if (!multipartData) { ctx.body = { error: "No image" }; ctx.status = 401; @@ -185,17 +185,6 @@ router.use(discord.routes()); router.use(github.routes()); router.use(twitter.routes()); -router.get("/v1/instance/peers", async (ctx) => { - const instances = await Instances.find({ - select: ["host"], - where: { - isSuspended: false, - }, - }); - - ctx.body = instances.map((instance) => instance.host); -}); - router.post("/miauth/:session/check", async (ctx) => { const token = await AccessTokens.findOneBy({ session: ctx.params.session, From 47fd2ab06c44d3797cd280840b5bf0496e28ff1d Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 24 Jun 2023 13:23:12 -0700 Subject: [PATCH 2/3] docs: :memo: mention libvips requirement #10352 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 04010e89a..f66d14a32 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ If you have access to a server that supports one of the sources below, I recomme - 🍀 Nginx (recommended) - 🦦 Caddy - 🪶 Apache +- ⚡ [libvips](https://www.libvips.org/) ### 😗 Optional dependencies From 2fb00642dcb8728247959f9cce4629a6d1e1e8c0 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 24 Jun 2023 13:25:25 -0700 Subject: [PATCH 3/3] fix: :adhesive_bandage: make cacheRemoteFiles false by default for new instances --- packages/backend/migration/1000000000000-Init.js | 2 +- packages/backend/src/models/entities/meta.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/migration/1000000000000-Init.js b/packages/backend/migration/1000000000000-Init.js index d32a6e0d2..bab5fae7a 100644 --- a/packages/backend/migration/1000000000000-Init.js +++ b/packages/backend/migration/1000000000000-Init.js @@ -220,7 +220,7 @@ export class Init1000000000000 { `CREATE INDEX "IDX_3c601b70a1066d2c8b517094cb" ON "notification" ("notifieeId") `, ); await queryRunner.query( - `CREATE TABLE "meta" ("id" character varying(32) NOT NULL, "name" character varying(128), "description" character varying(1024), "maintainerName" character varying(128), "maintainerEmail" character varying(128), "announcements" jsonb NOT NULL DEFAULT '[]', "disableRegistration" boolean NOT NULL DEFAULT false, "disableLocalTimeline" boolean NOT NULL DEFAULT false, "disableGlobalTimeline" boolean NOT NULL DEFAULT false, "enableEmojiReaction" boolean NOT NULL DEFAULT true, "useStarForReactionFallback" boolean NOT NULL DEFAULT false, "langs" character varying(64) array NOT NULL DEFAULT '{}'::varchar[], "hiddenTags" character varying(256) array NOT NULL DEFAULT '{}'::varchar[], "blockedHosts" character varying(256) array NOT NULL DEFAULT '{}'::varchar[], "mascotImageUrl" character varying(512) DEFAULT '/static-assets/badges/info.png', "bannerUrl" character varying(512), "errorImageUrl" character varying(512) DEFAULT '/static-assets/badges/error.png', "iconUrl" character varying(512), "cacheRemoteFiles" boolean NOT NULL DEFAULT true, "proxyAccount" character varying(128), "enableRecaptcha" boolean NOT NULL DEFAULT false, "recaptchaSiteKey" character varying(64), "recaptchaSecretKey" character varying(64), "localDriveCapacityMb" integer NOT NULL DEFAULT 1024, "remoteDriveCapacityMb" integer NOT NULL DEFAULT 32, "maxNoteTextLength" integer NOT NULL DEFAULT 500, "summalyProxy" character varying(128), "enableEmail" boolean NOT NULL DEFAULT false, "email" character varying(128), "smtpSecure" boolean NOT NULL DEFAULT false, "smtpHost" character varying(128), "smtpPort" integer, "smtpUser" character varying(128), "smtpPass" character varying(128), "enableServiceWorker" boolean NOT NULL DEFAULT false, "swPublicKey" character varying(128), "swPrivateKey" character varying(128), "enableTwitterIntegration" boolean NOT NULL DEFAULT false, "twitterConsumerKey" character varying(128), "twitterConsumerSecret" character varying(128), "enableGithubIntegration" boolean NOT NULL DEFAULT false, "githubClientId" character varying(128), "githubClientSecret" character varying(128), "enableDiscordIntegration" boolean NOT NULL DEFAULT false, "discordClientId" character varying(128), "discordClientSecret" character varying(128), CONSTRAINT "PK_c4c17a6c2bd7651338b60fc590b" PRIMARY KEY ("id"))`, + `CREATE TABLE "meta" ("id" character varying(32) NOT NULL, "name" character varying(128), "description" character varying(1024), "maintainerName" character varying(128), "maintainerEmail" character varying(128), "announcements" jsonb NOT NULL DEFAULT '[]', "disableRegistration" boolean NOT NULL DEFAULT false, "disableLocalTimeline" boolean NOT NULL DEFAULT false, "disableGlobalTimeline" boolean NOT NULL DEFAULT false, "enableEmojiReaction" boolean NOT NULL DEFAULT true, "useStarForReactionFallback" boolean NOT NULL DEFAULT false, "langs" character varying(64) array NOT NULL DEFAULT '{}'::varchar[], "hiddenTags" character varying(256) array NOT NULL DEFAULT '{}'::varchar[], "blockedHosts" character varying(256) array NOT NULL DEFAULT '{}'::varchar[], "mascotImageUrl" character varying(512) DEFAULT '/static-assets/badges/info.png', "bannerUrl" character varying(512), "errorImageUrl" character varying(512) DEFAULT '/static-assets/badges/error.png', "iconUrl" character varying(512), "cacheRemoteFiles" boolean NOT NULL DEFAULT false, "proxyAccount" character varying(128), "enableRecaptcha" boolean NOT NULL DEFAULT false, "recaptchaSiteKey" character varying(64), "recaptchaSecretKey" character varying(64), "localDriveCapacityMb" integer NOT NULL DEFAULT 1024, "remoteDriveCapacityMb" integer NOT NULL DEFAULT 32, "maxNoteTextLength" integer NOT NULL DEFAULT 500, "summalyProxy" character varying(128), "enableEmail" boolean NOT NULL DEFAULT false, "email" character varying(128), "smtpSecure" boolean NOT NULL DEFAULT false, "smtpHost" character varying(128), "smtpPort" integer, "smtpUser" character varying(128), "smtpPass" character varying(128), "enableServiceWorker" boolean NOT NULL DEFAULT false, "swPublicKey" character varying(128), "swPrivateKey" character varying(128), "enableTwitterIntegration" boolean NOT NULL DEFAULT false, "twitterConsumerKey" character varying(128), "twitterConsumerSecret" character varying(128), "enableGithubIntegration" boolean NOT NULL DEFAULT false, "githubClientId" character varying(128), "githubClientSecret" character varying(128), "enableDiscordIntegration" boolean NOT NULL DEFAULT false, "discordClientId" character varying(128), "discordClientSecret" character varying(128), CONSTRAINT "PK_c4c17a6c2bd7651338b60fc590b" PRIMARY KEY ("id"))`, ); await queryRunner.query( `CREATE TABLE "following" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "followeeId" character varying(32) NOT NULL, "followerId" character varying(32) NOT NULL, "followerHost" character varying(128), "followerInbox" character varying(512), "followerSharedInbox" character varying(512), "followeeHost" character varying(128), "followeeInbox" character varying(512), "followeeSharedInbox" character varying(512), CONSTRAINT "PK_c76c6e044bdf76ecf8bfb82a645" PRIMARY KEY ("id"))`, diff --git a/packages/backend/src/models/entities/meta.ts b/packages/backend/src/models/entities/meta.ts index b22c6510f..dd3c5b3b7 100644 --- a/packages/backend/src/models/entities/meta.ts +++ b/packages/backend/src/models/entities/meta.ts @@ -198,7 +198,7 @@ export class Meta { public iconUrl: string | null; @Column("boolean", { - default: true, + default: false, }) public cacheRemoteFiles: boolean;