-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from singnet/lighthouse
feat: filecoin integration
- Loading branch information
Showing
12 changed files
with
239 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ipfsutils | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const ( | ||
IpfsPrefix = "ipfs://" | ||
FilecoinPrefix = "filecoin://" | ||
) | ||
|
||
func ReadFile(hash string) (rawFile []byte, err error) { | ||
if strings.HasPrefix(hash, FilecoinPrefix) { | ||
rawFile, err = GetLighthouseFile(formatHash(hash)) | ||
} else { | ||
rawFile, err = GetIpfsFile(formatHash(hash)) | ||
} | ||
return rawFile, err | ||
} | ||
|
||
func formatHash(hash string) string { | ||
zap.L().Debug("Before Formatting", zap.String("metadataHash", hash)) | ||
hash = strings.Replace(hash, IpfsPrefix, "", -1) | ||
hash = strings.Replace(hash, FilecoinPrefix, "", -1) | ||
hash = removeSpecialCharacters(hash) | ||
zap.L().Debug("After Formatting", zap.String("metadataHash", hash)) | ||
return hash | ||
} | ||
|
||
func removeSpecialCharacters(pString string) string { | ||
reg := regexp.MustCompile("[^a-zA-Z0-9=]") | ||
return reg.ReplaceAllString(pString, "") | ||
} |
Oops, something went wrong.