UCDavisLibrary / ucd-hyku

The Hydra-in-a-Box repository application
http://hydrainabox.projecthydra.org/
Other
3 stars 0 forks source link

JSON import #1

Open qjhart opened 7 years ago

qjhart commented 7 years ago

We would like to have a json import methodology for file uploads.

Hydra

We have two options 'raw' json, which maps pretty much 1to1 with the Hydra inputs. In this case, we could have two inputs, one for collections, and one for works.

{ 
 "collection_id" : {
   "type" : "Collection",
   "title" : "foo #"
},

If the local identifier is the same, then you do an update. If the collections are included, they have to be defined before they are used. In that case, it can make sense to have two json files, oine for collections.

  "a:0002": {
   "type": "Image #This has to match a existing type (Collection |ETD|Image) ", 
  "title" : ["Title goes here","Can have two."],
  "title" : "But putting in one should be okay",
  "visibility" : "open",
  "administrative set" : "This is singular", 
  "keywords": [
    "https://foo.bar/this%20keyword Label",
    "Plain Text"
    "http://foo.bar/url+only"],
  "member_of_collection": [ "uuids here are okay","What about local identifiers here?"],
  "remote_files" : [
   "http://drive.google.com/file%name Here is Label",
    "file:///foo.bar Not+sure+on+this?" ]
  },
 "a:0003" : {
  }
}

Finally, these JSON files *Must be formatted in json-newline format. where an entire object is on a single line, and the file can be streamed. So the file representation looks like:

{"a:0002":{"title":"This is the title.....",}
{"a:0003":{"title":"This is the title.....",}
jrmerz commented 7 years ago

For this to work, we are disabling CSRF token checking. This attack vector should be able to stopped in the browser by enabling CORS and checking the Origin header: https://stackoverflow.com/questions/24680302/csrf-protection-with-cors-origin-header-vs-csrf-token

jrmerz commented 7 years ago

@qjhart Even with CSRF disabled, the HTTP requests still fail without the Origin header correctly set. I still need to investigate which part of Rails is preventing the request (I don't want to disable it, it is a good thing, just for my own understanding of the system).