Skip to content

Commit

Permalink
Merge pull request #645 from stratosnet/dev
Browse files Browse the repository at this point in the history
Release v0.12.0 extra
  • Loading branch information
jinzuo-qsn authored May 27, 2024
2 parents a6e7e34 + ce1743b commit b9c7cee
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
18 changes: 15 additions & 3 deletions pp/api/internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ package api

import (
"context"
"net/http"

"github.com/stratosnet/sds/framework/utils/httpserv"
"github.com/stratosnet/sds/pp/setting"
)

func StartHTTPServ(ctx context.Context) {
httpServ := httpserv.MyNewHTTPServ(setting.Config.Streaming.InternalPort)
httpServ.MyRoute("/streamVideoStorageInfo/", streamVideoInfoCache)
httpServ.MyRoute("/streamSharedVideoStorageInfo/", streamSharedVideoInfoCache)
httpServ.MyRoute("/streamVideo/", streamVideoP2P)
httpServ.MyRoute("/streamVideoStorageInfo/", corsHandler(streamVideoInfoCache))
httpServ.MyRoute("/streamSharedVideoStorageInfo/", corsHandler(streamSharedVideoInfoCache))
httpServ.MyRoute("/streamVideo/", corsHandler(streamVideoP2P))
httpServ.MyRoute("/streamVideoStorageInfoHttp/", streamVideoInfoHttp)
httpServ.MyRoute("/streamVideoHttp/", streamVideoHttp)
httpServ.MyRoute("/clearStreamTask/", clearStreamTask)
httpServ.MyStart(ctx)
}

func corsHandler(h func(w http.ResponseWriter, req *http.Request)) func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
} else {
h(w, r)
}
}
}
22 changes: 17 additions & 5 deletions pp/api/rest/rest_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"context"
"net/http"

"github.com/stratosnet/sds/framework/utils/httpserv"
"github.com/stratosnet/sds/pp/api"
Expand All @@ -10,10 +11,21 @@ import (

func StartHTTPServ(ctx context.Context) {
httpServ := httpserv.MyNewHTTPServ(setting.Config.Streaming.RestPort)
httpServ.MyRoute("/getOzone/", api.GetOzone)
httpServ.MyRoute("/prepareVideoFileCache/", api.PrepareVideoFileCache)
httpServ.MyRoute("/prepareSharedVideoFileCache/", api.PrepareSharedVideoFileCache)
httpServ.MyRoute("/getVideoSliceCache/", api.GetVideoSliceCache)
httpServ.MyRoute("/findVideoSlice/", api.GetVideoSlice)
httpServ.MyRoute("/getOzone/", corsHandler(api.GetOzone))
httpServ.MyRoute("/prepareVideoFileCache/", corsHandler(api.PrepareVideoFileCache))
httpServ.MyRoute("/prepareSharedVideoFileCache/", corsHandler(api.PrepareSharedVideoFileCache))
httpServ.MyRoute("/getVideoSliceCache/", corsHandler(api.GetVideoSliceCache))
httpServ.MyRoute("/findVideoSlice/", corsHandler(api.GetVideoSlice))
httpServ.MyStart(ctx)
}

func corsHandler(h func(w http.ResponseWriter, req *http.Request)) func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
} else {
h(w, r)
}
}
}
7 changes: 6 additions & 1 deletion pp/api/stream_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ func streamSharedVideoInfoCacheHelper(w http.ResponseWriter, req *http.Request,
return
}

walletSign, reqTime, _ := getSignature(req, shareLink)
walletSign, reqTime, err := getSignature(req, shareLink)
if err != nil {
w.WriteHeader(setting.FAILCode)
_, _ = w.Write(httpserv.NewErrorJson(setting.FAILCode, err.Error()).ToBytes())
return
}

reqGetSharedMsg := reqGetSharedMsg(pptypes.GetShareFile{ShareLink: shareLink, Password: password}, walletSign, reqTime)
res := namespace.RpcPubApi().RequestGetVideoShared(ctx, reqGetSharedMsg)
Expand Down
3 changes: 2 additions & 1 deletion pp/namespace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,13 @@ func (api *rpcPubApi) RequestGetShared(ctx context.Context, param rpc_api.ParamR
p2pserver.GetP2pServer(reqCtx).SendMessageToSPServer(reqCtx, req, header.ReqGetShareFile)

// the application gives FileShareResult type of result
key := shareLink.ShareLink + task.LOCAL_REQID
found := false
for !found {
select {
case <-ctx.Done():
return rpc_api.Result{Return: rpc_api.TIME_OUT}
case result := <-file.SubscribeFileShareResult(shareLink.ShareLink):
case result := <-file.SubscribeFileShareResult(key):
file.UnsubscribeFileShareResult(shareLink.ShareLink)
if result == nil {
return rpc_api.Result{Return: rpc_api.INTERNAL_DATA_FAILURE}
Expand Down

0 comments on commit b9c7cee

Please sign in to comment.