mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-07 08:36:49 +08:00
feat: Add Markdown direct link feature to DirectLinkModal (#28)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DrizzleTime <169802108+DrizzleTime@users.noreply.github.com> Co-authored-by: 时雨 <im@shiyu.dev>
This commit is contained in:
co-authored by
copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
DrizzleTime
时雨
parent
fd87dc3ce2
commit
59d6c94a57
@@ -1,6 +1,6 @@
|
|||||||
import { memo, useState, useEffect } from 'react';
|
import { memo, useState, useEffect } from 'react';
|
||||||
import { Modal, Radio, message, Button, Typography, Input } from 'antd';
|
import { Modal, Radio, message, Button, Typography, Input, Space } from 'antd';
|
||||||
import { CopyOutlined } from '@ant-design/icons';
|
import { CopyOutlined, FileMarkdownOutlined } from '@ant-design/icons';
|
||||||
import type { VfsEntry } from '../../../../api/client';
|
import type { VfsEntry } from '../../../../api/client';
|
||||||
import { vfsApi } from '../../../../api/client';
|
import { vfsApi } from '../../../../api/client';
|
||||||
|
|
||||||
@@ -11,6 +11,21 @@ interface DirectLinkModalProps {
|
|||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to check if a file is an image
|
||||||
|
const isImageFile = (fileName: string): boolean => {
|
||||||
|
const ext = fileName.split('.').pop()?.toLowerCase() || '';
|
||||||
|
return ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'ico', 'tiff'].includes(ext);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to generate Markdown formatted link
|
||||||
|
const generateMarkdownLink = (fileName: string, url: string): string => {
|
||||||
|
if (isImageFile(fileName)) {
|
||||||
|
return ``;
|
||||||
|
} else {
|
||||||
|
return `[${fileName}](${url})`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const DirectLinkModal = memo(function DirectLinkModal({ entry, path, open, onCancel }: DirectLinkModalProps) {
|
export const DirectLinkModal = memo(function DirectLinkModal({ entry, path, open, onCancel }: DirectLinkModalProps) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [expiresIn, setExpiresIn] = useState(3600);
|
const [expiresIn, setExpiresIn] = useState(3600);
|
||||||
@@ -41,6 +56,13 @@ export const DirectLinkModal = memo(function DirectLinkModal({ entry, path, open
|
|||||||
navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(text);
|
||||||
message.success('已复制到剪贴板');
|
message.success('已复制到剪贴板');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCopyMarkdown = () => {
|
||||||
|
if (!entry || !link) return;
|
||||||
|
const markdownText = generateMarkdownLink(entry.name, link);
|
||||||
|
navigator.clipboard.writeText(markdownText);
|
||||||
|
message.success('Markdown 格式已复制到剪贴板');
|
||||||
|
};
|
||||||
|
|
||||||
const handleExpiresChange = (e: any) => {
|
const handleExpiresChange = (e: any) => {
|
||||||
setExpiresIn(e.target.value);
|
setExpiresIn(e.target.value);
|
||||||
@@ -69,9 +91,14 @@ export const DirectLinkModal = memo(function DirectLinkModal({ entry, path, open
|
|||||||
|
|
||||||
<div style={{ display: 'flex', gap: 8 }}>
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
<Input readOnly value={link} disabled={loading} placeholder={loading ? "正在生成链接..." : "链接将显示在这里"} />
|
<Input readOnly value={link} disabled={loading} placeholder={loading ? "正在生成链接..." : "链接将显示在这里"} />
|
||||||
<Button icon={<CopyOutlined />} onClick={() => handleCopy(link)} disabled={!link || loading}>
|
<Space.Compact>
|
||||||
复制
|
<Button icon={<CopyOutlined />} onClick={() => handleCopy(link)} disabled={!link || loading}>
|
||||||
</Button>
|
复制
|
||||||
|
</Button>
|
||||||
|
<Button icon={<FileMarkdownOutlined />} onClick={handleCopyMarkdown} disabled={!link || loading}>
|
||||||
|
复制 Markdown
|
||||||
|
</Button>
|
||||||
|
</Space.Compact>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user