MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / reupStorage

Function reupStorage

src/controller/storage/storage.ts:19–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17
18//列举存储信息
19async function reupStorage() {
20 try {
21 const storageListTemp: StorageList[] = []
22 const storagesToDelete: string[] = []
23
24 //rclone
25 try {
26 const dump = await rclone_api_post('/config/dump')
27 for (const storageName in dump) {
28 const space = await getStorageSpace(storageName)
29
30 // 检查是否是失效的内部存储(标记为 -2)
31 if (space.total === -2 && storageName.includes('.netmount-')) {
32 console.warn(`Detected invalid internal storage: ${storageName}, will cleanup`)
33 storagesToDelete.push(storageName)
34 continue // 不添加到列表
35 }
36
37 storageListTemp.push({
38 framework: 'rclone',
39 name: storageName,
40 type: dump[storageName].type,
41 space: space,
42 hide: storageName.includes(openlistInfo.markInRclone),
43 })
44 }
45
46 // 清理失效的内部存储
47 for (const name of storagesToDelete) {
48 try {
49 console.log(`Cleaning up invalid internal storage: ${name}`)
50 await rclone_api_post('/config/delete', { name }, true)
51 console.log(`Successfully deleted: ${name}`)
52 } catch (deleteError) {
53 console.error(`Failed to delete ${name}:`, deleteError)
54 }
55 }
56 } catch (rcloneError) {
57 console.error('Failed to fetch rclone storage list:', rcloneError)
58 // rclone 失败不影响 openlist 的加载
59 }
60
61 //openlist
62 try {
63 const response = await openlist_api_get('/api/admin/storage/list')
64 const list = (response?.data?.content as OpenlistStorageItem[]) || []
65 for (const storage of list) {
66 // 数据验证
67 if (!storage || !storage.mount_path) {
68 console.warn('Invalid storage data from OpenList:', storage)
69 continue
70 }
71 storageListTemp.push({
72 framework: 'openlist',
73 name: storage.mount_path.substring(1),
74 type: storage.driver,
75 other: {
76 openlist: {

Callers 3

createStorageFunction · 0.90
delStorageFunction · 0.85

Calls 3

rclone_api_postFunction · 0.90
openlist_api_getFunction · 0.90
getStorageSpaceFunction · 0.85

Tested by

no test coverage detected