Skip to content

Commit

Permalink
fix: window 环境下压缩文件判断错误
Browse files Browse the repository at this point in the history
  • Loading branch information
rowthan committed Jul 27, 2024
1 parent be2695f commit 2f3c2d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
26 changes: 9 additions & 17 deletions apps/web/components/backup/extension/ImportAndExport.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import React, {type ReactNode, useState} from 'react'
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip"
import CloseSvg from 'assets/svg/close.svg'
import ImportFilter from './ImportFilter'
import ExportFilter from './ExportFilter'
import {
BackupData,
BackupVersion,
Expand All @@ -17,7 +9,6 @@ import {
Step
} from '@pagenote/shared/lib/@types/data'
import {toast} from 'utils/toast'
import {Button} from "@/components/ui/button";
import {
Dialog,
DialogContent,
Expand All @@ -30,9 +21,7 @@ import {UploadIcon} from '@radix-ui/react-icons'
import {readFiles, resolveImportString} from "../../../utils/file";
import {LightFormatFromWebPage} from "../../../utils/backup";
import md5 from "md5";
import TipInfo from "../../TipInfo";
import TipInfoSvg from "../../../assets/svg/info.svg";
import extApi from "@pagenote/shared/lib/pagenote-api";
import useWhoAmi from "../../../hooks/useWhoAmi";

interface Props {
children?: ReactNode
Expand All @@ -42,7 +31,8 @@ interface Props {
export default function ImportAndExport(props: Props) {
const { children,exportBy = 'web' } = props
const [backupData, setBackupData] = useState<BackupData | null>(null)
const [showConfirmModal, setShowConfirmModal] = useState(false)

const [showConfirmModal, setShowConfirmModal] = useState(false);

function onImportBackup(files: FileList) {
const selectedFile = files || []
Expand All @@ -56,7 +46,7 @@ export default function ImportAndExport(props: Props) {
}
for(let i = 0; i < list.length; i++){
try{
const backupData = resolveImportString(list[i].text, list[i].type)
const backupData = resolveImportString(list[i].text, list[i].type);
if (backupData) {
// 格式初始化
mergeBackupData.items = mergeBackupData.items || []
Expand All @@ -65,8 +55,9 @@ export default function ImportAndExport(props: Props) {
mergeBackupData.items.push(...backupData.items)
}

// 低版本数据处理
// 低版本数据处理 不再维护
if((backupData.version || 0) < BackupVersion.version7){
console.warn('正在使用低版本数据,',backupData)
if(backupData.pages && backupData.pages.length > 0){
mergeBackupData.items.push({
db: "lightpage",
Expand Down Expand Up @@ -170,8 +161,9 @@ export default function ImportAndExport(props: Props) {
} else {
toast('解析备份文件失败', 'error')
}
}catch (e) {
toast('部分文件解析失败', 'error')
}catch (e:any) {
console.error(e,'解析文件失败')
toast('部分文件解析失败'+e.message, 'error')
}
}

Expand Down
5 changes: 3 additions & 2 deletions apps/web/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export function readFiles(files: FileList):Promise<FileParse[]> {
text: base64Image,
type: fileType,
})
}else if(fileType === 'application/zip'){
}else if(fileType.includes('zip')){
console.log('解压文件 开始')
const zipFileList = await unzipFile(file);
result.push(...zipFileList);
} else{
Expand Down Expand Up @@ -134,7 +135,7 @@ export const resolveImportString = function (inputStr: string, type: string):Bac
data = JSON.parse(inputStr);
return data
}catch (e) {
console.warn('低版本数据,二次解码处理中。不推荐使用,请使用最新版本导出数据')
console.warn('初次尝试解析文件异常',inputStr)
}

/**
Expand Down

0 comments on commit 2f3c2d1

Please sign in to comment.