@openneuro/server 4.21.1 → 4.21.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 +3 -3
- package/src/datalad/files.ts +10 -5
- package/src/handlers/datalad.ts +24 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openneuro/server",
|
|
3
|
-
"version": "4.21.
|
|
3
|
+
"version": "4.21.2",
|
|
4
4
|
"description": "Core service for the OpenNeuro platform.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/server.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@elastic/elasticsearch": "7.15.0",
|
|
22
22
|
"@graphql-tools/schema": "^10.0.0",
|
|
23
23
|
"@keyv/redis": "^2.7.0",
|
|
24
|
-
"@openneuro/search": "^4.21.
|
|
24
|
+
"@openneuro/search": "^4.21.2",
|
|
25
25
|
"@passport-next/passport-google-oauth2": "^1.0.0",
|
|
26
26
|
"@sentry/node": "^4.5.3",
|
|
27
27
|
"base64url": "^3.0.0",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "5607a295f9130a0e51bffdaf8d3d6235c8eab8f8"
|
|
89
89
|
}
|
package/src/datalad/files.ts
CHANGED
|
@@ -92,11 +92,16 @@ export const getFiles = (datasetId, treeish): Promise<[DatasetFile?]> => {
|
|
|
92
92
|
])
|
|
93
93
|
return cache.get(
|
|
94
94
|
async (doNotCache): Promise<[DatasetFile?]> => {
|
|
95
|
-
const response = await fetch(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
const response = await fetch(
|
|
96
|
+
`http://${
|
|
97
|
+
getDatasetWorker(
|
|
98
|
+
datasetId,
|
|
99
|
+
)
|
|
100
|
+
}/datasets/${datasetId}/tree/${treeish}`,
|
|
101
|
+
{
|
|
102
|
+
signal: AbortSignal.timeout(10000),
|
|
103
|
+
},
|
|
104
|
+
)
|
|
100
105
|
const body = await response.json()
|
|
101
106
|
const files = body?.files
|
|
102
107
|
if (files) {
|
package/src/handlers/datalad.ts
CHANGED
|
@@ -24,11 +24,30 @@ export const getFile = async (req, res) => {
|
|
|
24
24
|
let tree = snapshotId || "HEAD"
|
|
25
25
|
let file
|
|
26
26
|
for (const level of pathComponents) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
try {
|
|
28
|
+
const files = await getFiles(datasetId, tree)
|
|
29
|
+
if (level == pathComponents.slice(-1)) {
|
|
30
|
+
file = files.find((f) => !f.directory && f.filename === level)
|
|
31
|
+
} else {
|
|
32
|
+
// This tree may exist but have no children
|
|
33
|
+
if (files) {
|
|
34
|
+
tree = files.find((f) => f.directory && f.filename === level).id
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
// ConnectTimeoutError is Node/Undici and TimeoutError is the standard DOMException name
|
|
39
|
+
if (
|
|
40
|
+
err?.cause?.name === "ConnectTimeoutError" ||
|
|
41
|
+
err?.name === "TimeoutError"
|
|
42
|
+
) {
|
|
43
|
+
// Unreachable backend, forward this error
|
|
44
|
+
// Usually this is the service restarting due to node migrations or upgrades
|
|
45
|
+
res.status(503).send("Worker could not be reached")
|
|
46
|
+
return
|
|
47
|
+
} else {
|
|
48
|
+
// Unknown error should bubble up
|
|
49
|
+
throw err
|
|
50
|
+
}
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
53
|
// Get the file URL and redirect if external or serve if local
|