-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: denis-tingaikin <[email protected]>
- Loading branch information
1 parent
9c7ce99
commit 93c3da5
Showing
17 changed files
with
322 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Copyright © 2025 Hardcore Engineering Inc. | ||
// | ||
// Licensed under the Eclipse Public License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. You may | ||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
import { getMetadata } from '@hcengineering/platform' | ||
import presentation from './plugin' | ||
|
||
export function isLinkPreviewEnabled (): boolean { | ||
return getMetadata(presentation.metadata.LinkPreviewUrl) !== undefined | ||
} | ||
export interface LinkPreviewDetails { | ||
title?: string | ||
description?: string | ||
url?: string | ||
icon?: string | ||
image?: string | ||
charset?: string | ||
hostname?: string | ||
host?: string | ||
} | ||
|
||
export function canDisplayLinkPreview (val: LinkPreviewDetails): boolean { | ||
if (val.hostname === undefined && val.title === undefined) { | ||
return false | ||
} | ||
if (val.image === undefined && val.description === undefined) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
export async function fetchLinkPreviewDetails (url: string): Promise<LinkPreviewDetails> { | ||
try { | ||
const linkPreviewUrl = getMetadata(presentation.metadata.LinkPreviewUrl) | ||
const response = await fetch(`${linkPreviewUrl}?q=${url}`, { | ||
signal: AbortSignal.timeout(5 * 1000) | ||
}) | ||
if (!response.ok) { | ||
throw new Error(`status: ${response.status}`) | ||
} | ||
console.log(response) | ||
return response.json() as LinkPreviewDetails | ||
} catch (error) { | ||
console.error(`An error occurced on fetching or parsing data by ${url}, error:`, error) | ||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.