Skip to content

Commit a2d46a4

Browse files
authored
feat(archive): support multipart archives (#263)
1 parent 8e523b8 commit a2d46a4

File tree

6 files changed

+21
-24
lines changed

6 files changed

+21
-24
lines changed

src/pages/home/previews/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { Obj, ObjType, UserMethods, UserPermissions } from "~/types"
44
import { ext } from "~/utils"
55
import { generateIframePreview } from "./iframe"
66
import { useRouter } from "~/hooks"
7-
import { getArchiveExtensions } from "~/store/archive"
7+
import { isArchive } from "~/store/archive"
88

9-
type Ext = string[] | "*" | (() => string[])
9+
type Ext = string[] | "*" | ((name: string) => boolean)
1010
type Prior = boolean | (() => boolean)
1111

12-
const extsContains = (exts: Ext | undefined, ext: string): boolean => {
12+
const extsContains = (exts: Ext | undefined, name: string): boolean => {
1313
if (exts === undefined) {
1414
return false
1515
} else if (exts === "*") {
1616
return true
1717
} else if (typeof exts === "function") {
18-
return (exts as () => string[])().includes(ext)
18+
return (exts as (name: string) => boolean)(name)
1919
} else {
20-
return (exts as string[]).includes(ext)
20+
return (exts as string[]).includes(ext(name).toLowerCase())
2121
}
2222
}
2323

@@ -129,12 +129,12 @@ const previews: Preview[] = [
129129
},
130130
{
131131
name: "Archive Preview",
132-
exts: () => {
132+
exts: (name: string) => {
133133
const index = UserPermissions.findIndex(
134134
(item) => item === "read_archives",
135135
)
136-
if (!UserMethods.can(me(), index)) return []
137-
return getArchiveExtensions()
136+
if (!UserMethods.can(me(), index)) return false
137+
return isArchive(name)
138138
},
139139
component: lazy(() => import("./archive")),
140140
prior: () => getSettingBool("preview_archives_by_default"),
@@ -157,7 +157,7 @@ export const getPreviews = (
157157
if (
158158
preview.type === file.type ||
159159
(typeOverride && preview.type === typeOverride) ||
160-
extsContains(preview.exts, ext(file.name).toLowerCase())
160+
extsContains(preview.exts, file.name)
161161
) {
162162
const r = { name: preview.name, component: preview.component }
163163
if (isPrior(preview.prior)) {

src/pages/home/toolbar/Center.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const Center = () => {
4141
backdropFilter: "blur(8px)",
4242
}}
4343
>
44-
<For each={["rename", "move", "copy", "delete"]}>
44+
<For each={["rename", "move", "copy", "delete", "decompress"]}>
4545
{(name) => {
4646
return (
4747
<CenterIcon

src/pages/home/toolbar/Decompress.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ export const Decompress = () => {
5656
const getPathAndName = () => {
5757
let path = pathname()
5858
if (innerPath() === "/") {
59-
return { path: path, name: selectedObjs()[0].name }
59+
return { path: path, name: selectedObjs().map((o) => o.name) }
6060
} else {
6161
let idx = path.lastIndexOf("/")
62-
return { path: path.slice(0, idx), name: path.slice(idx + 1) }
62+
return { path: path.slice(0, idx), name: [path.slice(idx + 1)] }
6363
}
6464
}
6565
return (

src/store/archive.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { ext } from "~/utils"
2-
31
let archiveExtensions: string[] = []
42

53
export const setArchiveExtensions = (extensions: string[]) => {
64
archiveExtensions = extensions
75
}
86

9-
export const getArchiveExtensions = () => archiveExtensions
10-
11-
export const isArchive = (name: string) => {
12-
return archiveExtensions.indexOf(ext(name).toLowerCase()) !== -1
7+
export const isArchive = (name: string): boolean => {
8+
name = name.toLowerCase()
9+
return archiveExtensions.some((v) => name.endsWith(v))
1310
}

src/utils/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export const fsArchiveList = (
177177
export const fsArchiveDecompress = (
178178
src_dir: string,
179179
dst_dir: string,
180-
name: string,
180+
name: string[],
181181
archive_pass = "",
182182
inner_path = "/",
183183
cache_full = true,

src/utils/icon.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
VscodeIconsFileTypePhotoshop2,
2929
} from "~/components"
3030
import { SiAsciinema } from "solid-icons/si"
31-
import { getArchiveExtensions } from "~/store/archive"
31+
import { isArchive } from "~/store/archive"
3232

3333
const iconMap = {
3434
"dmg,ipa,plist,tipa": BsApple,
@@ -49,14 +49,14 @@ const iconMap = {
4949
cast: SiAsciinema,
5050
}
5151

52-
export const getIconByTypeAndExt = (type: number, ext: string) => {
52+
export const getIconByTypeAndName = (type: number, name: string) => {
5353
if (type !== ObjType.FOLDER) {
5454
for (const [extensions, icon] of Object.entries(iconMap)) {
55-
if (extensions.split(",").includes(ext.toLowerCase())) {
55+
if (extensions.split(",").includes(ext(name).toLowerCase())) {
5656
return icon
5757
}
5858
}
59-
if (getArchiveExtensions().includes(ext)) {
59+
if (isArchive(name)) {
6060
return BsFileEarmarkZipFill
6161
}
6262
}
@@ -90,5 +90,5 @@ export const getIconByTypeAndExt = (type: number, ext: string) => {
9090
}
9191

9292
export const getIconByObj = (obj: Pick<Obj, "type" | "name">) => {
93-
return getIconByTypeAndExt(obj.type, ext(obj.name))
93+
return getIconByTypeAndName(obj.type, obj.name)
9494
}

0 commit comments

Comments
 (0)