mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 04:32:17 +10:00
wip
This commit is contained in:
+31
-18
@@ -13,6 +13,28 @@ import { useEffect, useCallback, memo } from "react";
|
|||||||
import { unfurlUrl } from "@/features/integration/services/integration-service";
|
import { unfurlUrl } from "@/features/integration/services/integration-service";
|
||||||
import classes from "./integration-link-view.module.css";
|
import classes from "./integration-link-view.module.css";
|
||||||
|
|
||||||
|
function toBadgeColor(raw?: string): string {
|
||||||
|
if (!raw) return "gray";
|
||||||
|
const hex = raw.toLowerCase().replace("#", "");
|
||||||
|
if (/^[0-9a-f]{6}$/.test(hex)) {
|
||||||
|
const r = parseInt(hex.slice(0, 2), 16);
|
||||||
|
const g = parseInt(hex.slice(2, 4), 16);
|
||||||
|
const b = parseInt(hex.slice(4, 6), 16);
|
||||||
|
const max = Math.max(r, g, b);
|
||||||
|
const min = Math.min(r, g, b);
|
||||||
|
const l = (max + min) / 2 / 255;
|
||||||
|
if (max - min < 30) return l > 0.6 ? "gray" : "dark";
|
||||||
|
if (r > g && r > b) return g > 160 ? "orange" : "red";
|
||||||
|
if (g > r && g > b) return r > 160 ? "lime" : "green";
|
||||||
|
if (b > r && b > g) return r > 100 ? "violet" : "blue";
|
||||||
|
if (r > 200 && g > 200) return "yellow";
|
||||||
|
if (r > 200 && b > 200) return "pink";
|
||||||
|
if (g > 200 && b > 200) return "cyan";
|
||||||
|
return "gray";
|
||||||
|
}
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
const providerIcons: Record<string, string> = {
|
const providerIcons: Record<string, string> = {
|
||||||
github: "https://github.githubassets.com/favicons/favicon-dark.svg",
|
github: "https://github.githubassets.com/favicons/favicon-dark.svg",
|
||||||
gitlab: "https://gitlab.com/assets/favicon-72a2cad5025aa931d6ea56c3201d1f18e68a8571da3c2571592f63571e0c5571.png",
|
gitlab: "https://gitlab.com/assets/favicon-72a2cad5025aa931d6ea56c3201d1f18e68a8571da3c2571592f63571e0c5571.png",
|
||||||
@@ -109,7 +131,7 @@ function IntegrationLinkView(props: any) {
|
|||||||
<Badge
|
<Badge
|
||||||
size="xs"
|
size="xs"
|
||||||
variant="light"
|
variant="light"
|
||||||
color={unfurlData.statusColor ?? "gray"}
|
color={toBadgeColor(unfurlData.statusColor)}
|
||||||
style={{ flexShrink: 0 }}
|
style={{ flexShrink: 0 }}
|
||||||
>
|
>
|
||||||
{unfurlData.status}
|
{unfurlData.status}
|
||||||
@@ -118,24 +140,15 @@ function IntegrationLinkView(props: any) {
|
|||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{unfurlData.description && (
|
{unfurlData.description && (
|
||||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
<Group gap={6} wrap="nowrap">
|
||||||
{unfurlData.description}
|
{iconUrl && (
|
||||||
</Text>
|
<Avatar src={iconUrl} size={14} radius="sm" style={{ flexShrink: 0 }} />
|
||||||
)}
|
)}
|
||||||
|
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||||
<Group gap="xs">
|
{unfurlData.description}
|
||||||
{iconUrl && (
|
|
||||||
<Avatar src={iconUrl} size={14} radius="sm" />
|
|
||||||
)}
|
|
||||||
<Text size="xs" c="dimmed">
|
|
||||||
{unfurlData.provider}
|
|
||||||
</Text>
|
|
||||||
{unfurlData.author && (
|
|
||||||
<Text size="xs" c="dimmed">
|
|
||||||
· {unfurlData.author}
|
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
</Group>
|
||||||
</Group>
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class UnfurlService {
|
|||||||
userId: string,
|
userId: string,
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
): Promise<UnfurlResult | null> {
|
): Promise<UnfurlResult | null> {
|
||||||
const cacheKey = this.buildCacheKey(workspaceId, url);
|
const cacheKey = this.buildCacheKey(workspaceId, userId, url);
|
||||||
const cached = await this.redis.get(cacheKey);
|
const cached = await this.redis.get(cacheKey);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
return JSON.parse(cached);
|
return JSON.parse(cached);
|
||||||
@@ -127,12 +127,12 @@ export class UnfurlService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildCacheKey(workspaceId: string, url: string): string {
|
private buildCacheKey(workspaceId: string, userId: string, url: string): string {
|
||||||
const hash = crypto
|
const hash = crypto
|
||||||
.createHash('sha256')
|
.createHash('sha256')
|
||||||
.update(url)
|
.update(url)
|
||||||
.digest('hex')
|
.digest('hex')
|
||||||
.slice(0, 16);
|
.slice(0, 16);
|
||||||
return `${UNFURL_CACHE_PREFIX}${workspaceId}:${hash}`;
|
return `${UNFURL_CACHE_PREFIX}${workspaceId}:${userId}:${hash}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule apps/server/src/ee updated: 010a833e1a...73f6bad794
Reference in New Issue
Block a user