Skip to content

Commit

Permalink
chore: Cancel clear image
Browse files Browse the repository at this point in the history
  • Loading branch information
1943time committed Jan 29, 2025
1 parent 4856776 commit fac9cb7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 67 deletions.
14 changes: 7 additions & 7 deletions src/renderer/src/components/editor/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ export const Nav = observer(() => {
core.file.convertRemoteImages(core.tree.openedNote!)
}
},
{
text: t('claerImage'),
disabled: !core.tree.root,
click: () => {
core.file.clear()
}
},
// {
// text: t('claerImage'),
// disabled: !core.tree.root,
// click: () => {
// core.file.clear()
// }
// },
{ hr: true },
{
text: isMac ? 'Reveal in Finder' : 'Reveal in File Explorer',
Expand Down
120 changes: 60 additions & 60 deletions src/renderer/src/store/logic/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,68 +31,68 @@ export class FileAssets {
}
}

clear() {
if (!this.core.tree.root) return
openConfirmDialog$.next({
title: i18n.t('note'),
description: i18n.t('clearImageTip'),
onConfirm: async () => {
let imgDirs: (IFileItem | ISpaceNode)[] = []
const base = basename(this.core.tree.root!.imageFolder || '')
if (this.core.tree.root?.relative) {
const stack = this.core.tree.root?.children!.slice() || []
while (stack.length) {
const item = stack.shift()!
if (item.folder && item.children) {
stack.unshift(...item.children)
if (item.filename === base || !base || base === './' || base === '.') {
imgDirs.push(item)
}
}
}
} else {
const item = this.core.tree.root?.children?.find(item => item.filePath === join(this.core.tree.root?.filePath || '', this.core.tree.root?.imageFolder || '.images'))
if (item) imgDirs.push(item)
}
// clear() {
// if (!this.core.tree.root) return
// openConfirmDialog$.next({
// title: i18n.t('note'),
// description: i18n.t('clearImageTip'),
// onConfirm: async () => {
// let imgDirs: (IFileItem | ISpaceNode)[] = []
// const base = basename(this.core.tree.root!.imageFolder || '')
// if (this.core.tree.root?.relative) {
// const stack = this.core.tree.root?.children!.slice() || []
// while (stack.length) {
// const item = stack.shift()!
// if (item.folder && item.children) {
// stack.unshift(...item.children)
// if (item.filename === base || !base || base === './' || base === '.') {
// imgDirs.push(item)
// }
// }
// }
// } else {
// const item = this.core.tree.root?.children?.find(item => item.filePath === join(this.core.tree.root?.filePath || '', this.core.tree.root?.imageFolder || '.images'))
// if (item) imgDirs.push(item)
// }

if (!base || base === '.') {
imgDirs.push(this.core.tree.root!)
}
// if (!base || base === '.') {
// imgDirs.push(this.core.tree.root!)
// }

if (imgDirs.length) {
const usedImages = new Set<string>()
const stack = this.core.tree.root?.children!.slice() || []
while (stack.length) {
const item = stack.pop()!
if (item.folder) {
stack.push(...item.children!.slice())
} else {
if (item.ext === 'md') {
this.findMedia(item.filePath, item.schema || [], usedImages)
}
}
}
for (let dir of imgDirs) {
const images = await readdir(dir.filePath)
const remove = new Set<string>()
for (let img of images) {
const path = join(dir.filePath, img)
if (!usedImages.has(path)) {
remove.add(path)
MainApi.moveToTrash(path)
}
}
runInAction(() => {
dir.children = dir.children?.filter(img => {
return !remove.has(img.filePath)
})
})
}
this.core.message.success(i18n.t('clearSuccess'))
}
}
})
}
// if (imgDirs.length) {
// const usedImages = new Set<string>()
// const stack = this.core.tree.root?.children!.slice() || []
// while (stack.length) {
// const item = stack.pop()!
// if (item.folder) {
// stack.push(...item.children!.slice())
// } else {
// if (item.ext === 'md') {
// this.findMedia(item.filePath, item.schema || [], usedImages)
// }
// }
// }
// for (let dir of imgDirs) {
// const images = await readdir(dir.filePath)
// const remove = new Set<string>()
// for (let img of images) {
// const path = join(dir.filePath, img)
// if (!usedImages.has(path)) {
// remove.add(path)
// MainApi.moveToTrash(path)
// }
// }
// runInAction(() => {
// dir.children = dir.children?.filter(img => {
// return !remove.has(img.filePath)
// })
// })
// }
// this.core.message.success(i18n.t('clearSuccess'))
// }
// }
// })
// }
async convertRemoteImages(node: IFileItem) {
if (node.ext === 'md') {
const schema = node.schema
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/store/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'path'
import { db } from './db'
import {IApi} from '@inkdown/client'
import { Core } from './core'
import { isWindows } from '../utils'
export class Publish {
access_key_id = ''
access_key_secret = ''
Expand All @@ -25,6 +26,7 @@ export class Publish {
return new IApi({
fetch: window.fetch.bind(window),
mode: 'inkdown',
os: isWindows ? 'windows' : 'other',
getFileData: async (path) => {
try {
const buffer = await window.api.fs.readFile(path)
Expand Down

0 comments on commit fac9cb7

Please sign in to comment.