0.3.5 共享功能修复

This commit is contained in:
liaibo
2026-01-24 12:32:51 +08:00
parent 25923f308c
commit 3c3f407f4b
44 changed files with 3754 additions and 420 deletions
@@ -18,6 +18,7 @@ import { useImagePicker } from "@/components/media/image-picker-context";
import type { MediaKind } from "@/types/media";
import { emitAssetsChanged } from "@/lib/events";
import { getMnoteRuntimeConfig } from "@/lib/runtime-config";
import { useCurrentDocumentStore } from "@/store/current-document";
import {
DropdownMenu,
DropdownMenuContent,
@@ -281,6 +282,7 @@ const MediaBlockContent = ({ block, editor }: any) => {
window.alert("缺少 ONLYOFFICE 地址,请在 .env.local 配置 NEXT_PUBLIC_ONLYOFFICE_BASE_URL");
return;
}
const currentDocReadOnly = useCurrentDocumentStore.getState().readOnly;
try {
const assetId = await resolveAssetId();
const res = assetId
@@ -299,16 +301,33 @@ const MediaBlockContent = ({ block, editor }: any) => {
target.searchParams.set("fileUrl", signedUrl);
target.searchParams.set("fileName", displayFileName);
target.searchParams.set("fileType", extension || "docx");
const docId = resolveDocumentId();
if (docId) {
target.searchParams.set("documentId", docId);
}
if (assetId) {
target.searchParams.set("assetId", assetId);
}
target.searchParams.set("mode", currentDocReadOnly ? "view" : "edit");
window.open(target.toString(), "_blank", "noopener,noreferrer");
} catch (error) {
window.alert((error as Error).message);
}
};
const currentDocumentId = useCurrentDocumentStore((state) => state.documentId);
const currentDisableDownload = useCurrentDocumentStore((state) => state.disableDownload);
const resolvedDocIdForRestriction = resolveDocumentId();
const downloadDisabled =
Boolean(currentDisableDownload) &&
Boolean(resolvedDocIdForRestriction) &&
String(currentDocumentId ?? "") === String(resolvedDocIdForRestriction);
const downloadAsset = async () => {
if (downloadDisabled) {
window.alert("该页面已禁止下载");
return;
}
const url = await resolveLatestFileUrl();
if (!url) return;
const anchor = document.createElement("a");
@@ -449,8 +468,9 @@ const MediaBlockContent = ({ block, editor }: any) => {
type="button"
data-testid="wolai-media-file-download"
className="inline-flex h-6 w-6 items-center justify-center rounded-[4px] text-[#9B9A97] hover:bg-[#EDEDED] hover:text-[#37352F]"
aria-label="下载"
title="下载"
aria-label={downloadDisabled ? "已禁止下载" : "下载"}
title={downloadDisabled ? "已禁止下载" : "下载"}
disabled={downloadDisabled}
onMouseDown={(e) => {
e.preventDefault();
e.stopPropagation();
@@ -497,11 +517,12 @@ const MediaBlockContent = ({ block, editor }: any) => {
</DropdownMenuItem>
{isOfficeDoc && <DropdownMenuItem onClick={() => void openWithOnlyOffice()}>使 ONLYOFFICE </DropdownMenuItem>}
<DropdownMenuItem
disabled={downloadDisabled}
onClick={() => {
void downloadAsset();
}}
>
{downloadDisabled ? "已禁止下载" : "下载到本地"}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleDeleteAsset}></DropdownMenuItem>
@@ -570,14 +591,16 @@ const MediaBlockContent = ({ block, editor }: any) => {
icon: <LinkIcon className="h-4 w-4" />,
onClick: handleLink,
},
{
key: "download",
label: `下载${typeLabel}`,
icon: <Download className="h-4 w-4" />,
onClick: () => {
void downloadAsset();
},
},
!downloadDisabled
? {
key: "download",
label: `下载${typeLabel}`,
icon: <Download className="h-4 w-4" />,
onClick: () => {
void downloadAsset();
},
}
: null,
{
key: "delete",
label: `删除${typeLabel}`,
@@ -657,11 +680,12 @@ const MediaBlockContent = ({ block, editor }: any) => {
</DropdownMenuItem>
<DropdownMenuItem
disabled={downloadDisabled}
onClick={() => {
void downloadAsset();
}}
>
{downloadDisabled ? "已禁止下载" : "下载到本地"}
</DropdownMenuItem>
{canTriggerOcr && (
<>