@openneuro/server 4.12.1 → 4.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openneuro/server",
3
- "version": "4.12.1",
3
+ "version": "4.12.2",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@apollo/client": "3.4.17",
20
20
  "@elastic/elasticsearch": "7.15.0",
21
- "@openneuro/search": "^4.12.1",
21
+ "@openneuro/search": "^4.12.2",
22
22
  "@passport-next/passport-google-oauth2": "^1.0.0",
23
23
  "@sentry/node": "^4.5.3",
24
24
  "apollo-server": "2.25.4",
@@ -105,5 +105,5 @@
105
105
  "publishConfig": {
106
106
  "access": "public"
107
107
  },
108
- "gitHead": "a3709e0ef915f32d178dc0fb1b9d6dacfd5f9e1d"
108
+ "gitHead": "d36002753b049a7d4d2fc8edd904c57a0bd35596"
109
109
  }
@@ -1,5 +1,4 @@
1
1
  import request from 'superagent'
2
- import { addFileUrl } from './utils'
3
2
  import { redis } from '../libs/redis'
4
3
  import CacheItem, { CacheType } from '../cache/item'
5
4
  import { getDatasetWorker } from '../libs/datalad-service'
@@ -79,7 +78,7 @@ export const getFiles = (datasetId, treeish) => {
79
78
  const {
80
79
  body: { files },
81
80
  } = response
82
- return files.map(addFileUrl(datasetId, treeish))
81
+ return files
83
82
  }
84
83
  }),
85
84
  )
@@ -23,3 +23,26 @@ export const getFile = (req, res) => {
23
23
  : `${worker}/datasets/${datasetId}/files/${filename}`
24
24
  return request.get(uri).pipe(res)
25
25
  }
26
+
27
+ /**
28
+ * Get a file from a dataset
29
+ */
30
+ export const getObject = (req, res) => {
31
+ const { datasetId, key } = req.params
32
+ const worker = getDatasetWorker(datasetId)
33
+ // Backend depends on git object or git-annex key
34
+ if (key.length === 40) {
35
+ const uri = `${worker}/datasets/${datasetId}/objects/${key}`
36
+ res.set('Content-Type', 'application/octet-stream')
37
+ return request.get(uri).pipe(res)
38
+ } else if (key.startsWith('SHA256E-') || key.startsWith('MD5E-')) {
39
+ const uri = `${worker}/datasets/${datasetId}/annex/${key}`
40
+ res.set('Content-Type', 'application/octet-stream')
41
+ return request.get(uri).pipe(res)
42
+ } else {
43
+ res.set('Content-Type', 'application/json')
44
+ res.status(400).send({
45
+ error: 'Key must be a git object hash or git-annex key',
46
+ })
47
+ }
48
+ }
package/src/routes.js CHANGED
@@ -122,6 +122,11 @@ const routes = [
122
122
  url: '/datasets/:datasetId/snapshots/:snapshotId/files/:filename',
123
123
  handler: datalad.getFile,
124
124
  },
125
+ {
126
+ method: 'get',
127
+ url: '/datasets/:datasetId/objects/:key',
128
+ handler: datalad.getObject,
129
+ },
125
130
 
126
131
  // Authentication routes
127
132
 
@@ -1,25 +0,0 @@
1
- import config from '../config.js'
2
-
3
- /**
4
- * @param {string} datasetId
5
- * @param {string} [tag]
6
- */
7
- export const addFileUrl = (datasetId, tag) => file => {
8
- // Skip files annotated with a URL from datalad service
9
- if (file.urls.length > 0) {
10
- return file
11
- } else {
12
- // This is a draft, files are local and no URLs defined
13
- const filePath = file.filename.replace(/\//g, ':')
14
- if (tag) {
15
- // Snapshot
16
- // Backup URL for direct access for private datasets
17
- const fileUrl = `${config.url}${config.apiPrefix}datasets/${datasetId}/snapshots/${tag}/files/${filePath}`
18
- return { ...file, urls: [fileUrl] }
19
- } else {
20
- // Dataset draft
21
- const fileUrl = `${config.url}${config.apiPrefix}datasets/${datasetId}/files/${filePath}`
22
- return { ...file, urls: [fileUrl] }
23
- }
24
- }
25
- }