Skip to content

Commit

Permalink
[preprocessor/proofmode] move proofmode into /preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 11, 2024
1 parent dd9c68c commit 4f0d8b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions preprocessor/folder/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/jackc/pgx/v5/pgxpool"
"github.com/starlinglab/integrity-v2/config"
"github.com/starlinglab/integrity-v2/util"
proofmode "github.com/starlinglab/integrity-v2/preprocessor/proofmode"
"github.com/starlinglab/integrity-v2/webhook"
)

Expand All @@ -27,7 +27,7 @@ var (

// getProofModeFileMetadatas reads a proofmode file and returns a list of metadata
func getProofModeFileMetadatas(filePath string) ([]map[string]any, error) {
assets, err := util.ReadAndVerifyProofModeMetadata(filePath)
assets, err := proofmode.ReadAndVerifyMetadata(filePath)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func checkFileType(filePath string) (string, string, error) {
}
mediaType := http.DetectContentType(buffer[:n])
if mediaType == "application/zip" {
isProofMode := util.CheckIsProofModeFile(filePath)
isProofMode := proofmode.CheckIsProofModeFile(filePath)
if isProofMode {
fileType = "proofmode"
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func handleNewFile(pgPool *pgxpool.Pool, filePath string, project *ProjectQueryR
return "", fmt.Errorf("error opening zip file %s: %v", filePath, err)
}
defer zipListing.Close()
fileMap, _, err := util.GetProofModeZipFiles(zipListing)
fileMap, _, err := proofmode.GetMapOfZipFiles(zipListing)
if err != nil {
if err := setFileStatusError(pgPool, filePath, err.Error()); err != nil {
log.Println("error setting file status to error:", err)
Expand Down
16 changes: 8 additions & 8 deletions util/proofmode.go → preprocessor/proofmode/proofmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ProofModeFileData struct {

// validateAndParseProofModeFileSignatures reads a file and verify
// its asset and metadata hash and signature
func validateAndParseProofModeFileSignatures(fileMap map[string]*zip.File, fileName string, fileSha string, jsonMetadataBytes []byte) (
func validateAndParseFileSignatures(fileMap map[string]*zip.File, fileName string, fileSha string, jsonMetadataBytes []byte) (
*ProofModeFileData,
error,
) {
Expand Down Expand Up @@ -191,7 +191,7 @@ func validateAndParseProofModeFileSignatures(fileMap map[string]*zip.File, fileN

// parseProofModeBundleAssetInfo reads the files in the zip
// and returns a map of files and the json metadata files
func parseProofModeBundleAssetInfo(zipReader *zip.ReadCloser) (map[string]*zip.File, [][]byte, error) {
func parseBundleAssetInfo(zipReader *zip.ReadCloser) (map[string]*zip.File, [][]byte, error) {
var jsonFilesBytes [][]byte
fileMap := map[string]*zip.File{}
for _, file := range zipReader.File {
Expand Down Expand Up @@ -232,9 +232,9 @@ func CheckIsProofModeFile(filePath string) bool {
return found
}

// GetProofModeZipFiles reads the files mapping and JSON metadata in the zip
func GetProofModeZipFiles(zipListing *zip.ReadCloser) (map[string]*zip.File, [][]byte, error) {
fileMap, jsonFilesBytes, err := parseProofModeBundleAssetInfo(zipListing)
// GetMapOfZipFiles reads the files mapping and JSON metadata in the zip
func GetMapOfZipFiles(zipListing *zip.ReadCloser) (map[string]*zip.File, [][]byte, error) {
fileMap, jsonFilesBytes, err := parseBundleAssetInfo(zipListing)
if err != nil {
return nil, nil, err
}
Expand All @@ -246,13 +246,13 @@ func GetProofModeZipFiles(zipListing *zip.ReadCloser) (map[string]*zip.File, [][

// ReadAndVerifyProofModeMetadata reads and verifies a proof mode file
// and returns its metadata
func ReadAndVerifyProofModeMetadata(filePath string) ([]*ProofModeFileData, error) {
func ReadAndVerifyMetadata(filePath string) ([]*ProofModeFileData, error) {
zipListing, err := zip.OpenReader(filePath)
if err != nil {
return nil, err
}
defer zipListing.Close()
fileMap, jsonFilesBytes, err := GetProofModeZipFiles(zipListing)
fileMap, jsonFilesBytes, err := GetMapOfZipFiles(zipListing)
if err != nil {
return nil, err
}
Expand All @@ -265,7 +265,7 @@ func ReadAndVerifyProofModeMetadata(filePath string) ([]*ProofModeFileData, erro
return nil, err
}
filename := filepath.Base(metadata.FilePath)
assetData, err := validateAndParseProofModeFileSignatures(fileMap, filename, metadata.Sha256, jsonFileBytes)
assetData, err := validateAndParseFileSignatures(fileMap, filename, metadata.Sha256, jsonFileBytes)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4f0d8b1

Please sign in to comment.