Skip to content

Commit

Permalink
Tweak publish app
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Sep 12, 2019
1 parent d578798 commit dba4889
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func InstallRoutes(proxyService *proxy.Service, r *mux.Router) {
r.HandleFunc("/content/claims/{uri}/{claim}/{filename}", captureErrors(ContentByClaimsURI))
r.HandleFunc("/content/url", captureErrors(ContentByURL))

actionsRouter := r.Path("/api/v1/actions").Subrouter()
actionsRouter := r.PathPrefix("/api/v1/actions").Subrouter()
authenticator := users.NewAuthenticator(users.NewUserService())
lbrynetPublisher := &publish.LbrynetPublisher{Service: proxyService}
UploadHandler := publish.NewUploadHandler(config.GetPublishSourceDir(), lbrynetPublisher)
actionsRouter.HandleFunc("/publish", authenticator.Wrap(UploadHandler.Handle)).Headers(users.TokenHeader, "")
actionsRouter.HandleFunc("/publish", authenticator.Wrap(UploadHandler.Handle)) //.Headers(users.TokenHeader, "")
}
12 changes: 6 additions & 6 deletions app/publish/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func TestUploadHandler(t *testing.T) {

writer := multipart.NewWriter(body)

fileBody, err := writer.CreateFormFile(fileField, "lbry_auto_test_file")
fileBody, err := writer.CreateFormFile(FileFieldName, "lbry_auto_test_file")
require.Nil(t, err)
_, err = io.Copy(fileBody, readSeeker)
require.Nil(t, err)

jsonPayload, err := writer.CreateFormField(jsonrpcPayloadField)
jsonPayload, err := writer.CreateFormField(JSONRPCFieldName)
require.Nil(t, err)
jsonPayload.Write([]byte(lbrynet.ExampleStreamCreateRequest))

Expand Down Expand Up @@ -87,11 +87,11 @@ func TestUploadHandlerAuthRequired(t *testing.T) {

writer := multipart.NewWriter(body)

fileBody, err := writer.CreateFormFile(fileField, "lbry_auto_test_file")
fileBody, err := writer.CreateFormFile(FileFieldName, "lbry_auto_test_file")
require.Nil(t, err)
io.Copy(fileBody, readSeeker)

jsonPayload, err := writer.CreateFormField(jsonrpcPayloadField)
jsonPayload, err := writer.CreateFormField(JSONRPCFieldName)
require.Nil(t, err)
jsonPayload.Write([]byte(lbrynet.ExampleStreamCreateRequest))

Expand Down Expand Up @@ -126,11 +126,11 @@ func TestUploadHandlerSystemError(t *testing.T) {

writer := multipart.NewWriter(body)

fileBody, err := writer.CreateFormFile(fileField, "lbry_auto_test_file")
fileBody, err := writer.CreateFormFile(FileFieldName, "lbry_auto_test_file")
require.Nil(t, err)
io.Copy(fileBody, readSeeker)

jsonPayload, err := writer.CreateFormField(jsonrpcPayloadField)
jsonPayload, err := writer.CreateFormField(JSONRPCFieldName)
require.Nil(t, err)
jsonPayload.Write([]byte(lbrynet.ExampleStreamCreateRequest))

Expand Down
8 changes: 4 additions & 4 deletions app/publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

const uploadPath = "/tmp"

const fileField = "file"
const jsonrpcPayloadField = "json_payload"
const FileFieldName = "file"
const JSONRPCFieldName = "json_payload"

const fileNameParam = "file_path"

Expand Down Expand Up @@ -80,7 +80,7 @@ func (h UploadHandler) handleUpload(r *users.AuthenticatedRequest) (*os.File, er
if err != nil {
return nil, err
}
log.Debugf("saved uploaded file %v (%v bytes written)", f.Name(), numWritten)
log.Infof("saved uploaded file %v (%v bytes written)", f.Name(), numWritten)

if err := f.Close(); err != nil {
return nil, err
Expand Down Expand Up @@ -111,7 +111,7 @@ func (h UploadHandler) Handle(w http.ResponseWriter, r *users.AuthenticatedReque
return
}

response := h.Publisher.Publish(f.Name(), r.AccountID, []byte(r.FormValue(jsonrpcPayloadField)))
response := h.Publisher.Publish(f.Name(), r.AccountID, []byte(r.FormValue(JSONRPCFieldName)))
w.Write(response)
}

Expand Down
3 changes: 2 additions & 1 deletion lbrytv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ AccountsEnabled: 1
MetricsAddress: :2112
MetricsPath: /metrics

PublishSourceDir: ./.lbrynet/publish
PublishSourceDir: /storage/published
BlobFilesDir: /storage/lbrynet/blobfiles

0 comments on commit dba4889

Please sign in to comment.