Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/files.js
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | const fileDropHandler = (event) => { | ||||
// "progress source", i.e. we might want to refresh the files list once | // "progress source", i.e. we might want to refresh the files list once | ||||
// all files finished uploading, not multiple times in the middle | // all files finished uploading, not multiple times in the middle | ||||
// of the upload process. | // of the upload process. | ||||
params.eventHandler('upload-progress', progress) | params.eventHandler('upload-progress', progress) | ||||
// A "recursive" function to upload the file in chunks (if needed) | // A "recursive" function to upload the file in chunks (if needed) | ||||
const uploadFn = (start = 0, uploadId) => { | const uploadFn = (start = 0, uploadId) => { | ||||
let url = 'api/v4/files' | let url = 'api/v4/fs' | ||||
let body = '' | let body = '' | ||||
if (file.size <= maxChunkSize) { | if (file.size <= maxChunkSize) { | ||||
// The file is small, we'll upload it using a single request | // The file is small, we'll upload it using a single request | ||||
// Note that even in this case the auth token might expire while | // Note that even in this case the auth token might expire while | ||||
// the file is uploading, but the risk is quite small. | // the file is uploading, but the risk is quite small. | ||||
body = file | body = file | ||||
start += maxChunkSize | start += maxChunkSize | ||||
if (params.parent) { | |||||
url = url + '?parent=' + params.parent | |||||
} | |||||
} else if (!uploadId) { | } else if (!uploadId) { | ||||
// The file is big, first send a request for the upload location | // The file is big, first send a request for the upload location | ||||
// The upload location does not require authentication, which means | // The upload location does not require authentication, which means | ||||
// there should be no problem with expired auth token, etc. | // there should be no problem with expired auth token, etc. | ||||
config.params.media = 'resumable' | config.params.media = 'resumable' | ||||
config.params.size = file.size | config.params.size = file.size | ||||
if (params.parent) { | |||||
config.params.parent = params.parent | |||||
machniak: config.params.parent = params.parent | |||||
} | |||||
} else { | } else { | ||||
// Upload a chunk of the file to the upload location | // Upload a chunk of the file to the upload location | ||||
url = 'api/v4/files/uploads/' + uploadId | url = 'api/v4/fs/uploads/' + uploadId | ||||
body = file.slice(start, start + maxChunkSize, file.type) | body = file.slice(start, start + maxChunkSize, file.type) | ||||
config.params = { from: start } | config.params = { from: start } | ||||
config.headers.Authorization = '' | config.headers.Authorization = '' | ||||
start += maxChunkSize | start += maxChunkSize | ||||
} | } | ||||
axios.post(url, body, config) | axios.post(url, body, config) | ||||
Show All 26 Lines | const fileDropHandler = (event) => { | ||||
uploadFn() | uploadFn() | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Download a file. Starts downloading using a hidden link trick. | * Download a file. Starts downloading using a hidden link trick. | ||||
*/ | */ | ||||
this.fileDownload = (id) => { | this.fileDownload = (id) => { | ||||
axios.get('api/v4/files/' + id + '?downloadUrl=1') | axios.get('api/v4/fs/' + id + '?downloadUrl=1') | ||||
.then(response => { | .then(response => { | ||||
// Create a dummy link element and click it | // Create a dummy link element and click it | ||||
if (response.data.downloadUrl) { | if (response.data.downloadUrl) { | ||||
$('<a>').attr('href', response.data.downloadUrl).get(0).click() | $('<a>').attr('href', response.data.downloadUrl).get(0).click() | ||||
} | } | ||||
}) | }) | ||||
} | } | ||||
/** | /** | ||||
* Rename a file. | * Rename a file. | ||||
*/ | */ | ||||
this.fileRename = (id, name) => { | this.fileRename = (id, name) => { | ||||
axios.put('api/v4/files/' + id, { name }) | axios.put('api/v4/fs/' + id, { name }) | ||||
.then(response => { | .then(response => { | ||||
}) | }) | ||||
} | } | ||||
/** | /** | ||||
* Convert file size as a number of bytes to a human-readable format | * Convert file size as a number of bytes to a human-readable format | ||||
*/ | */ | ||||
Show All 13 Lines |
config.params.parent = params.parent