mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-11 18:10:10 +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:
@@ -1,6 +1,6 @@
|
||||
import { memo, useState, useEffect } from 'react';
|
||||
import { Modal, Radio, message, Button, Typography, Input } from 'antd';
|
||||
import { CopyOutlined } from '@ant-design/icons';
|
||||
import { Modal, Radio, message, Button, Typography, Input, Space } from 'antd';
|
||||
import { CopyOutlined, FileMarkdownOutlined } from '@ant-design/icons';
|
||||
import type { VfsEntry } from '../../../../api/client';
|
||||
import { vfsApi } from '../../../../api/client';
|
||||
|
||||
@@ -11,6 +11,21 @@ interface DirectLinkModalProps {
|
||||
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) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [expiresIn, setExpiresIn] = useState(3600);
|
||||
@@ -41,6 +56,13 @@ export const DirectLinkModal = memo(function DirectLinkModal({ entry, path, open
|
||||
navigator.clipboard.writeText(text);
|
||||
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) => {
|
||||
setExpiresIn(e.target.value);
|
||||
@@ -69,9 +91,14 @@ export const DirectLinkModal = memo(function DirectLinkModal({ entry, path, open
|
||||
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<Input readOnly value={link} disabled={loading} placeholder={loading ? "正在生成链接..." : "链接将显示在这里"} />
|
||||
<Button icon={<CopyOutlined />} onClick={() => handleCopy(link)} disabled={!link || loading}>
|
||||
复制
|
||||
</Button>
|
||||
<Space.Compact>
|
||||
<Button icon={<CopyOutlined />} onClick={() => handleCopy(link)} disabled={!link || loading}>
|
||||
复制
|
||||
</Button>
|
||||
<Button icon={<FileMarkdownOutlined />} onClick={handleCopyMarkdown} disabled={!link || loading}>
|
||||
复制 Markdown
|
||||
</Button>
|
||||
</Space.Compact>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user