[develop-16-deposit | WIP | ADDED ] initial implementation for deposit functionality
This commit is contained in:
parent
7ca0d9e8b8
commit
252bbf519f
|
@ -100,6 +100,7 @@ const routes: Routes = [
|
|||
},
|
||||
// { path: 'claims-project-manager', loadChildren: './claims/claimsByToken/claimsByToken.module#LibClaimsByTokenModule'},
|
||||
// help pages - do not exist in Admin portal/api/db
|
||||
{path: 'deposit', loadChildren: () => import('./openaireLibrary/deposit/deposit-grant-redirect/deposit.module').then(m => m.DepositModule)},
|
||||
{path: 'reload', loadChildren: () => import('./openaireLibrary/reload/reload.module').then(m => m.ReloadModule)},
|
||||
{path: 'user-info', loadChildren: () => import('./openaireLibrary/login/user.module').then(m => m.UserModule)},
|
||||
{path: 'error', component: ErrorPageComponent},
|
||||
|
|
|
@ -17,7 +17,10 @@ let props: EnvProperties = {
|
|||
dashboard: "explore",
|
||||
adminToolsCommunity: "openaire",
|
||||
baseLink : "",
|
||||
domain: "https://explore.openaire.eu"
|
||||
domain: "https://explore.openaire.eu",
|
||||
utilsService: "http://localhost:8000",
|
||||
cacheUrl:"http://scoobydoo.di.uoa.gr:3200",
|
||||
claimsAPIURL: "http://scoobydoo.di.uoa.gr:8181/claimsService/",
|
||||
|
||||
|
||||
/*environment: "development",
|
||||
|
|
|
@ -7,6 +7,9 @@ var PropertiesReader = require('properties-reader');
|
|||
var properties = PropertiesReader('./properties.file');
|
||||
var app = express();
|
||||
var http = null;
|
||||
var fs = require("fs");
|
||||
const FormData = require('form-data');
|
||||
|
||||
// Properties
|
||||
if (properties.get('ssl')) {
|
||||
http = require("https");
|
||||
|
@ -477,3 +480,215 @@ function isCurator(type, roles) {
|
|||
function isManager(type, id, roles) {
|
||||
return roles.includes(mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER");
|
||||
}
|
||||
let api = "https://sandbox.zenodo.org/";
|
||||
client_id= "JK9mqlayFu793ylUmCtiU8yZRbl1pBYD3uWrZ3Dg";
|
||||
client_secret ="Mr1L2SK1La4vpGXSyqMFqo551YVM4koNKPFIM1vdRw8sTb5AlD89KZwGLaqN";
|
||||
redirect_uri = "http://localhost:4300/deposit";
|
||||
app.get('/deposit/info', async function (req, res) {
|
||||
const requestParams = {
|
||||
params: {
|
||||
'access_token': req.query['token']
|
||||
}
|
||||
}
|
||||
axios.get(api + "api/deposit/depositions", requestParams).then(response => {
|
||||
console.log(response.status);
|
||||
// > 200
|
||||
console.log(response.data);
|
||||
res.send(response.data)
|
||||
// > []
|
||||
}).catch(error => {
|
||||
console.log(error.response.data);
|
||||
res.status(error.response.status).send(error.response.data)
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/deposit/start', async function (req, res) {
|
||||
const requestParams = {
|
||||
params: {
|
||||
'access_token': req.query['token']
|
||||
}
|
||||
}
|
||||
axios.post(api + "api/deposit/depositions", requestParams).then(response => {
|
||||
console.log(response.status);
|
||||
// > 200
|
||||
console.log(response.data);
|
||||
res.send(response.data)
|
||||
// > []
|
||||
}).catch(error => {
|
||||
console.log(error.response.data);
|
||||
res.status(error.response.status).send(error.response.data )
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/deposit/getToken', async function (req, res) {
|
||||
let code;
|
||||
let refresh;
|
||||
console.log(req.query);
|
||||
if(req.query['code']){
|
||||
code = req.query['code'];
|
||||
}else if(req.query['refresh_token']){
|
||||
refresh = req.query['refresh_token'];
|
||||
}
|
||||
console.log(code, refresh)
|
||||
_getToken(req, res,code, refresh);
|
||||
});
|
||||
function _getToken(req, res,code, refresh){
|
||||
let data = new FormData();
|
||||
data.append('client_id', client_id);
|
||||
data.append('client_secret', client_secret);
|
||||
if(code){
|
||||
data.append('grant_type', 'authorization_code');
|
||||
data.append('code', code);
|
||||
}else if(refresh){
|
||||
data.append('grant_type', 'refresh_token');
|
||||
data.append('refresh_token', refresh);
|
||||
}
|
||||
data.append('redirect_uri', redirect_uri);
|
||||
console.log(data);
|
||||
let config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: api + 'oauth/token',
|
||||
headers: {
|
||||
...data.getHeaders()
|
||||
},
|
||||
data : data
|
||||
};
|
||||
|
||||
axios.request(config)
|
||||
.then((response) => {
|
||||
console.log(JSON.stringify(response.data));
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
res.status(200).send(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
// console.log(error);
|
||||
console.log(error.response.status);
|
||||
|
||||
res.status(error.response.status).send(error.response.data)
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
app.get('/deposit/getAccessToken', async function (req, res) {
|
||||
console.log(req.query);
|
||||
if(req.query['access_token']){
|
||||
const requestParams = {
|
||||
params: {
|
||||
'access_token': req.query['token']
|
||||
}
|
||||
}
|
||||
axios.get(api + "api/deposit/depositions", requestParams).then(response => {
|
||||
console.log(response.status);
|
||||
// > 200
|
||||
console.log(response.data);
|
||||
res.send(req.query['token'])
|
||||
// > []
|
||||
}).catch(error => {
|
||||
console.log(error.response.data);
|
||||
// res.status(error.response.status).send(error.response.data)
|
||||
});
|
||||
}
|
||||
let data = new FormData();
|
||||
data.append('client_id', client_id);
|
||||
data.append('client_secret', client_secret);
|
||||
if(req.query['code']){
|
||||
data.append('grant_type', 'authorization_code');
|
||||
data.append('code', req.query['code']);
|
||||
}else if(req.query['refresh_token']){
|
||||
data.append('grant_type', 'refresh_token');
|
||||
data.append('refresh_token', req.query['refresh_token']);
|
||||
}
|
||||
data.append('redirect_uri', redirect_uri);
|
||||
console.log(data);
|
||||
let config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: api + 'oauth/token',
|
||||
headers: {
|
||||
...data.getHeaders()
|
||||
},
|
||||
data : data
|
||||
};
|
||||
|
||||
axios.request(config)
|
||||
.then((response) => {
|
||||
console.log(JSON.stringify(response.data));
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
res.status(200).send(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
// console.log(error);
|
||||
console.log(error.response.status);
|
||||
|
||||
res.status(error.response.status).send(error.response.data)
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
app.post('/deposit/upload', async function (req, res) {
|
||||
console.log("UPLOAD!!!!!!!")
|
||||
const requestParams = {
|
||||
params: {
|
||||
'access_token': req.query['token']
|
||||
}
|
||||
}
|
||||
|
||||
if( req.body['links'] && req.body['links']['bucket']) {
|
||||
const filePath = '/home/argirok/projects/openaire/explore-services/services/utils-service/test.txt'; // Replace with file path
|
||||
const bucketURL = req.body['links']['bucket']; // Replace with bucket url
|
||||
const fileName = 'test.txt'; // Replace with file name
|
||||
const token = req.query['token']; // Replace with token value
|
||||
console.log("bucket:" + bucketURL)
|
||||
|
||||
// Create a form
|
||||
const form = new FormData();
|
||||
|
||||
// Read file as a stream
|
||||
const stream = fs.createReadStream(filePath);
|
||||
console.log(filePath)
|
||||
form.append('file', stream);
|
||||
let url = `${bucketURL}/${fileName}`;
|
||||
|
||||
let params = { 'access_token': token }
|
||||
|
||||
let headers = {
|
||||
'Content-type': 'application/octet-stream'
|
||||
}
|
||||
|
||||
const requestConfig = {
|
||||
data: {
|
||||
name: fileName,
|
||||
...form
|
||||
},
|
||||
headers: headers,
|
||||
params: params
|
||||
}
|
||||
|
||||
console.log("Try to upload", url, requestConfig)
|
||||
axios.put(url, {
|
||||
name: fileName,
|
||||
...form
|
||||
},
|
||||
headers,
|
||||
params ).then(response => {
|
||||
console.log(response.headers['Referer'], response.headers['Origin'], response.headers['Host'])
|
||||
console.log(response.data,);
|
||||
res.send(response.data)
|
||||
}).catch(error => {
|
||||
console.log(error.response.headers)
|
||||
|
||||
console.error(error.response.data)
|
||||
res.status(error.response.status).send(error.response.data)
|
||||
});
|
||||
|
||||
}else{
|
||||
res.status(400).send("no bucket link")
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue