Skip to content

Commit

Permalink
Resolved merge conflict by removing release.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Oct 3, 2023
2 parents c3c7a24 + 7369838 commit c83b307
Show file tree
Hide file tree
Showing 19 changed files with 599 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.1.0
- uses: actions/setup-go@v4
with:
go-version: 1.20.2 # The Go version to download (if necessary) and use.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.1.0

# Runs djdefi/cloc-action
- name: Count Lines of Code (cloc)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: 1.20.2
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.1.0
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.1.0
- uses: actions/setup-go@v4
with:
go-version: 1.21.0 # The Go version to download (if necessary) and use.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ seed-phrase of the API.
```shell
git clone https://github.com/JackalLabs/jackalapi.git
cd jackalapi
git checkout v0.1.0
git checkout v0.2.0
go make install
```

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ go 1.20

require (
github.com/JackalLabs/jackalgo v0.0.3
github.com/rs/cors v1.10.0
github.com/rs/cors v1.10.1
github.com/stretchr/testify v1.8.4
github.com/uptrace/bunrouter v1.0.20
)

Expand Down Expand Up @@ -112,7 +113,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,8 @@ github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE=
github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/cors v1.10.0 h1:62NOS1h+r8p1mW6FM0FSB0exioXLhd/sh15KpjWBZ+8=
github.com/rs/cors v1.10.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
122 changes: 122 additions & 0 deletions japicore/fidRouteHandling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package japicore

import (
"fmt"
"net/http"
"strings"

"github.com/JackalLabs/jackalapi/jutils"
"github.com/uptrace/bunrouter"
)

func (j JApiCore) IpfsHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
var allBytes []byte

operatingRoot := jutils.LoadEnvVarOrFallback("JAPI_IPFS_ROOT", "s/JAPI/IPFS")
gateway := jutils.LoadEnvVarOrFallback("JAPI_IPFS_GATEWAY", "https://ipfs.io/ipfs/")
toClone := false
cloneHeader := req.Header.Get("J-Clone-Ipfs")
if strings.ToLower(cloneHeader) == "true" {
toClone = true
}

id := req.Param("id")
if len(id) == 0 {
warning := "Failed to get IPFS CID"
return jutils.ProcessCustomHttpError("processUpload", warning, 500, w)
}

cid := strings.ReplaceAll(id, "/", "_")

handler, err := j.FileIo.DownloadFile(fmt.Sprintf("%s/%s", operatingRoot, cid))
if err != nil {
if !toClone {
warning := "IPFS CID Not Found"
return jutils.ProcessCustomHttpError("DownloadFile", warning, 404, w)
}

byteBuffer, err := httpGetFileRequest(w, gateway, cid)
if err != nil {
jutils.ProcessHttpError("httpGetFileRequest", err, 404, w)
return err
}

clonedBytes1, clonedBytes2, err := jutils.CloneByteSlice(byteBuffer.Bytes())
if err != nil {
jutils.ProcessHttpError("httpGetFileRequest", err, 404, w)
return err
}
allBytes = clonedBytes2

fid := processUpload(w, j.FileIo, clonedBytes1, cid, operatingRoot, j.FileIoQueue)
if len(fid) == 0 {
warning := "Failed to get FID post-upload"
return jutils.ProcessCustomHttpError("IpfsHandler", warning, 500, w)
}
} else {
allBytes = handler.GetFile().Buffer().Bytes()
}
_, err = w.Write(allBytes)
if err != nil {
jutils.ProcessError("WWriteError for IpfsHandler", err)
return err
}
return nil
}
}

func (j JApiCore) DownloadByFidHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
id := req.Param("id")
if len(id) == 0 {
warning := "Failed to get FileName"
return jutils.ProcessCustomHttpError("DownloadByFidHandler", warning, 404, w)
}
fid := strings.ReplaceAll(id, "/", "_")

handler, err := j.FileIo.DownloadFileFromFid(fid)
if err != nil {
return err
}

fileBytes := handler.GetFile().Buffer().Bytes()
_, err = w.Write(fileBytes)
if err != nil {
jutils.ProcessError("WWriteError for DownloadByFidHandler", err)
}
return nil
}
}

func (j JApiCore) DeleteByFidHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
id := req.Param("id")
if len(id) == 0 {
warning := "Failed to get FileName"
return jutils.ProcessCustomHttpError("processUpload", warning, 400, w)
}

fid := strings.ReplaceAll(id, "/", "_")
fmt.Println(fid)

// TODO - update after deletion by fid is added to jackalgo

//folder, err := j.FileIo.DownloadFolder(j.FileIoQueue.GetRoot("bulk"))
//if err != nil {
// jutils.ProcessHttpError("DeleteFile", err, 404, w)
// return err
//}
//
//err = j.FileIo.DeleteTargets([]string{fid}, folder)
//if err != nil {
// jutils.ProcessHttpError("DeleteFile", err, 500, w)
// return err
//}

// message := createJsonResponse("Deletion complete")
message := createJsonResponse("Deletion Not Implemented")
jutils.SimpleWriteJSON(w, message)
return nil
}
}
42 changes: 42 additions & 0 deletions japicore/miscRouteHandling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package japicore

import (
"fmt"
"net/http"

"github.com/JackalLabs/jackalapi/jutils"
"github.com/uptrace/bunrouter"
)

var (
Version = "v0.0.0"
Module = "Jackal API Core"
)

func (j JApiCore) Handler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
return nil
}
}

func (j JApiCore) RouteNotFoundHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
warning := fmt.Sprintf("%s is not an availble route", req.URL.Path)
return jutils.ProcessCustomHttpError("MethodNotAllowedHandler", warning, 404, w)
}
}

func (j JApiCore) MethodNotAllowedHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
warning := fmt.Sprintf("%s method not availble for \"%s\"", req.URL.Path, req.Method)
return jutils.ProcessCustomHttpError("MethodNotAllowedHandler", warning, 405, w)
}
}

func (j JApiCore) VersionHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
message := createJsonResponse("")
jutils.SimpleWriteJSON(w, message)
return nil
}
}
Loading

0 comments on commit c83b307

Please sign in to comment.