-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_raw.js
More file actions
executable file
·79 lines (75 loc) · 2.73 KB
/
Copy pathimport_raw.js
File metadata and controls
executable file
·79 lines (75 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const fetch = require('node-fetch')
const fs = require('fs')
function checkHttp200(res) {
if (res.status === 200) {
return res
} else {
return Promise.reject('got unexpected HTTP status ' + res.status)
}
}
const url = 'http://api-65-cwurst-schani.cloud.itandtel.at'
//const url = 'http://localhost:8000'
//const url = 'http://apigateway:8000'
fetch(url + '/auth/login?username=christoph&password=123456', {
method: 'POST'
})
.then((res) => res.text())
.then((jwt) => {
console.log('got jwt', jwt)
return jwt
})
.then((jwt) => {
let import_data = {
user_id: 100,
}
return fetch(url + '/imports', {
method: 'POST',
headers: {
'Authorization': 'bearer ' + jwt,
'Content-Type': 'application/json'
},
body: JSON.stringify(import_data)
})
.then((res) => checkHttp200(res))
.then((res) => res.json())
.then((import_data) => {
console.log('got import id', import_data.id)
console.log('now uploading the raw image')
const rawStream = fs.createReadStream('./resources/RAW1.NEF')
return fetch(url + '/imports/' + import_data.id + '/raw', {
method: 'PUT',
headers: {
'Authorization': 'bearer ' + jwt,
},
body: rawStream
})
.then((res) => checkHttp200(res))
})
.then((res) => res.json())
.then((import_data) => {
console.log('now uploading the sidecar')
const sidecarStream = fs.createReadStream('./resources/RAW1.NEF.pp3')
return fetch(url + '/imports/' + import_data.id + '/sidecar', {
method: 'PUT',
headers: {
'Authorization': 'bearer ' + jwt,
},
body: sidecarStream
})
})
.then((res) => checkHttp200(res))
.then((res) => res.json())
.then((import_data) => {
console.log('now finishing the upload')
return fetch(url + '/imports/' + import_data.id + '/finish', {
method: 'POST',
headers: {
'Authorization': 'bearer ' + jwt,
}
})
})
.then((res) => checkHttp200(res))
.then((res) => res.json())
.then((import_data) => console.info('import successful', import_data))
})
.catch((e) => console.error('error importing the image: ', e))