Переглянути джерело

chore: Remove unused code (bp #12671) (#12675)

(cherry picked from commit c4b0f54943)

Co-authored-by: Sagar Vora <sagar@resilient.tech>
version-14
mergify[bot] 4 роки тому
committed by GitHub
джерело
коміт
74fef045f3
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
3 змінених файлів з 3 додано та 163 видалено
  1. +3
    -10
      frappe/core/doctype/system_settings/system_settings.json
  2. +0
    -112
      frappe/public/js/frappe/socketio_client.js
  3. +0
    -41
      socketio.js

+ 3
- 10
frappe/core/doctype/system_settings/system_settings.json Переглянути файл

@@ -67,8 +67,7 @@
"enable_prepared_report_auto_deletion",
"prepared_report_expiry_period",
"chat",
"enable_chat",
"use_socketio_to_upload_file"
"enable_chat"
],
"fields": [
{
@@ -394,12 +393,6 @@
"fieldtype": "Check",
"label": "Enable Chat"
},
{
"default": "1",
"fieldname": "use_socketio_to_upload_file",
"fieldtype": "Check",
"label": "Use socketio to upload file"
},
{
"fieldname": "column_break_21",
"fieldtype": "Column Break"
@@ -486,7 +479,7 @@
"icon": "fa fa-cog",
"issingle": 1,
"links": [],
"modified": "2020-12-30 18:52:22.161391",
"modified": "2021-03-25 13:58:12.750629",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",
@@ -504,4 +497,4 @@
"sort_field": "modified",
"sort_order": "ASC",
"track_changes": 1
}
}

+ 0
- 112
frappe/public/js/frappe/socketio_client.js Переглянути файл

@@ -54,7 +54,6 @@ frappe.socketio = {

frappe.socketio.setup_listeners();
frappe.socketio.setup_reconnect();
frappe.socketio.uploader = new frappe.socketio.SocketIOUploader();

$(document).on('form-load form-rename', function(e, frm) {
if (frm.is_new()) {
@@ -257,114 +256,3 @@ frappe.realtime.publish = function(event, message) {
}
}

frappe.socketio.SocketIOUploader = class SocketIOUploader {
constructor() {
frappe.socketio.socket.on('upload-request-slice', (data) => {
var place = data.currentSlice * this.chunk_size,
slice = this.file.slice(place,
place + Math.min(this.chunk_size, this.file.size - place));

if (this.on_progress) {
// update progress
this.on_progress(place / this.file.size * 100);
}

this.reader.readAsArrayBuffer(slice);
this.started = true;
this.keep_alive();
});

frappe.socketio.socket.on('upload-end', (data) => {
this.reader = null;
this.file = null;
if (data.file_url.substr(0, 7)==='/public') {
data.file_url = data.file_url.substr(7);
}
this.callback(data);
});

frappe.socketio.socket.on('upload-error', (data) => {
this.disconnect(false);
frappe.msgprint({
title: __('Upload Failed'),
message: data.error,
indicator: 'red'
});
});

frappe.socketio.socket.on('disconnect', () => {
this.disconnect();
});
}

start({file=null, is_private=0, filename='', callback=null, on_progress=null,
chunk_size=24576, fallback=null} = {}) {

if (this.reader) {
frappe.throw(__('File Upload in Progress. Please try again in a few moments.'));
}

function fallback_required() {
return !frappe.socketio.socket.connected
|| !( !frappe.boot.sysdefaults || frappe.boot.sysdefaults.use_socketio_to_upload_file );
}

if (fallback_required()) {
return fallback ? fallback() : frappe.throw(__('Socketio is not connected. Cannot upload'));
}

this.reader = new FileReader();
this.file = file;
this.chunk_size = chunk_size;
this.callback = callback;
this.on_progress = on_progress;
this.fallback = fallback;
this.started = false;

this.reader.onload = () => {
frappe.socketio.socket.emit('upload-accept-slice', {
is_private: is_private,
name: filename,
type: this.file.type,
size: this.file.size,
data: this.reader.result
});
this.keep_alive();
};

var slice = file.slice(0, this.chunk_size);
this.reader.readAsArrayBuffer(slice);
}

keep_alive() {
if (this.next_check) {
clearTimeout (this.next_check);
}
this.next_check = setTimeout (() => {
if (!this.started) {
// upload never started, so try fallback
if (this.fallback) {
this.fallback();
} else {
this.disconnect();
}
}
this.disconnect();
}, 3000);
}

disconnect(with_message = true) {
if (this.reader) {
this.reader = null;
this.file = null;
frappe.hide_progress();
if (with_message) {
frappe.msgprint({
title: __('File Upload'),
message: __('File Upload Disconnected. Please try again.'),
indicator: 'red'
});
}
}
}
}

+ 0
- 41
socketio.js Переглянути файл

@@ -216,47 +216,6 @@ io.on('connection', function (socket) {
'type'
);
});

socket.on('upload-accept-slice', (data) => {
try {
if (!socket.files[data.name]) {
socket.files[data.name] = Object.assign({}, files_struct, data);
socket.files[data.name].data = [];
}

//convert the ArrayBuffer to Buffer
data.data = new Buffer(new Uint8Array(data.data));
//save the data
socket.files[data.name].data.push(data.data);
socket.files[data.name].slice++;

if (socket.files[data.name].slice * 24576 >= socket.files[data.name].size) {
// do something with the data
var fileBuffer = Buffer.concat(socket.files[data.name].data);

const file_url = path.join((socket.files[data.name].is_private ? 'private' : 'public'),
'files', data.name);
const file_path = path.join('sites', get_site_name(socket), file_url);

fs.writeFile(file_path, fileBuffer, (err) => {
delete socket.files[data.name];
if (err) return socket.emit('upload error');
socket.emit('upload-end', {
file_url: '/' + file_url
});
});
} else {
socket.emit('upload-request-slice', {
currentSlice: socket.files[data.name].slice
});
}
} catch (e) {
log(e);
socket.emit('upload-error', {
error: e.message
});
}
});
});

subscriber.on("message", function (_channel, message) {


Завантаження…
Відмінити
Зберегти