(w http.ResponseWriter, r *http.Request, params httprouter.Params)
| 98 | } |
| 99 | |
| 100 | func (api *API) ServeV1WriteNQuad(w http.ResponseWriter, r *http.Request, params httprouter.Params) { |
| 101 | if api.config.ReadOnly { |
| 102 | jsonResponse(w, 400, "Database is read-only.") |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | formFile, _, err := r.FormFile("NQuadFile") |
| 107 | if err != nil { |
| 108 | clog.Errorf("%v", err) |
| 109 | jsonResponse(w, 500, "Couldn't read file: "+err.Error()) |
| 110 | return |
| 111 | } |
| 112 | defer formFile.Close() |
| 113 | |
| 114 | blockSize, blockErr := strconv.Atoi(r.URL.Query().Get("block_size")) |
| 115 | if blockErr != nil { |
| 116 | blockSize = quad.DefaultBatch |
| 117 | } |
| 118 | |
| 119 | quadReader, err := decompressor.New(formFile) |
| 120 | // TODO(kortschak) Make this configurable from the web UI. |
| 121 | dec := nquads.NewReader(quadReader, false) |
| 122 | |
| 123 | h, err := api.GetHandleForRequest(r) |
| 124 | if err != nil { |
| 125 | jsonResponse(w, 400, err) |
| 126 | return |
| 127 | } |
| 128 | qw := graph.NewWriter(h.QuadWriter) |
| 129 | n, err := quad.CopyBatch(qw, dec, blockSize) |
| 130 | if err != nil { |
| 131 | jsonResponse(w, 400, err) |
| 132 | return |
| 133 | } |
| 134 | err = qw.Close() |
| 135 | if err != nil { |
| 136 | jsonResponse(w, 400, err) |
| 137 | return |
| 138 | } |
| 139 | fmt.Fprintf(w, "{\"result\": \"Successfully wrote %d quads.\"}", n) |
| 140 | } |
| 141 | |
| 142 | func (api *API) ServeV1Delete(w http.ResponseWriter, r *http.Request, params httprouter.Params) { |
| 143 | if api.config.ReadOnly { |
nothing calls this directly
no test coverage detected