Skip to content

Commit

Permalink
暂存
Browse files Browse the repository at this point in the history
  • Loading branch information
luoluoTH committed Dec 25, 2024
1 parent 53dacf2 commit abe2e8d
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 70 deletions.
84 changes: 42 additions & 42 deletions app/renderer/src/main/src/components/MilkdownEditor/Block/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,49 +150,49 @@ export const BlockView: React.FC<BlockViewProps> = (props) => {
command(state, dispatch)
})
break
case "上传文件":
ipcRenderer
.invoke("openDialog", {
title: "请选择文件",
properties: ["openFile"]
})
.then((data: {filePaths: string[]}) => {
const filesLength = data.filePaths.length
if (filesLength) {
const path = data.filePaths[0].replace(/\\/g, "\\")
getLocalFileLinkInfo(path).then((res) => {
if (res.size > FileMaxSize) {
yakitNotify("error", "文件大小不能超过1G")
return
}
const index = path.lastIndexOf(".")
const fileType = path.substring(index, path.length)
if (imgTypes.includes(fileType)) {
if (res.size > ImgMaxSize) {
yakitNotify("error", "图片大小不能超过1M")
return
}
httpUploadImgPath({path, type, filedHash: notepadHash})
.then((src) => {
action(
callCommand(insertImageBlockCommand.key, {
src,
alt: path,
title: ""
})
)
})
.catch((e) => {
yakitNotify("error", `上传图片失败:${e}`)
})
} else {
action(callCommand(fileCommand.key, {id: "0", path, notepadHash}))
}
})
}
})
// case "上传文件":
// ipcRenderer
// .invoke("openDialog", {
// title: "请选择文件",
// properties: ["openFile"]
// })
// .then((data: {filePaths: string[]}) => {
// const filesLength = data.filePaths.length
// if (filesLength) {
// const path = data.filePaths[0].replace(/\\/g, "\\")
// getLocalFileLinkInfo(path).then((res) => {
// if (res.size > FileMaxSize) {
// yakitNotify("error", "文件大小不能超过1G")
// return
// }
// const index = path.lastIndexOf(".")
// const fileType = path.substring(index, path.length)
// if (imgTypes.includes(fileType)) {
// if (res.size > ImgMaxSize) {
// yakitNotify("error", "图片大小不能超过1M")
// return
// }
// httpUploadImgPath({path, type, filedHash: notepadHash})
// .then((src) => {
// action(
// callCommand(insertImageBlockCommand.key, {
// src,
// alt: path,
// title: ""
// })
// )
// })
// .catch((e) => {
// yakitNotify("error", `上传图片失败:${e}`)
// })
// } else {
// action(callCommand(fileCommand.key, {id: "0", path, notepadHash}))
// }
// })
// }
// })

