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

View File

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

View File

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