Skip to content

Commit 5b35853

Browse files
authored
fix(backup-restore): add shares (#243)
1 parent 9f7e509 commit 5b35853

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

src/pages/manage/backup-restore.tsx

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
Resp,
2121
PEmptyResp,
2222
PPageResp,
23+
ShareInfo,
2324
} from "~/types"
2425
import { createSignal, For } from "solid-js"
2526
import crypto from "crypto-js"
@@ -30,6 +31,7 @@ interface Data {
3031
users: User[]
3132
storages: Storage[]
3233
metas: Meta[]
34+
shares: ShareInfo[]
3335
}
3436
type LogType = "success" | "error" | "info"
3537
const LogMap = {
@@ -83,12 +85,16 @@ const BackupRestore = () => {
8385
const [getStoragesLoading, getStorages] = useFetch(
8486
(): PPageResp<Storage> => r.get("/admin/storage/list"),
8587
)
88+
const [getSharesLoading, getShares] = useFetch(
89+
(): PPageResp<ShareInfo> => r.get("/share/list"),
90+
)
8691
const backupLoading = () => {
8792
return (
8893
getSettingsLoading() ||
8994
getUsersLoading() ||
9095
getMetasLoading() ||
91-
getStoragesLoading()
96+
getStoragesLoading() ||
97+
getSharesLoading()
9298
)
9399
}
94100
function encrypt(data: any, key: string): string {
@@ -119,13 +125,15 @@ const BackupRestore = () => {
119125
users: [],
120126
storages: [],
121127
metas: [],
128+
shares: [],
122129
}
123130
if (password() != "") allData.encrypted = encrypt("encrypted", password())
124131
for (const item of [
125132
{ name: "settings", fn: getSettings, page: false },
126133
{ name: "users", fn: getUsers, page: true },
127134
{ name: "storages", fn: getStorages, page: true },
128135
{ name: "metas", fn: getMetas, page: true },
136+
{ name: "shares", fn: getShares, page: true },
129137
] as const) {
130138
const resp = await item.fn()
131139
handleRespWithoutNotify(
@@ -187,6 +195,11 @@ const BackupRestore = () => {
187195
const [addMetaLoading, addMeta] = useFetch((meta: Meta): PEmptyResp => {
188196
return r.post(`/admin/meta/create`, meta)
189197
})
198+
const [addShareLoading, addShare] = useFetch(
199+
(share: ShareInfo): PEmptyResp => {
200+
return r.post(`/share/create`, share)
201+
},
202+
)
190203
const [updateUserLoading, updateUser] = useFetch((user: User): PEmptyResp => {
191204
return r.post(`/admin/user/update`, user)
192205
})
@@ -198,6 +211,11 @@ const BackupRestore = () => {
198211
const [updateMetaLoading, updateMeta] = useFetch((meta: Meta): PEmptyResp => {
199212
return r.post(`/admin/meta/update`, meta)
200213
})
214+
const [updateShareLoading, updateShare] = useFetch(
215+
(share: ShareInfo): PEmptyResp => {
216+
return r.post(`/share/update`, share)
217+
},
218+
)
201219
async function handleOvrData<T>(
202220
dataArray: T[],
203221
getDataFunc: { (): PResp<{ content: T[]; total: number }> },
@@ -252,9 +270,11 @@ const BackupRestore = () => {
252270
addUserLoading() ||
253271
addStorageLoading() ||
254272
addMetaLoading() ||
273+
addShareLoading() ||
255274
updateUserLoading() ||
256275
updateStorageLoading() ||
257-
updateMetaLoading()
276+
updateMetaLoading() ||
277+
updateShareLoading()
258278
)
259279
}
260280
const restore = async () => {
@@ -345,19 +365,49 @@ const BackupRestore = () => {
345365
"path",
346366
"manage.sidemenu.metas",
347367
)
368+
await handleOvrData(
369+
data.shares,
370+
getShares,
371+
addShare,
372+
updateShare,
373+
"id",
374+
"manage.sidemenu.shares",
375+
)
348376
} else {
349377
for (const item of [
350-
{ name: "users", fn: addUser, data: data.users, key: "username" },
378+
{
379+
name: "users",
380+
fn: addUser,
381+
data: data.users,
382+
key: "username",
383+
removeId: true,
384+
},
351385
{
352386
name: "storages",
353387
fn: addStorage,
354388
data: data.storages,
355389
key: "mount_path",
390+
removeId: true,
391+
},
392+
{
393+
name: "metas",
394+
fn: addMeta,
395+
data: data.metas,
396+
key: "path",
397+
removeId: true,
398+
},
399+
{
400+
name: "shares",
401+
fn: addShare,
402+
data: data.shares,
403+
key: "id",
404+
removeId: false,
356405
},
357-
{ name: "metas", fn: addMeta, data: data.metas, key: "path" },
358406
] as const) {
359407
for (const itemData of item.data || []) {
360-
itemData.id = 0
408+
if (item.removeId) {
409+
itemData.id = 0
410+
}
361411
handleRespWithoutNotify(
362412
await item.fn(itemData),
363413
() => {

0 commit comments

Comments
 (0)