-
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
81dd4cd
commit d020053
Showing
23 changed files
with
515 additions
and
105 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
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,60 @@ | ||
// | ||
// 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 plugin from './plugin' | ||
|
||
export function isLinkPreviewEnabled (): boolean { | ||
return getMetadata(plugin.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) { | ||
return false | ||
} | ||
if (val.image === undefined && val.description === undefined) { | ||
return false | ||
} | ||
if (val.title === undefined && val.description === undefined) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
export async function fetchLinkPreviewDetails (url: string, timeoutMs = 15000): Promise<LinkPreviewDetails> { | ||
try { | ||
const linkPreviewUrl = getMetadata(plugin.metadata.LinkPreviewUrl) | ||
let token: string = '' | ||
if (getMetadata(plugin.metadata.Token) !== undefined) { | ||
token = getMetadata(plugin.metadata.Token) as string | ||
} | ||
const response = await fetch(`${linkPreviewUrl}/details?q=${url}`, { | ||
headers: { Authorization: 'Bearer ' + token }, | ||
signal: AbortSignal.timeout(timeoutMs) | ||
}) | ||
return response.json() as LinkPreviewDetails | ||
} catch { | ||
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
51 changes: 51 additions & 0 deletions
51
plugins/attachment-resources/src/components/AttachmentGroup.svelte
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,51 @@ | ||
<!-- // | ||
// 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. | ||
// --> | ||
|
||
<script lang="ts"> | ||
import { type Attachment } from '@hcengineering/attachment' | ||
import { type WithLookup, Ref } from '@hcengineering/core' | ||
import { AttachmentImageSize } from '../types' | ||
import AttachmentList from './AttachmentList.svelte' | ||
import LinkPreviewList from './LinkPreviewList.svelte' | ||
export let attachments: WithLookup<Attachment>[] | ||
export let savedAttachmentsIds: Ref<Attachment>[] = [] | ||
export let imageSize: AttachmentImageSize = 'auto' | ||
export let videoPreload = true | ||
let otherAttachments: WithLookup<Attachment>[] | ||
let linkPreviewAttachments: WithLookup<Attachment>[] | ||
$: filter(attachments) | ||
function filter (value: WithLookup<Attachment>[]): void { | ||
linkPreviewAttachments = [] | ||
otherAttachments = [] | ||
for (const attachment of value) { | ||
if (attachment === undefined) { | ||
continue | ||
} | ||
if (attachment.type === 'application/link-preview') { | ||
linkPreviewAttachments.push(attachment) | ||
} else { | ||
otherAttachments.push(attachment) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<div class="gapV-2"> | ||
<AttachmentList attachments={otherAttachments} {savedAttachmentsIds} {imageSize} {videoPreload} /> | ||
<LinkPreviewList attachments={linkPreviewAttachments} /> | ||
</div> |
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.