Project

General

Profile

Improvements #10382 ยป WFileDropWidget-custom-upload.patch

Raf Pauwels, 05/19/2022 08:49 AM

View differences:

src/Wt/WFileDropWidget.C
if (uploads_[i]->uploadId() == id) {
fileFound = true;
currentFileIdx_ = i;
auto currentFile = uploads_[currentFileIdx_].get();
resource_ = std::make_unique<WFileDropUploadResource>(this, currentFile);
resource_->dataReceived().connect(this, &WFileDropWidget::onData);
resource_->dataExceeded().connect(this, &WFileDropWidget::onDataExceeded);
resource_ = uploadResource();
doJavaScript(jsRef() + ".send('" + resource_->url() + "', "
+ (currentFile->filterEnabled() ? "true" : "false")
+ (uploads_[currentFileIdx_]->filterEnabled() ? "true" : "false")
+ ");");
uploadStart_.emit(currentFile);
uploadStart_.emit(uploads_[currentFileIdx_].get());
break;
} else {
// If a previous upload was not cancelled, it must have failed
......
}
}
std::unique_ptr<WResource> WFileDropWidget::uploadResource()
{
auto resource = std::make_unique<WFileDropUploadResource>(this, uploads_[currentFileIdx_].get());
resource->dataReceived().connect(this, &WFileDropWidget::onData);
resource->dataExceeded().connect(this, &WFileDropWidget::onDataExceeded);
return resource;
}
void WFileDropWidget::handleTooLarge(::uint64_t size)
{
if (currentFileIdx_ >= uploads_.size()) {
src/Wt/WFileDropWidget.h
*/
Signal<File*>& uploadFailed() { return uploadFailed_; }
class WFileDropUploadResource;
protected:
virtual std::string renderRemoveJs(bool recursive) override;
virtual void enableAjax() override;
virtual void updateDom(DomElement& element, bool all) override;
virtual std::unique_ptr<WResource> uploadResource();
virtual JSignal<int>& requestSend() { return requestSend_; };
std::unique_ptr<WResource> resource_;
friend class WFileDropUploadResource;
private:
void setup();
......
bool incomingIdCheck(int id);
WMemoryResource *uploadWorkerResource_;
class WFileDropUploadResource;
std::unique_ptr<WFileDropUploadResource> resource_;
unsigned currentFileIdx_;
static const std::string WORKER_JS;
......
std::bitset<5> updateFlags_;
bool updatesEnabled_; // track if this widget enabled updates.
friend class WFileDropUploadResource;
};
}
src/js/WFileDropWidget.js
return items || types;
};
this.validFileCheck = function(file, callback, url) {
this.validFileCheck = function(upload, callback, url) {
var reader = new FileReader();
reader.onload = function() {
callback(true, url);
callback(true, url, upload, APP);
}
reader.onerror = function() {
callback(false, url);
callback(false, url, upload, APP);
}
reader.readAsText(file.slice(0, 32)); // try reading some bytes
reader.readAsText(upload.file.slice(0, 32)); // try reading some bytes
}
dropwidget.setAcceptDrops = function(enable) {
......
bodyDragEnter = function(e) {
if (!(dropIndication || bodyDropForward)
|| !$(dropwidget).is(":visible"))
|| !$(dropwidget).is(":visible")
|| !acceptDrops)
return;
dragState = 1;
......
}
sending = true;
APP.emit(dropwidget, 'requestsend', uploads[0].id);
dropwidget.emitRequestSend(APP, uploads[0]);
}
dropwidget.emitRequestSend = function(APP, upload) {
APP.emit(dropwidget, 'requestsend', upload.id);
}
dropwidget.send = function(url, useFilter) {
......
self.uploadFinished(null);
return;
} else {
var sendFn = (uploadWorker != undefined && useFilter) ?
self.workerSend : self.actualSend;
self.validFileCheck(upload.file, sendFn, url);
self.validFileCheck(upload, dropwidget.getSendFn(), url);
}
}
this.actualSend = function(isValid, url) {
dropwidget.getSendFn = function() {
return (uploadWorker != undefined && useFilter) ? self.workerSend : self.actualSend;
}
this.actualSend = function(isValid, url, upload, APP) {
if (!isValid) {
self.uploadFinished(null);
return;
......
xhr.send(fd);
}
this.workerSend = function(isValid, url) {
this.workerSend = function(isValid, url, upload, APP) {
if (!isValid) {
self.uploadFinished(null);
return;
    (1-1/1)