提交 56d6b060 编写于 作者: R rsercano

almost done #352

上级 aae14c14
......@@ -53,7 +53,7 @@ export const initFilesInformation = function () {
return;
}
Meteor.call('getFileInfos', $('#txtBucketName').val(), selector, $('#txtFileFetchLimit').val(), function (err, result) {
Meteor.call('getFileInfos', $('#txtBucketName').val(), selector, $('#txtFileFetchLimit').val(), Meteor.default_connection._lastSessionId, function (err, result) {
if (err || result.error) {
Helper.showMeteorFuncError(err, result, "Couldn't get file informations");
return;
......@@ -142,7 +142,7 @@ Template.fileManagement.events({
return;
}
Meteor.call('deleteFiles', $('#txtBucketName').val(), selector,Meteor.default_connection._lastSessionId, function (err, result) {
Meteor.call('deleteFiles', $('#txtBucketName').val(), selector, Meteor.default_connection._lastSessionId, function (err, result) {
if (err || result.err) {
Helper.showMeteorFuncError(err, result, "Couldn't delete files");
} else {
......@@ -163,7 +163,7 @@ Template.fileManagement.events({
e.preventDefault();
const fileRow = Session.get(Helper.strSessionSelectedFile);
if (fileRow) {
window.open('download?fileId=' + fileRow._id + '&bucketName=' + $('#txtBucketName').val());
window.open('download?fileId=' + fileRow._id + '&bucketName=' + $('#txtBucketName').val() + '&sessionId=' + Meteor.default_connection._lastSessionId);
}
},
......@@ -183,7 +183,7 @@ Template.fileManagement.events({
if (isConfirm) {
Ladda.create(document.querySelector('#btnReloadFiles')).start();
Meteor.call('deleteFile', $('#txtBucketName').val(), fileRow._id, function (err) {
Meteor.call('deleteFile', $('#txtBucketName').val(), fileRow._id, Meteor.default_connection._lastSessionId, function (err) {
if (err) {
toastr.error("Couldn't delete: " + err.message);
} else {
......@@ -216,7 +216,7 @@ Template.fileManagement.events({
delete setValue._id;
Meteor.call('updateOne', $('#txtBucketName').val() + '.files',
{'_id': {"$oid": Session.get(Helper.strSessionSelectedFile)._id}}, {"$set": setValue}, {},Meteor.default_connection._lastSessionId, function (err) {
{'_id': {"$oid": Session.get(Helper.strSessionSelectedFile)._id}}, {"$set": setValue}, {}, Meteor.default_connection._lastSessionId, function (err) {
if (err) {
toastr.error("Couldn't update file info: " + err.message);
} else {
......
......@@ -53,7 +53,7 @@ export const proceedUploading = function (blob, contentType, metaData, aliases)
Ladda.create(document.querySelector('#btnUpload')).start();
const fileReader = new FileReader();
fileReader.onload = function (file) {
Meteor.call('uploadFile', $('#txtBucketName').val(), new Uint8Array(file.target.result), blob.name, contentType, metaData, aliases, function (err, result) {
Meteor.call('uploadFile', $('#txtBucketName').val(), new Uint8Array(file.target.result), blob.name, contentType, metaData, aliases, Meteor.default_connection._lastSessionId, function (err, result) {
if (err || result.error) {
Helper.showMeteorFuncError(err, result, "Couldn't upload file");
}
......
......@@ -96,6 +96,7 @@ const migrateSSHPart = function (oldConnection, connection) {
host: oldConnection.sshAddress,
port: oldConnection.sshPort,
username: oldConnection.sshUser,
destinationPort: oldConnection.sshPort
};
if (oldConnection.sshPassword) connection.ssh.password = oldConnection.sshPassword;
......@@ -117,7 +118,7 @@ function tryInjectDefaultConnection() {
connection.connectionName = DEFAULT_CONNECTION_NAME;
// delete existing connection after we parsed the new one
let existingConnection = Connections.findOne({ connectionName: DEFAULT_CONNECTION_NAME });
let existingConnection = Connections.findOne({connectionName: DEFAULT_CONNECTION_NAME});
if (existingConnection) {
Connections.remove(existingConnection._id);
connection._id = existingConnection._id;
......@@ -155,5 +156,5 @@ Meteor.startup(function () {
ShellCommands.remove({});
SchemaAnalyzeResult.remove({});
migrateConnectionsIfExist();
tryInjectDefaultConnection();
tryInjectDefaultConnection();
});
......@@ -21,7 +21,7 @@ const proceedMapReduceExecution = function (selectedCollection, map, reduce, opt
done(err, null);
return;
}
if ((typeof options.out) == 'string') {
if ((typeof options.out) === 'string') {
resultCollection.find().toArray(function (err, result) {
done(err, result);
});
......@@ -47,12 +47,12 @@ export const proceedQueryExecution = function (selectedCollection, methodArray,
try {
let execution = databasesBySessionId[sessionId].collection(selectedCollection);
for (let i = 0; i < methodArray.length; i++) {
let last = i == (methodArray.length - 1);
let last = (i === (methodArray.length - 1));
let entry = methodArray[i];
entry = Helper.convertJSONtoBSON(entry);
for (let key in entry) {
if (entry.hasOwnProperty(key)) {
if (last && key == Object.keys(entry)[Object.keys(entry).length - 1]) {
if (last && key === Object.keys(entry)[Object.keys(entry).length - 1]) {
entry[key].push(function (err, docs) {
done(err, docs);
});
......
......@@ -22,7 +22,6 @@ export let databasesBySessionId = {};
let spawnedShellsBySessionId = {};
let tunnelsBySessionId = {};
export let database;
let spawnedShell;
let tunnel;
......
......@@ -4,21 +4,21 @@
/*global Async*/
import LOGGER from "../internal/logger";
import Helper from "./helper";
import {database} from "./methods_common";
import {databasesBySessionId} from "./methods_common";
import {Meteor} from "meteor/meteor";
const mongodbApi = require('mongodb');
Meteor.methods({
deleteFiles(bucketName, selector){
LOGGER.info('[deleteFiles]', bucketName, selector);
deleteFiles(bucketName, selector, sessionId){
LOGGER.info('[deleteFiles]', bucketName, selector, sessionId);
selector = Helper.convertJSONtoBSON(selector);
let result = Async.runSync(function (done) {
try {
let filesCollection = database.collection(bucketName + ".files");
let chunksCollection = database.collection(bucketName + ".chunks");
let filesCollection = databasesBySessionId[sessionId].collection(bucketName + ".files");
let chunksCollection = databasesBySessionId[sessionId].collection(bucketName + ".chunks");
filesCollection.find(selector, {_id: 1}).toArray(function (err, docs) {
if (err) {
......@@ -54,12 +54,12 @@ Meteor.methods({
return Helper.convertBSONtoJSON(result);
},
deleteFile(bucketName, fileId) {
LOGGER.info('[deleteFile]', bucketName, fileId);
deleteFile(bucketName, fileId, sessionId) {
LOGGER.info('[deleteFile]', bucketName, fileId, sessionId);
let result = Async.runSync(function (done) {
try {
const bucket = new mongodbApi.GridFSBucket(database, {bucketName: bucketName});
const bucket = new mongodbApi.GridFSBucket(databasesBySessionId[sessionId], {bucketName: bucketName});
bucket.delete(new mongodbApi.ObjectId(fileId), function (err) {
done(err, null);
});
......@@ -73,16 +73,16 @@ Meteor.methods({
return Helper.convertBSONtoJSON(result);
},
getFileInfos(bucketName, selector, limit) {
getFileInfos(bucketName, selector, limit, sessionId) {
limit = parseInt(limit) || 100;
selector = selector || {};
selector = Helper.convertJSONtoBSON(selector);
LOGGER.info('[getFileInfos]', bucketName, JSON.stringify(selector), limit);
LOGGER.info('[getFileInfos]', bucketName, JSON.stringify(selector), limit, sessionId);
let result = Async.runSync(function (done) {
try {
const bucket = new mongodbApi.GridFSBucket(database, {bucketName: bucketName});
const bucket = new mongodbApi.GridFSBucket(databasesBySessionId[sessionId], {bucketName: bucketName});
bucket.find(selector, {limit: limit}).toArray(function (err, files) {
done(err, files);
});
......@@ -97,18 +97,18 @@ Meteor.methods({
return Helper.convertBSONtoJSON(result);
},
uploadFile(bucketName, blob, fileName, contentType, metaData, aliases) {
uploadFile(bucketName, blob, fileName, contentType, metaData, aliases, sessionId) {
if (metaData) {
metaData = Helper.convertJSONtoBSON(metaData);
}
blob = new Buffer(blob);
LOGGER.info('[uploadFile]', bucketName, fileName, contentType, JSON.stringify(metaData), aliases);
LOGGER.info('[uploadFile]', bucketName, fileName, contentType, JSON.stringify(metaData), aliases, sessionId);
return Async.runSync(function (done) {
try {
const bucket = new mongodbApi.GridFSBucket(database, {bucketName: bucketName});
const bucket = new mongodbApi.GridFSBucket(databasesBySessionId[sessionId], {bucketName: bucketName});
let uploadStream = bucket.openUploadStream(fileName, {
metadata: metaData,
contentType: contentType,
......@@ -126,12 +126,12 @@ Meteor.methods({
});
},
getFile(bucketName, fileId) {
LOGGER.info('[getFile]', bucketName, fileId);
getFile(bucketName, fileId, sessionId) {
LOGGER.info('[getFile]', bucketName, fileId, sessionId);
let result = Async.runSync(function (done) {
try {
let filesCollection = database.collection(bucketName + '.files');
let filesCollection = databasesBySessionId[sessionId].collection(bucketName + '.files');
filesCollection.find({_id: new mongodbApi.ObjectId(fileId)}).limit(1).next(function (err, doc) {
if (doc) {
done(null, doc);
......
/**
* Created by Sercan on 26.10.2016.
*/
import {WebApp} from 'meteor/webapp';
import {Meteor} from 'meteor/meteor';
import {Papa} from 'meteor/harrison:papa-parse';
import {database} from "/server/imports/mongodb/methods_common";
import {WebApp} from "meteor/webapp";
import {Meteor} from "meteor/meteor";
import {Papa} from "meteor/harrison:papa-parse";
import {databasesBySessionId} from "/server/imports/mongodb/methods_common";
import LOGGER from "/server/imports/internal/logger";
const mongodbApi = require('mongodb');
......@@ -18,7 +18,7 @@ WebApp.connectHandlers.use('/export', function (req, res) {
LOGGER.info('[export]', format, selectedCollection, selector, cursorOptions);
Meteor.call("find", selectedCollection, JSON.parse(selector), JSON.parse(cursorOptions), false,Meteor.default_connection._lastSessionId, function (err, result) {
Meteor.call("find", selectedCollection, JSON.parse(selector), JSON.parse(cursorOptions), false, Meteor.default_connection._lastSessionId, function (err, result) {
if (err || result.error) {
LOGGER.error('[export]', err, result.error);
res.writeHead(400);
......@@ -52,8 +52,9 @@ WebApp.connectHandlers.use("/download", function (req, res) {
const urlParts = decodeURI(req.url).split('&');
let fileId = urlParts[0].substr(urlParts[0].indexOf('=') + 1);
let bucketName = urlParts[1].substr(urlParts[1].indexOf('=') + 1);
let sessionId = urlParts[2].substr(urlParts[2].indexOf('=') + 1);
LOGGER.info('[downloadFile]', fileId, bucketName);
LOGGER.info('[downloadFile]', fileId, bucketName, sessionId);
if (!bucketName || !fileId) {
LOGGER.info('[downloadFile]', 'file not found !');
......@@ -63,10 +64,10 @@ WebApp.connectHandlers.use("/download", function (req, res) {
}
try {
let filesCollection = database.collection(bucketName + '.files');
let filesCollection = databasesBySessionId[sessionId].collection(bucketName + '.files');
filesCollection.find({_id: new mongodbApi.ObjectId(fileId)}).limit(1).next(function (err, doc) {
if (doc) {
const bucket = new mongodbApi.GridFSBucket(database, {bucketName: bucketName});
const bucket = new mongodbApi.GridFSBucket(databasesBySessionId[sessionId], {bucketName: bucketName});
const headers = {
'Content-type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename=' + doc.filename
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册