refactor: remove unused fileType and downloadUrl properties from ArchiveComponent and ArchiveNode
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 18s

This commit is contained in:
2025-10-27 21:24:19 +08:00
parent 06426eb781
commit b4b36ae082
3 changed files with 7 additions and 62 deletions

View File

@@ -32,9 +32,7 @@ interface ArchiveComponentProps {
nodeKey: NodeKey; nodeKey: NodeKey;
fileName: string; fileName: string;
fileSize?: number; fileSize?: number;
fileType?: string;
fileKey?: string; fileKey?: string;
downloadUrl?: string;
uploadProgress?: number; uploadProgress?: number;
uploadError?: string; uploadError?: string;
uploadId?: string; uploadId?: string;
@@ -44,9 +42,7 @@ export default function ArchiveComponent({
nodeKey, nodeKey,
fileName, fileName,
fileSize, fileSize,
fileType,
fileKey, fileKey,
downloadUrl,
uploadProgress, uploadProgress,
uploadError, uploadError,
}: ArchiveComponentProps): JSX.Element { }: ArchiveComponentProps): JSX.Element {
@@ -55,14 +51,11 @@ export default function ArchiveComponent({
const containerRef = useRef<HTMLDivElement | null>(null); const containerRef = useRef<HTMLDivElement | null>(null);
const resolvedUrl = useMemo(() => { const resolvedUrl = useMemo(() => {
if (downloadUrl) {
return downloadUrl;
}
if (fileKey) { if (fileKey) {
return getS3Url(fileKey); return getS3Url(fileKey);
} }
return undefined; return undefined;
}, [downloadUrl, fileKey]); }, [fileKey]);
const readableSize = useMemo(() => formatFileSize(fileSize), [fileSize]); const readableSize = useMemo(() => formatFileSize(fileSize), [fileSize]);
const isUploading = uploadProgress !== undefined && uploadProgress < 100 && !uploadError; const isUploading = uploadProgress !== undefined && uploadProgress < 100 && !uploadError;
@@ -137,13 +130,12 @@ export default function ArchiveComponent({
setSelected(true); setSelected(true);
}} }}
> >
<div className="editor-archive-icon" aria-hidden>ZIP</div> <div className="editor-archive-icon" aria-hidden>
ZIP
</div>
<div className="editor-archive-details"> <div className="editor-archive-details">
<div className="editor-archive-title">{fileName}</div> <div className="editor-archive-title">{fileName}</div>
<div className="editor-archive-meta"> <div className="editor-archive-meta">Archive{readableSize ? `${readableSize}` : ''}</div>
{fileType || 'Archive'}
{readableSize ? `${readableSize}` : ''}
</div>
{resolvedUrl ? ( {resolvedUrl ? (
<a <a
className="editor-archive-link" className="editor-archive-link"

View File

@@ -18,9 +18,7 @@ const ArchiveComponent = lazy(() => import('./ArchiveComponent'));
export interface ArchivePayload { export interface ArchivePayload {
fileName: string; fileName: string;
fileSize?: number; fileSize?: number;
fileType?: string;
fileKey?: string; fileKey?: string;
downloadUrl?: string;
uploadProgress?: number; uploadProgress?: number;
uploadError?: string; uploadError?: string;
uploadId?: string; uploadId?: string;
@@ -35,18 +33,14 @@ function $convertArchiveElement(domNode: Node): DOMConversionOutput | null {
const fileName = element.textContent?.trim() || 'attachment'; const fileName = element.textContent?.trim() || 'attachment';
const fileSizeAttr = element.getAttribute('data-file-size'); const fileSizeAttr = element.getAttribute('data-file-size');
const fileType = element.getAttribute('data-file-type') || undefined;
const fileKey = element.getAttribute('data-file-key') || undefined; const fileKey = element.getAttribute('data-file-key') || undefined;
const downloadUrl = element.getAttribute('href') || undefined;
const fileSize = fileSizeAttr ? Number(fileSizeAttr) : undefined; const fileSize = fileSizeAttr ? Number(fileSizeAttr) : undefined;
const node = $createArchiveNode({ const node = $createArchiveNode({
fileName, fileName,
fileSize: Number.isFinite(fileSize) ? fileSize : undefined, fileSize: Number.isFinite(fileSize) ? fileSize : undefined,
fileType,
fileKey, fileKey,
downloadUrl,
}); });
return { node }; return { node };
@@ -56,9 +50,7 @@ export type SerializedArchiveNode = Spread<
{ {
fileName: string; fileName: string;
fileSize?: number; fileSize?: number;
fileType?: string;
fileKey?: string; fileKey?: string;
downloadUrl?: string;
}, },
SerializedLexicalNode SerializedLexicalNode
>; >;
@@ -66,9 +58,7 @@ export type SerializedArchiveNode = Spread<
export class ArchiveNode extends DecoratorNode<JSX.Element> { export class ArchiveNode extends DecoratorNode<JSX.Element> {
__fileName: string; __fileName: string;
__fileSize?: number; __fileSize?: number;
__fileType?: string;
__fileKey?: string; __fileKey?: string;
__downloadUrl?: string;
__uploadProgress?: number; __uploadProgress?: number;
__uploadError?: string; __uploadError?: string;
__uploadId?: string; __uploadId?: string;
@@ -81,9 +71,7 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
return new ArchiveNode( return new ArchiveNode(
node.__fileName, node.__fileName,
node.__fileSize, node.__fileSize,
node.__fileType,
node.__fileKey, node.__fileKey,
node.__downloadUrl,
node.__uploadProgress, node.__uploadProgress,
node.__uploadError, node.__uploadError,
node.__uploadId, node.__uploadId,
@@ -92,13 +80,11 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
} }
static importJSON(serializedNode: SerializedArchiveNode): ArchiveNode { static importJSON(serializedNode: SerializedArchiveNode): ArchiveNode {
const { fileName, fileSize, fileType, fileKey, downloadUrl } = serializedNode; const { fileName, fileSize, fileKey } = serializedNode;
return $createArchiveNode({ return $createArchiveNode({
fileName, fileName,
fileSize, fileSize,
fileType,
fileKey, fileKey,
downloadUrl,
}); });
} }
@@ -106,9 +92,7 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
return { return {
fileName: this.__fileName, fileName: this.__fileName,
fileSize: this.__fileSize, fileSize: this.__fileSize,
fileType: this.__fileType,
fileKey: this.__fileKey, fileKey: this.__fileKey,
downloadUrl: this.__downloadUrl,
type: 'archive', type: 'archive',
version: 1, version: 1,
}; };
@@ -117,13 +101,7 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
exportDOM(): DOMExportOutput { exportDOM(): DOMExportOutput {
const element = document.createElement('a'); const element = document.createElement('a');
element.textContent = this.__fileName; element.textContent = this.__fileName;
if (this.__downloadUrl) {
element.setAttribute('href', this.__downloadUrl);
}
element.setAttribute('data-lexical-archive', 'true'); element.setAttribute('data-lexical-archive', 'true');
if (this.__fileType) {
element.setAttribute('data-file-type', this.__fileType);
}
if (typeof this.__fileSize === 'number') { if (typeof this.__fileSize === 'number') {
element.setAttribute('data-file-size', String(this.__fileSize)); element.setAttribute('data-file-size', String(this.__fileSize));
} }
@@ -136,9 +114,7 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
constructor( constructor(
fileName: string, fileName: string,
fileSize?: number, fileSize?: number,
fileType?: string,
fileKey?: string, fileKey?: string,
downloadUrl?: string,
uploadProgress?: number, uploadProgress?: number,
uploadError?: string, uploadError?: string,
uploadId?: string, uploadId?: string,
@@ -147,9 +123,7 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
super(key); super(key);
this.__fileName = fileName; this.__fileName = fileName;
this.__fileSize = fileSize; this.__fileSize = fileSize;
this.__fileType = fileType;
this.__fileKey = fileKey; this.__fileKey = fileKey;
this.__downloadUrl = downloadUrl;
this.__uploadProgress = uploadProgress; this.__uploadProgress = uploadProgress;
this.__uploadError = uploadError; this.__uploadError = uploadError;
this.__uploadId = uploadId; this.__uploadId = uploadId;
@@ -176,18 +150,10 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
return this.__fileSize; return this.__fileSize;
} }
getFileType(): string | undefined {
return this.__fileType;
}
getFileKey(): string | undefined { getFileKey(): string | undefined {
return this.__fileKey; return this.__fileKey;
} }
getDownloadUrl(): string | undefined {
return this.__downloadUrl;
}
getUploadProgress(): number | undefined { getUploadProgress(): number | undefined {
return this.__uploadProgress; return this.__uploadProgress;
} }
@@ -205,11 +171,6 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
writable.__fileKey = fileKey; writable.__fileKey = fileKey;
} }
setDownloadUrl(downloadUrl: string): void {
const writable = this.getWritable();
writable.__downloadUrl = downloadUrl;
}
setUploadProgress(progress: number): void { setUploadProgress(progress: number): void {
const writable = this.getWritable(); const writable = this.getWritable();
writable.__uploadProgress = progress; writable.__uploadProgress = progress;
@@ -241,9 +202,7 @@ export class ArchiveNode extends DecoratorNode<JSX.Element> {
nodeKey={this.getKey()} nodeKey={this.getKey()}
fileName={this.__fileName} fileName={this.__fileName}
fileSize={this.__fileSize} fileSize={this.__fileSize}
fileType={this.__fileType}
fileKey={this.__fileKey} fileKey={this.__fileKey}
downloadUrl={this.__downloadUrl}
uploadProgress={this.__uploadProgress} uploadProgress={this.__uploadProgress}
uploadError={this.__uploadError} uploadError={this.__uploadError}
uploadId={this.__uploadId} uploadId={this.__uploadId}
@@ -257,9 +216,7 @@ export function $createArchiveNode(payload: ArchivePayload): ArchiveNode {
const { const {
fileName, fileName,
fileSize, fileSize,
fileType,
fileKey, fileKey,
downloadUrl,
uploadProgress, uploadProgress,
uploadError, uploadError,
uploadId, uploadId,
@@ -269,9 +226,7 @@ export function $createArchiveNode(payload: ArchivePayload): ArchiveNode {
new ArchiveNode( new ArchiveNode(
fileName, fileName,
fileSize, fileSize,
fileType,
fileKey, fileKey,
downloadUrl,
uploadProgress, uploadProgress,
uploadError, uploadError,
uploadId, uploadId,

View File

@@ -169,13 +169,12 @@ export default function DragDropPastePlugin(): null {
editor.dispatchCommand(INSERT_ARCHIVE_COMMAND, { editor.dispatchCommand(INSERT_ARCHIVE_COMMAND, {
fileName: file.name, fileName: file.name,
fileSize: file.size, fileSize: file.size,
fileType: file.type || undefined,
uploadProgress: 0, uploadProgress: 0,
uploadId, uploadId,
}); });
try { try {
const { fileKey, url } = await uploadBlogFile(file, (progress: number) => { const { fileKey } = await uploadBlogFile(file, (progress: number) => {
editor.update(() => { editor.update(() => {
const nodes = $nodesOfType(ArchiveNode); const nodes = $nodesOfType(ArchiveNode);
nodes.forEach((node: ArchiveNode) => { nodes.forEach((node: ArchiveNode) => {
@@ -191,7 +190,6 @@ export default function DragDropPastePlugin(): null {
nodes.forEach((node: ArchiveNode) => { nodes.forEach((node: ArchiveNode) => {
if (node.getUploadId() === uploadId) { if (node.getUploadId() === uploadId) {
node.setFileKey(fileKey); node.setFileKey(fileKey);
node.setDownloadUrl(url);
node.setUploadProgress(100); node.setUploadProgress(100);
node.setUploadError(undefined); node.setUploadError(undefined);
} }