MCPcopy
hub / github.com/MauriceNino/dashdot / mapToStorageLayout

Function mapToStorageLayout

apps/server/src/data/storage/static.ts:107–163  ·  view source on GitHub ↗
(
  hostWin32: boolean,
  disks: Disk[],
  blocks: Block[],
  sizes: Size[],
)

Source from the content-addressed store, hash-verified

105};
106
107export const mapToStorageLayout = (
108 hostWin32: boolean,
109 disks: Disk[],
110 blocks: Block[],
111 sizes: Size[],
112): StorageInfo => {
113 const diskBlocks = getDiskBlocks(blocks);
114
115 const mapDiskBlock = (acc: StorageInfo, diskBlock: Block) => {
116 const device = diskBlock.name;
117 const nativeDisk = getNativeDisk(disks, diskBlock);
118 const raidInfo = getRaidInfo(blocks, diskBlock, hostWin32);
119
120 const disk: StorageInfo[number]['disks'][number] = {
121 device: hostWin32 ? (diskBlock.device ?? '') : device,
122 brand: nativeDisk.vendor,
123 type: getDiskType(nativeDisk.type, nativeDisk.interfaceType),
124 };
125
126 if (raidInfo != null) {
127 const existingRaid = acc.find((r) => r.raidName === raidInfo.name);
128 if (existingRaid) {
129 existingRaid.disks.push(disk);
130 } else {
131 acc.push({
132 raidLabel: raidInfo.label,
133 raidName: raidInfo.name,
134 raidType: raidInfo.type,
135 size: raidInfo.size,
136 disks: [disk],
137 });
138 }
139 } else {
140 acc.push({
141 size: nativeDisk.size,
142 disks: [disk],
143 });
144 }
145
146 return acc;
147 };
148
149 const blockLayout = (
150 hostWin32
151 ? diskBlocks.reduce((acc, curr) => {
152 if (curr.device && !acc.some((b) => b.device === curr.device)) {
153 acc.push(curr);
154 }
155 return acc;
156 }, [] as Block[])
157 : diskBlocks
158 ).reduce(mapDiskBlock, [] as StorageInfo);
159
160 const sizesLayout = getVirtualMountsLayout(sizes);
161
162 return blockLayout.concat(sizesLayout);
163};
164

Callers 2

static.tsFile · 0.85

Calls 2

getDiskBlocksFunction · 0.85
getVirtualMountsLayoutFunction · 0.85

Tested by

no test coverage detected