From 546189d04f2d6676e2302fc6377ed14ffd99b95d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 7 Aug 2024 13:14:59 -0400 Subject: [PATCH] Add ability to fill magnet link title on post creation. --- src/shared/components/post/post-form.tsx | 26 ++++++++++++++++++++---- src/shared/markdown.ts | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 15a9c81d..6d227382 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -45,6 +45,9 @@ import { MarkdownTextArea } from "../common/markdown-textarea"; import { SearchableSelect } from "../common/searchable-select"; import { PostListings } from "./post-listings"; import { isBrowser } from "@utils/browser"; +import isMagnetLink, { + extractMagnetLinkDownloadName, +} from "@utils/media/is-magnet-link"; const MAX_POST_TITLE_LENGTH = 200; @@ -806,10 +809,25 @@ export class PostForm extends Component { async fetchPageTitle() { const url = this.state.form.url; if (url && validURL(url)) { - this.setState({ metadataRes: LOADING_REQUEST }); - this.setState({ - metadataRes: await HttpService.client.getSiteMetadata({ url }), - }); + // If its a magnet link, fill in the download name + if (isMagnetLink(url)) { + const title = extractMagnetLinkDownloadName(url); + if (title) { + this.setState({ + metadataRes: { + state: "success", + data: { + metadata: { title }, + }, + }, + }); + } + } else { + this.setState({ metadataRes: LOADING_REQUEST }); + this.setState({ + metadataRes: await HttpService.client.getSiteMetadata({ url }), + }); + } } } diff --git a/src/shared/markdown.ts b/src/shared/markdown.ts index 8b8b7cca..5db10dc8 100644 --- a/src/shared/markdown.ts +++ b/src/shared/markdown.ts @@ -336,7 +336,8 @@ export function getEmojiMart( } export async function setupTribute() { - if (Tribute === null) { + // eslint-disable-next-line eqeqeq + if (Tribute == null) { console.debug("Tribute is null, importing..."); Tribute = (await import("tributejs")).default; }