Skip to content

Commit

Permalink
Update file input component
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansberry committed Dec 10, 2024
1 parent ccb868a commit 6c944da
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 34 deletions.
1 change: 0 additions & 1 deletion ckanext/dms/react/components/FileInputComponent/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import ProgressBar from './ProgressBar';
import DisplayUploadedFile from './DisplayUploadedFile';
import UrlUploader from './UrlUploader';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export default function FileUploader({
setUploadError
}) {

const getAuthToken = () =>
axios.post(
const getAuthToken = () => {
const csrf_field = $('meta[name=csrf_field_name]').attr('content');
const csrf_token = $('meta[name='+ csrf_field +']').attr('content');
return axios.post(
'/api/3/action/authz_authorize',
{ scopes: `obj:${orgId}/${datasetName}/*:write` },
{ withCredentials: true }
{ withCredentials: true, headers: {'X-CSRFToken': csrf_token} }
)
.then(res => res.data.result.token)
.catch(error => {
Expand All @@ -23,6 +25,8 @@ export default function FileUploader({
});
throw error;
});
}

const uploadFile = (client, file) =>
client.upload(file, orgId, datasetName, progress =>
setUploadProgress({
Expand All @@ -43,6 +47,7 @@ export default function FileUploader({
setUploadProgress({ loaded: 0, total: 1 });
const file = data.open(inputFile);
const authToken = await getAuthToken();
console.log(authToken);
const client = new Client(lfsServer, authToken, ['basic']);
await uploadFile(client, file);
setUploadProgress({ loaded: 100, total: 100 });
Expand Down
2 changes: 1 addition & 1 deletion ckanext/dms/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@babel/preset-react": "^7.12.13",
"axios": "^0.28.0",
"axios": "^0.21.1",
"babel-loader": "^8.2.2",
"bluebird": "^3.7.2",
"core-js": "^3.9.1",
Expand Down
30 changes: 1 addition & 29 deletions ckanext/dms/react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2740,15 +2740,6 @@ axios@^0.21.1:
dependencies:
follow-redirects "^1.10.0"

axios@^0.28.0:
version "0.28.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.28.1.tgz#2a7bcd34a3837b71ee1a5ca3762214b86b703e70"
integrity sha512-iUcGA5a7p0mVb4Gm/sy+FSECNkPFT4y7wt6OM/CDpO/OnNCvSs3PoMG8ibrC9jRoGYU0gUK5pXVC4NPXq6lHRQ==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axobject-query@^2.0.2:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
Expand Down Expand Up @@ -3620,7 +3611,7 @@ colorette@^1.2.1:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==

combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
Expand Down Expand Up @@ -5312,11 +5303,6 @@ follow-redirects@^1.10.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147"
integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==

follow-redirects@^1.15.0:
version "1.15.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
Expand Down Expand Up @@ -5360,15 +5346,6 @@ [email protected]:
tapable "^1.0.0"
worker-rpc "^0.1.0"

form-data@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48"
integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -9312,11 +9289,6 @@ proxy-addr@~2.0.5:
forwarded "~0.1.2"
ipaddr.js "1.9.1"

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

prr@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
Expand Down

0 comments on commit 6c944da

Please sign in to comment.