GMOD / Apollo3

JBrowse 2 plugin for editing annotations on an Apollo server
Apache License 2.0
7 stars 4 forks source link

Add files module/controller/service #79

Closed garrettjstevens closed 2 years ago

garrettjstevens commented 2 years ago

From discussion with @rbuels, add an endpoint for managing files, specifically at first a way to upload files. The user will supply a file and it will be saved to disk and the following information will be saved in MongoDB:

type File { checksum: number; basename: string; type: 'text/x-gff3' | 'text/x-fasta' }

For example:

{ checksum: 12453446236435, basename: 'mygenome.fasta', type: 'text/x-fasta' }

The file will be saved in a compressed format. The idea is that once a file is uploaded successfully, it can be referenced in change objects, perhaps looking something like this:

{ type: 'AddReferenceSequencesFromFile', fileChecksum: 12453446236435 }
garrettjstevens commented 2 years ago

xref https://github.com/GMOD/jbrowse-plugin-apollo/issues/65

garrettjstevens commented 2 years ago

This will need a new endpoint "files," which to match the other modules can be created by running yarn dlx @nestjs/cli generate resource files in the packages/apollo-collaboration-server/ directory.

This will also need a MongoDB schema that has:

interface File {
  basename: string // the name of the file that was uploaded
  checksum: number // or string, depending on hash used
  type: 'text/x-gff3' | 'text/x-fasta' // depends on what kind of file was uploaded
}

There will be /files/fasta and /files/gff3 endpoints. Users can POST a new file to those endpoints, GET a list of files, and GET a file with e.g. /files/fasta/507f1f77bcf86cd799439011.

The location the files are saved to should be configurable in the ENV file. The file name that it is saved as internally should be the file ID, e.g. 507f1f77bcf86cd799439011, not the file name of the uploaded file. (See next comments for what the file name should be.)

rbuels commented 2 years ago

One thing to clarify about this is that if the same file is uploaded multiple times (possibly with different names) it is only stored once, because it’s stored name is a hash of its contents.

garrettjstevens commented 2 years ago

Good point, I forgot about that. So the file name should be the hash, not the (MongoDB) file ID. I'll correct that in my above comment.