break
// break
case "分割线":
action((ctx) => {
const command = clearContentAndAddBlockType(hrSchema.type(ctx))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class CollabManager extends ObservableV2<CollabManagerEvents> {
})

this.wsProvider.once("online-user-count", (onlineUserCount: number) => {
console.log("wsProvider-online-user-count", onlineUserCount)
if (onlineUserCount < 2 && this.collabStatus.isSynced) {
this.collabService.applyTemplate(template).connect()
} else if (this.collabStatus.isSynced) {
Expand All @@ -139,12 +140,14 @@ export class CollabManager extends ObservableV2<CollabManagerEvents> {
})

this.wsProvider.on("saveStatus", ({saveStatus}) => {
console.log("wsProvider-saveStatus", saveStatus)
this.setCollabStatus({...this.collabStatus, saveStatus})
})
// 监听在线用户数据
this.wsProvider?.awareness?.on("change", (payload) => {
// 获取当前所有用户的状态
const users = this.getOnlineUser()
console.log("wsProvider-awareness-change", users)
this.setOnlineUsers([...users])
})
}
Expand Down Expand Up @@ -212,7 +215,9 @@ export class CollabManager extends ObservableV2<CollabManagerEvents> {
token: this.wsRequest.token
}
if (this.wsProvider && this.wsProvider?.ws && this.wsProvider.ws?.readyState === WebSocket.OPEN) {
this.wsProvider?.ws?.send(Buffer.from(JSON.stringify(v)))
const sendValueString = JSON.stringify(v)
console.log("sendContent-valueString", sendValueString)
this.wsProvider?.ws?.send(Buffer.from(sendValueString))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const CustomFile: React.FC = () => {
const [loading, setLoading] = useState<boolean>(false)
const [errorReason, setErrorReason] = useState<string>("")
const [downFileInfo, setDownFileInfo] = useState<DownFileInfoProps>()
const [visibleDownFiles, setVisibleDownFiles] = useState<boolean>(false)
const [queryFileErrorInfo, setQueryFileErrorInfo] = useState<string>("")
const [loadingRefresh, setLoadingRefresh] = useState<boolean>(false)

Expand Down Expand Up @@ -198,7 +197,6 @@ export const CustomFile: React.FC = () => {
saveDialogAndGetLocalFileInfo(fileId).then((v) => {
setDownFileInfo(v)
setFileInfo({...fileInfo, path: v.path})
setVisibleDownFiles(true)
})
}
const onCopyLink = useMemoizedFn((e) => {
Expand Down Expand Up @@ -252,7 +250,6 @@ export const CustomFile: React.FC = () => {
})
const onCancelDownload = useMemoizedFn(() => {
setFileInfo({...fileInfo, path: ""})
setVisibleDownFiles(false)
setDownFileInfo(undefined)
})
const onRefreshFileInfo = useMemoizedFn((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import {useStore} from "@/store"
import {CollabManager, CollabUserInfo} from "./CollabManager"
import emiter from "@/utils/eventBus/eventBus"

import {YakitButton} from "../yakitUI/YakitButton/YakitButton"
import {collab, collabServiceCtx} from "@milkdown/plugin-collab"
import {showYakitModal} from "../yakitUI/YakitModal/YakitModalConfirm"
import {tokenOverdue} from "@/services/fetch"
Expand All @@ -88,8 +87,6 @@ const markdown1 = `
#ggg
:file[]{fileId="https://yakit-online.oss-accelerate.aliyuncs.com/notepade/2e80f8894f904134fb795f0731bed428-1732088835089&*&app.zip"}
![1.00](
Maybe more? ![]()
Expand Down Expand Up @@ -192,6 +189,7 @@ const CustomMilkdown: React.FC<CustomMilkdownProps> = React.memo((props) => {
images.map(async (image) => {
const alt = image.name
try {
console.log("uploadConfig-image", image)
const src = await uploadImg(image)
return schema.nodes["image-block"].createAndFill({
src,
Expand Down Expand Up @@ -232,6 +230,7 @@ const CustomMilkdown: React.FC<CustomMilkdownProps> = React.memo((props) => {
</svg>
`,
onUpload: async (image: File) => {
console.log("imageBlockConfig-image", image)
const url = uploadImg(image)
return url
}
Expand All @@ -258,6 +257,7 @@ const CustomMilkdown: React.FC<CustomMilkdownProps> = React.memo((props) => {
<circle cx="14" cy="8" r="1" fill="currentColor" />
</svg> `,
onUpload: async (image: File) => {
console.log("inlineImageConfig-image", image)
const url = uploadImg(image)
return url
}
Expand Down Expand Up @@ -356,7 +356,8 @@ const CustomMilkdown: React.FC<CustomMilkdownProps> = React.memo((props) => {
filename: image.name || "image.png",
contentType: image.type || "image/png"
},
type: "notepad"
type: collabParams.enableCollab ? "notepad" : "img",
filedHash: collabParams.milkdownHash
})
return src
} catch (error) {
Expand Down Expand Up @@ -490,6 +491,7 @@ const CustomMilkdown: React.FC<CustomMilkdownProps> = React.memo((props) => {
useMemoizedFn((ctx) => {
// 获取 trackDeletePlugin 插件共享的值
const urls = ctx.get(deletedFileUrlsCtx)
console.log("onDeleteFiles", urls)
if (urls.length > 0) {
setInterval(1000)
} else {
Expand Down Expand Up @@ -519,8 +521,10 @@ const CustomMilkdown: React.FC<CustomMilkdownProps> = React.memo((props) => {
newDeletedFiles.push(element)
}
}
console.log("onDeleteFiles-deletedFiles", deletedFiles)
if (fileName.length > 0) {
setInterval(undefined)
console.log("onDeleteFiles-fileName", fileName)
httpDeleteOSSResource({file_name: fileName}, true).finally(() => {
// 暂不考虑删除失败的情况
get()?.action((ctx) => ctx.update(deletedFileUrlsCtx, () => [...newDeletedFiles]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const setupWS = (provider: WebsocketProvider) => {
const bytes = Buffer.from(event.data).toString()
const data: NotepadWsRequest = JSON.parse(bytes)
const yjsParams = Buffer.from(data.yjsParams, "base64")
console.log("websocket.onmessage-data", data)
if (!!data.params.userCount && data.params.docType === notepadActions.join) {
// 目前加入类型的消息会修改在线人数,用来做连接文档的初始化内容
provider.onlineUserCount = data.params.userCount
Expand All @@ -136,12 +137,15 @@ const setupWS = (provider: WebsocketProvider) => {
} catch (error) {}
}
websocket.onerror = (event) => {
console.log("websocket.onerror-event", event)
provider.emit("connection-error", [event, provider])
}
websocket.onclose = (event) => {
console.log("websocket.onclose-event", event)
closeWebsocketConnection(provider, websocket, event)
}
websocket.onopen = () => {
console.log("websocket.onopen")
provider.wsLastMessageReceived = time.getUnixTime()
provider.wsconnecting = false
provider.wsconnected = true
Expand Down Expand Up @@ -189,7 +193,9 @@ const setupWS = (provider: WebsocketProvider) => {
* @param {CloseEvent} event
*/
const closeWebsocketConnection = (provider: WebsocketProvider, ws: WebSocket, event?: CloseEvent) => {
console.log("closeWebsocketConnection------1", ws, provider.ws)
if (ws === provider.ws) {
console.log("closeWebsocketConnection------2", event)
if (event) provider.emit("connection-close", [event, provider])
provider.ws = null
ws.close()
Expand Down Expand Up @@ -375,6 +381,7 @@ export class WebsocketProvider extends ObservableV2<ObservableEvents> {
if (resyncInterval > 0) {
this._resyncInterval = setInterval(() => {
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
console.log("_resyncInterval")
// resend sync step 1
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageSync)
Expand Down Expand Up @@ -408,6 +415,7 @@ export class WebsocketProvider extends ObservableV2<ObservableEvents> {
token
}
const jsonString = JSON.stringify(value)
console.log("getSendData", jsonString)
const finalArrayBuffer = Buffer.from(jsonString)
return finalArrayBuffer
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export const defaultBlockList: BlockListProps[] = [
label: "高亮",
description: "高亮: :::success空格"
},
{
id: 10,
icon: <OutlinePaperclipIcon />,
label: "上传文件",
description: "上传文件"
},
// {
// id: 10,
// icon: <OutlinePaperclipIcon />,
// label: "上传文件",
// description: "上传文件"
// },
{
id: 11,
icon: <IconFlipVertical />,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {$command, $nodeSchema, $nodeAttr} from "@milkdown/utils"
import {Attrs} from "@milkdown/kit/prose/model"
import {TextSelection} from "@milkdown/kit/prose/state"
import { getTypeAndNameByPath } from "../CustomFile/CustomFile"
import { getLocalFileLinkInfo } from "../CustomFile/utils"
import { UploadOSSStartProps } from "@/hook/useUploadOSS/useUploadOSS"
import { uploadBigFileType } from "@/hook/useUploadOSS/constants"

export const fileCustomId = "file-custom"
export const fileCustomAttr = $nodeAttr("file-custom", () => ({
Expand Down Expand Up @@ -77,12 +81,25 @@ export const fileCustomSchema = $nodeSchema(fileCustomId, (ctx) => ({
}
}))

export const fileCommand = $command(`command-${fileCustomId}`, (ctx) => (props) => (state, dispatch) => {
export const fileCommand = $command(`command-${fileCustomId}`, (ctx) => (props: any) => (state, dispatch) => {
const {selection, tr} = state
if (!(selection instanceof TextSelection)) return false

const {from, to} = selection
const fragment = state.doc.slice(from, to).content // 获取 Fragment

const path = props.path.replace(/\\/g, "\\")

// if (props.path) {
// getLocalFileLinkInfo(path).then((fileInfo) => {
// const value: UploadOSSStartProps = {
// filePath:path,
// filedHash: props?.notepadHash || "",
// type: uploadBigFileType.notepad
// }
// // onStartUpload(value)
// })
// }
dispatch?.(
tr
.setMeta(fileCustomId, true)
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/main/src/pages/EnterpriseJudgeLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const EnterpriseJudgeLogin: React.FC<EnterpriseJudgeLoginProps> = (props) => {
</div>
) : (
<>
{activateLicense ? (
{true ? (
<div style={{width: 480, margin: "0 auto", paddingTop: 200, height: "100%"}}>
<ConfigPrivateDomain
enterpriseLogin={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const apiGetUserSearch: APIFunc<UserSearchQuery, API.UserOrdinaryResponse
*/
export const apiSetNotepadPermission: APIFunc<API.PostNotepadPermissionRequest, API.ActionSucceeded> = (query) => {
return new Promise((resolve, reject) => {
console.log("apiSetNotepadPermission-query", query)
try {
NetWorkApi<API.PostNotepadPermissionRequest, API.ActionSucceeded>({
method: "post",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const apiGetNotepadList: APIFunc<GetNotepadRequestProps, API.GetNotepadRe
*/
export const apiSaveNotepadList: APIFunc<API.PostNotepadRequest, string> = (params, hiddenError) => {
return new Promise((resolve, reject) => {
console.log("apiSaveNotepadList", params)
NetWorkApi<API.PostNotepadRequest, string>({
method: "post",
url: "notepad",
Expand Down Expand Up @@ -159,8 +160,10 @@ export const onBaseNotepadDown: APIFunc<API.NotepadDownloadRequest, SaveDialogRe
const params: API.NotepadDownloadRequest = {
...value
}
console.log("onBaseNotepadDown-params", params)
apiDownloadNotepad(params)
.then((res) => {
console.log("onBaseNotepadDown-res", res)
saveDialogAndGetLocalFileInfo((res as string) || "")
.then(resolve)
.catch(reject)
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/src/main/src/routes/newRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ export const RouteToPage: (props: PageItemProps) => ReactNode = (props) => {
const {routeKey, yakScriptId, params} = props
switch (routeKey) {
case YakitRoute.NewHome:
return <Home />
// return <Home />
return <NotepadManage />
case YakitRoute.HTTPHacker:
return (
<Suspense fallback={<PageLoading />}>
Expand Down
Loading

0 comments on commit abe2e8d

Please sign in to comment.