-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFlatDirectory.sol
38 lines (29 loc) · 1.13 KB
/
FlatDirectory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC5018.sol";
contract FlatDirectory is ERC5018 {
bytes public defaultFile = "";
constructor(uint8 slotLimit, uint32 maxChunkSize, address storageAddress) ERC5018(slotLimit, maxChunkSize, storageAddress) {}
function resolveMode() external pure virtual returns (bytes32) {
return "manual";
}
fallback(bytes calldata pathinfo) external returns (bytes memory) {
bytes memory content;
if (pathinfo.length == 0) {
// TODO: redirect to "/"?
return bytes("");
} else if (pathinfo[0] != 0x2f) {
// Should not happen since manual mode will have prefix "/" like "/....."
return bytes("incorrect path");
}
if (pathinfo[pathinfo.length - 1] == 0x2f) {
(content, ) = read(bytes.concat(pathinfo[1:], defaultFile));
} else {
(content, ) = read(pathinfo[1:]);
}
StorageHelper.returnBytesInplace(content);
}
function setDefault(bytes memory _defaultFile) public onlyOwner virtual {
defaultFile = _defaultFile;
}
}