From 35735342c156e27c1e50f8884af4cea808ee33ae Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 7 Sep 2024 09:48:25 +0200 Subject: [PATCH] server: remove summaly Changelog: Removed --- .../migration/1725695130950-remove-summaly.js | 11 + packages/backend/package.json | 1 - packages/backend/src/models/entities/meta.ts | 6 - .../src/server/api/endpoints/admin/meta.ts | 1 - .../server/api/endpoints/admin/update-meta.ts | 5 - packages/backend/src/server/web/index.ts | 4 - .../backend/src/server/web/url-preview.ts | 71 ---- packages/client/src/components/global/url.vue | 12 - packages/client/src/components/link.vue | 13 - .../client/src/components/note-detailed.vue | 6 - packages/client/src/components/note.vue | 6 - .../src/components/url-preview-popup.vue | 42 -- .../client/src/components/url-preview.vue | 275 ------------- packages/client/src/pages/admin/security.vue | 23 -- .../messaging/messaging-room.message.vue | 2 - yarn.lock | 364 +----------------- 16 files changed, 20 insertions(+), 822 deletions(-) create mode 100644 packages/backend/migration/1725695130950-remove-summaly.js delete mode 100644 packages/backend/src/server/web/url-preview.ts delete mode 100644 packages/client/src/components/url-preview-popup.vue delete mode 100644 packages/client/src/components/url-preview.vue diff --git a/packages/backend/migration/1725695130950-remove-summaly.js b/packages/backend/migration/1725695130950-remove-summaly.js new file mode 100644 index 000000000..3496d2ac0 --- /dev/null +++ b/packages/backend/migration/1725695130950-remove-summaly.js @@ -0,0 +1,11 @@ +export class removeSummaly1725695130950 { + name = 'removeSummaly1725695130950' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "summalyProxy"`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "summalyProxy" character varying(128)`); + } +} diff --git a/packages/backend/package.json b/packages/backend/package.json index acb2fdadc..641f41a91 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -96,7 +96,6 @@ "strict-event-emitter-types": "2.0.0", "stringz": "2.1.0", "style-loader": "3.3.1", - "summaly": "2.7.0", "systeminformation": "5.11.22", "tinycolor2": "1.4.2", "tmp": "0.2.1", diff --git a/packages/backend/src/models/entities/meta.ts b/packages/backend/src/models/entities/meta.ts index f00d0473e..c19e1c571 100644 --- a/packages/backend/src/models/entities/meta.ts +++ b/packages/backend/src/models/entities/meta.ts @@ -175,12 +175,6 @@ export class Meta { }) public remoteDriveCapacityMb: number; - @Column('varchar', { - length: 128, - nullable: true, - }) - public summalyProxy: string | null; - @Column('boolean', { default: false, }) diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index fcf90a129..fc573bac9 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -288,7 +288,6 @@ export default define(meta, paramDef, async () => { hcaptchaSecretKey: instance.hcaptchaSecretKey, recaptchaSecretKey: instance.recaptchaSecretKey, proxyAccountId: instance.proxyAccountId, - summalyProxy: instance.summalyProxy, email: instance.email, smtpSecure: instance.smtpSecure, smtpHost: instance.smtpHost, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index f4a2172ec..0ec83c1d7 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -48,7 +48,6 @@ export const paramDef = { langs: { type: 'array', items: { type: 'string', } }, - summalyProxy: { type: 'string', nullable: true }, translationService: { type: 'string', nullable: true, enum: [null, ...Object.values(TranslationService)] }, deeplAuthKey: { type: 'string', nullable: true }, libreTranslateAuthKey: { type: 'string', nullable: true }, @@ -198,10 +197,6 @@ export default define(meta, paramDef, async (ps, me) => { set.langs = ps.langs.filter(Boolean); } - if (ps.summalyProxy !== undefined) { - set.summalyProxy = ps.summalyProxy; - } - if (ps.enableEmail !== undefined) { set.enableEmail = ps.enableEmail; } diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index 2f9a76c84..66b2a8f24 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -24,7 +24,6 @@ import { getNoteSummary } from '@/misc/get-note-summary.js'; import { queues } from '@/queue/queues.js'; import { MINUTE, DAY } from '@/const.js'; import { genOpenapiSpec } from '../api/openapi/gen-spec.js'; -import { urlPreviewHandler } from './url-preview.js'; import { manifestHandler } from './manifest.js'; import { packFeed } from './feed.js'; @@ -210,9 +209,6 @@ router.get('/api-doc', async ctx => { }); }); -// URL preview endpoint -router.get('/url', urlPreviewHandler); - router.get('/api.json', async ctx => { ctx.body = genOpenapiSpec(); }); diff --git a/packages/backend/src/server/web/url-preview.ts b/packages/backend/src/server/web/url-preview.ts deleted file mode 100644 index 259912e55..000000000 --- a/packages/backend/src/server/web/url-preview.ts +++ /dev/null @@ -1,71 +0,0 @@ -import Koa from 'koa'; -import summaly from 'summaly'; -import { fetchMeta } from '@/misc/fetch-meta.js'; -import Logger from '@/services/logger.js'; -import config from '@/config/index.js'; -import { query } from '@/prelude/url.js'; -import { getJson } from '@/misc/fetch.js'; - -const logger = new Logger('url-preview'); - -export const urlPreviewHandler = async (ctx: Koa.Context): Promise => { - const url = ctx.query.url; - if (typeof url !== 'string') { - ctx.status = 400; - return; - } - - const lang = ctx.query.lang; - if (Array.isArray(lang)) { - ctx.status = 400; - return; - } - - const meta = await fetchMeta(); - - logger.info(meta.summalyProxy - ? `(Proxy) Getting preview of ${url}@${lang} ...` - : `Getting preview of ${url}@${lang} ...`); - - try { - const summary = meta.summalyProxy ? await getJson(`${meta.summalyProxy}?${query({ - url, - lang: lang ?? 'en-US', - })}`) : await summaly.default(url, { - followRedirects: false, - lang: lang ?? 'en-US', - }); - - logger.succ(`Got preview of ${url}: ${summary.title}`); - - if (summary.url && !(summary.url.startsWith('http://') || summary.url.startsWith('https://'))) { - throw new Error('unsupported schema included'); - } - - if (summary.player?.url && !(summary.player.url.startsWith('http://') || summary.player.url.startsWith('https://'))) { - throw new Error('unsupported schema included'); - } - - summary.icon = wrap(summary.icon); - summary.thumbnail = wrap(summary.thumbnail); - - // Cache 7days - ctx.set('Cache-Control', 'max-age=604800, immutable'); - - ctx.body = summary; - } catch (err) { - logger.warn(`Failed to get preview of ${url}: ${err}`); - ctx.status = 200; - ctx.set('Cache-Control', 'max-age=86400, immutable'); - ctx.body = '{}'; - } -}; - -function wrap(url?: string): string | null { - if (url == null) return null; - if (!['http:', 'https:'].includes(new URL(url).protocol)) return null; - return config.url + '/proxy/preview.webp?' + query({ - url, - preview: '1', - }); -} diff --git a/packages/client/src/components/global/url.vue b/packages/client/src/components/global/url.vue index 0147b2ec1..696b4ea0a 100644 --- a/packages/client/src/components/global/url.vue +++ b/packages/client/src/components/global/url.vue @@ -19,12 +19,9 @@ diff --git a/packages/client/src/components/url-preview.vue b/packages/client/src/components/url-preview.vue deleted file mode 100644 index 28646e0a3..000000000 --- a/packages/client/src/components/url-preview.vue +++ /dev/null @@ -1,275 +0,0 @@ -