@openneuro/server 4.15.2-demo.1 → 4.16.1

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.15.2-demo.1",
3
+ "version": "4.16.1",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "@apollo/client": "3.7.2",
19
19
  "@elastic/elasticsearch": "7.15.0",
20
- "@openneuro/search": "^4.15.2-demo.1",
20
+ "@openneuro/search": "^4.16.1",
21
21
  "@passport-next/passport-google-oauth2": "^1.0.0",
22
22
  "@sentry/node": "^4.5.3",
23
23
  "apollo-server": "2.25.4",
@@ -92,5 +92,5 @@
92
92
  "publishConfig": {
93
93
  "access": "public"
94
94
  },
95
- "gitHead": "38094ea1b60e11a55425dbe597a10d872a4cb89e"
95
+ "gitHead": "0739211264d035ff4531bf7961232c1abd0165d5"
96
96
  }
@@ -1,3 +1,5 @@
1
+ import config from '../config.js'
2
+ import { ApolloError } from 'apollo-server'
1
3
  import Permission from '../models/permission'
2
4
  import Dataset from '../models/dataset'
3
5
  import Deletion from '../models/deletion'
@@ -50,12 +52,37 @@ export const checkPermissionLevel = (permission, state) => {
50
52
  }
51
53
  }
52
54
 
55
+ export class DeletedDatasetError extends ApolloError {
56
+ constructor(datasetId, reason, redirect = undefined) {
57
+ let extension
58
+ if (redirect) {
59
+ try {
60
+ // Validate URL before we attach it to the API response
61
+ const canonical = new URL(config.url)
62
+ const url = new URL(redirect)
63
+ if (
64
+ url.hostname === canonical.hostname &&
65
+ url.pathname.startsWith('/datasets')
66
+ ) {
67
+ // Only return a relative path to avoid cross site risks
68
+ extension = { redirect: url.pathname }
69
+ }
70
+ } catch (err) {
71
+ // Do nothing
72
+ }
73
+ }
74
+ super(
75
+ `Dataset ${datasetId} has been deleted. Reason: ${reason}.`,
76
+ 'DELETED_DATASET',
77
+ extension,
78
+ )
79
+ }
80
+ }
81
+
53
82
  export const checkDatasetExists = async datasetId => {
54
83
  const deleted = await Deletion.findOne({ datasetId }).exec()
55
84
  if (deleted) {
56
- throw new Error(
57
- `Dataset ${datasetId} has been deleted. Reason: ${deleted.reason}.`,
58
- )
85
+ throw new DeletedDatasetError(datasetId, deleted.reason, deleted.redirect)
59
86
  }
60
87
  const found = await Dataset.countDocuments({ id: datasetId }).exec()
61
88
  if (!found) throw new Error(`Dataset ${datasetId} does not exist.`)
@@ -41,8 +41,11 @@ export const onBrainlife = async (
41
41
  dataset: DatasetOrSnapshot,
42
42
  ): Promise<boolean> => {
43
43
  try {
44
+ const abortController = new AbortController()
44
45
  const url = brainlifeQuery(dataset)
45
- const res = await fetch(url.toString())
46
+ const timeout = setTimeout(() => abortController.abort(), 5000)
47
+ const res = await fetch(url.toString(), { signal: abortController.signal })
48
+ clearTimeout(timeout)
46
49
  const body = await res.json()
47
50
  if (Array.isArray(body) && body.length) {
48
51
  return true