working init update
parent
bd8ad2c428
commit
56d6e48ad4
@ -1 +1 @@
|
|||||||
Subproject commit 1a72909f51a76b41fc4824f0eefef1cf503c8d0e
|
Subproject commit 423ba0e52ceb70b685af6118eead2d9d77e25469
|
@ -0,0 +1,65 @@
|
|||||||
|
import 'babel-polyfill';
|
||||||
|
|
||||||
|
let apiPort = '8880'
|
||||||
|
if (process.env.API_PORT !== undefined) {
|
||||||
|
apiPort = process.env.API_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEndpoint (path) {
|
||||||
|
return new URL(path, apiEndpoint).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
const endPoints = {
|
||||||
|
get upload () {
|
||||||
|
return getEndpoint('upload')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiEndpoint = function() {
|
||||||
|
let currentLoc = self.location;
|
||||||
|
let endpoint = new URL(currentLoc);
|
||||||
|
|
||||||
|
endpoint.port = apiPort;
|
||||||
|
|
||||||
|
return endpoint.toString()
|
||||||
|
}()
|
||||||
|
|
||||||
|
class Upload {
|
||||||
|
|
||||||
|
constructor(files) {
|
||||||
|
this.files = Array.from(files)
|
||||||
|
this.timestamp = new Date()
|
||||||
|
}
|
||||||
|
|
||||||
|
get payload() {
|
||||||
|
return {
|
||||||
|
files: this.files,
|
||||||
|
timestamp: this.timestamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async create() {
|
||||||
|
let req = new Request(endPoints.upload, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(this.payload)
|
||||||
|
})
|
||||||
|
|
||||||
|
//let result = await fetch(req);
|
||||||
|
let res = await fetch(req)
|
||||||
|
.catch((e) => { console.error(e) })
|
||||||
|
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw(`${res.status}: ` + (await res.json()).error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
endpoint: apiEndpoint,
|
||||||
|
endPoints: endPoints,
|
||||||
|
Upload: Upload
|
||||||
|
}
|
Loading…
Reference in New Issue