-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dataobj): Add a Explorer UI for dataobj (#15908)
- Loading branch information
1 parent
93cee63
commit 9b1407e
Showing
43 changed files
with
5,357 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package explorer | ||
|
||
import "flag" | ||
|
||
// Config holds the configuration for the explorer service | ||
type Config struct { | ||
// StorageBucketPrefix is the prefix to use when exploring the bucket | ||
StorageBucketPrefix string `yaml:"storage_bucket_prefix"` | ||
} | ||
|
||
// RegisterFlags registers the flags for the explorer configuration | ||
func (cfg *Config) RegisterFlags(f *flag.FlagSet) { | ||
f.StringVar(&cfg.StorageBucketPrefix, "dataobj-explorer.storage-bucket-prefix", "dataobj/", "Prefix to use when exploring the bucket. If set, only objects under this prefix will be visible.") | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>DataObj Explorer</title> | ||
<script type="module" crossorigin src="/dataobj/explorer/assets/index-CWzBrpZu.js"></script> | ||
<link rel="stylesheet" crossorigin href="/dataobj/explorer/assets/style-Dz5w-Rts.css"> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package explorer | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"path" | ||
|
||
"github.com/go-kit/log/level" | ||
) | ||
|
||
func (s *Service) handleDownload(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodGet { | ||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
filename := r.URL.Query().Get("file") | ||
if filename == "" { | ||
http.Error(w, "file parameter is required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
attrs, err := s.bucket.Attributes(r.Context(), filename) | ||
if err != nil { | ||
level.Error(s.logger).Log("msg", "failed to get file attributes", "file", filename, "err", err) | ||
http.Error(w, fmt.Sprintf("failed to get file: %v", err), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
reader, err := s.bucket.Get(r.Context(), filename) | ||
if err != nil { | ||
level.Error(s.logger).Log("msg", "failed to get file", "file", filename, "err", err) | ||
http.Error(w, fmt.Sprintf("failed to get file: %v", err), http.StatusInternalServerError) | ||
return | ||
} | ||
defer reader.Close() | ||
|
||
w.Header().Set("Content-Type", "application/octet-stream") | ||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, path.Base(filename))) | ||
w.Header().Set("Content-Length", fmt.Sprintf("%d", attrs.Size)) | ||
|
||
if _, err := io.Copy(w, reader); err != nil { | ||
level.Error(s.logger).Log("msg", "failed to stream file", "file", filename, "err", err) | ||
return | ||
} | ||
} |
Oops, something went wrong.