Skip to content

Commit

Permalink
update PreviewFile and DeleteFile (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Sep 10, 2024
1 parent 94827e2 commit 435f91a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
20 changes: 20 additions & 0 deletions node/delete_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
package node

import (
"errors"
"net/http"
"os"
"path/filepath"

"github.com/CESSProject/DeOSS/common/utils"
"github.com/CESSProject/cess-go-sdk/chain"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -46,6 +50,22 @@ func (n *Node) DeleteFile(c *gin.Context) {
return
}
n.RemoveCacheRecord(fid)

n.Logdel("info", clientIp+" DeleteFile suc: "+blockHash)
c.JSON(200, map[string]string{"block hash": blockHash})

_, err = n.QueryFile(fid, -1)
if err != nil {
if errors.Is(err, chain.ERR_RPC_EMPTY_VALUE) {
data, err := n.ParseTrackFile(fid)
if err == nil {
for _, segment := range data.Segment {
for _, fragment := range segment.FragmentHash {
os.Remove(fragment)
}
}
}
os.Remove(filepath.Join(n.fileDir, fid))
}
}
}
22 changes: 18 additions & 4 deletions node/open_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ func (n *Node) PreviewFile(c *gin.Context) {
if clientIp == "" {
clientIp = c.ClientIP()
}
temp := strings.Split(fid, ".")
fid = temp[0]
if format == "" && len(temp) > 1 {
format = temp[1]

if strings.Contains(fid, ".") {
temp := strings.Split(fid, ".")
fid = temp[0]
if format == "" && len(temp) > 1 {
format = temp[1]
}
} else {
if len(fid) > chain.FileHashLen {
tmp_fid := fid[:chain.FileHashLen]
format = fid[chain.FileHashLen:]
fid = tmp_fid
} else if len(fid) < chain.FileHashLen {
n.Logopen("err", clientIp+" invalid fid: "+fid)
c.JSON(404, "invalid fid")
return
}
}

n.Logopen("info", clientIp+" open file: "+fid+" account: "+account+" format: "+format+" Range: "+rgn)

var err error
Expand Down

0 comments on commit 435f91a

Please sign in to comment.