Skip to content

Commit

Permalink
Added an uploader for notebooks. (Velocidex#1639)
Browse files Browse the repository at this point in the history
Now notebooks can use the upload() function. This will save files
within the notebook directory.

The files may be retrieved by exporting the notebook to a zip file or
individually.
  • Loading branch information
scudette authored Mar 9, 2022
1 parent 335d681 commit 96382cb
Show file tree
Hide file tree
Showing 22 changed files with 500 additions and 131 deletions.
2 changes: 1 addition & 1 deletion accessors/file_store/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (self FileSystem) Open(path string) (http.File, error) {
return nil, os.ErrNotExist
}

components := path_specs.NewSafeFilestorePath(
components := path_specs.NewUnsafeFilestorePath(
utils.SplitComponents(path)...).
SetType(api.PATH_TYPE_FILESTORE_ANY)
fd, err := self.file_store.ReadFile(components)
Expand Down
3 changes: 2 additions & 1 deletion accessors/registry/registry_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ func (self RegFileSystemAccessor) OpenWithOSPath(path *accessors.OSPath) (
}

// Keys do not have any data.
return NewValueBuffer([]byte{}, stat), nil
serialized, _ := json.Marshal(stat.Data)
return NewValueBuffer(serialized, stat), nil
}

func (self RegFileSystemAccessor) Open(path string) (
Expand Down
35 changes: 34 additions & 1 deletion api/notebooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (self *ApiServer) GetNotebooks(
notebook.AvailableDownloads, _ = getAvailableDownloadFiles(self.config,
notebook_path_manager.HtmlExport().Dir())

if in.IncludeUploads {
notebook.AvailableUploads, _ = getAvailableUploadFiles(self.config,
notebook_path_manager)
}

notebook.Timelines = getAvailableTimelines(
self.config, notebook_path_manager)

Expand Down Expand Up @@ -1105,14 +1110,42 @@ func getAvailableDownloadFiles(config_obj *config_proto.Config,
Type: api.GetExtensionForFilestore(ps),
Path: ps.AsClientPath(),
Size: uint64(item.Size()),
Date: fmt.Sprintf("%v", item.ModTime()),
Date: item.ModTime().UTC().Format(time.RFC3339),
Complete: is_complete(ps.Base()),
})
}

return result, nil
}

func getAvailableUploadFiles(config_obj *config_proto.Config,
notebook_path_manager *paths.NotebookPathManager) (
*api_proto.AvailableDownloads, error) {
result := &api_proto.AvailableDownloads{}

file_store_factory := file_store.GetFileStore(config_obj)
files, err := file_store_factory.ListDirectory(
notebook_path_manager.UploadsDir())
if err != nil {
return nil, err
}

for _, item := range files {
ps := item.PathSpec()

result.Files = append(result.Files, &api_proto.AvailableDownloadFile{
Name: item.Name(),
Type: api.GetExtensionForFilestore(ps),
Path: ps.AsClientPath(),
Size: uint64(item.Size()),
Date: item.ModTime().UTC().Format(time.RFC3339),
Complete: true,
})
}

return result, nil
}

func updateCellContents(
ctx context.Context,
config_obj *config_proto.Config,
Expand Down
28 changes: 14 additions & 14 deletions api/proto/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96382cb

Please sign in to comment.