From 1031818a58e821970cfb26ecefe1c4f842c1a25f Mon Sep 17 00:00:00 2001 From: zhihao Date: Thu, 11 Feb 2021 09:10:38 +0100 Subject: [PATCH 1/5] replace '\\' to '/' and double check in bridge --- src/renderer/logic/uploader.js | 38 ++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/renderer/logic/uploader.js b/src/renderer/logic/uploader.js index 7e1b8d98c..c7ec3cb1e 100644 --- a/src/renderer/logic/uploader.js +++ b/src/renderer/logic/uploader.js @@ -75,11 +75,21 @@ async function uploadNewFile(storj, filePath, nCurrent, nTotal) { mkdirp.sync(tempPath) } - const relativePath = path.relative(folderRoot, filePath) + let relativePath = path.relative(folderRoot, filePath) + relativePath = relativePath.replace(/\\/g, '/') Logger.log('Network name should be: %s', relativePath) const hashName = Hash.hasher(relativePath) + console.log(hashName) // Double check: Prevent upload if file already exist - const maybeNetworkId = await BridgeService.findFileByName(bucketId, hashName) + let maybeNetworkId = await BridgeService.findFileByName(bucketId, hashName) + // this will remove in the future version + if (!maybeNetworkId) { + maybeNetworkId = await BridgeService.findFileByName( + bucketId, + Hash.hasher(relativePath.replace(/\//g, '\\')) + ) + } + if (maybeNetworkId) { return File.createFileEntry( bucketId, @@ -125,7 +135,6 @@ async function uploadNewFile(storj, filePath, nCurrent, nTotal) { return new Promise((resolve, reject) => { const state = storj.storeFile(bucketId, tempFile, { - filename: hashName, progressCallback: function(progress, uploadedBytes, totalBytes) { let progressPtg = progress * 100 progressPtg = progressPtg.toFixed(2) @@ -155,9 +164,6 @@ async function uploadNewFile(storj, filePath, nCurrent, nTotal) { // File already exists, so there's no need to upload again. Logger.warn('FILE ALREADY EXISTS', tempFile) - // Right now file names in network are full paths encrypted. - // This could be an issue if user uses multiple devices. - // TODO: Migrate to relative paths based on drive folder path const networkId = await BridgeService.findFileByName( bucketId, hashName @@ -276,11 +282,20 @@ async function uploadZeroSizeFile(filePath, nCurrent, nTotal) { const finalName = encryptedFileName + (fileExt ? '.' + fileExt : '') - const relativePath = path.relative(folderRoot, filePath) + let relativePath = path.relative(folderRoot, filePath) + relativePath = relativePath.replace(/\\/g, '/') Logger.log('Network name should be: %s', relativePath) const hashName = Hash.hasher(relativePath) // Double check: Prevent upload if file already exists - const maybeNetworkId = await BridgeService.findFileByName(bucketId, hashName) + let maybeNetworkId = await BridgeService.findFileByName(bucketId, hashName) + // this will remove in the future version + if (!maybeNetworkId) { + maybeNetworkId = await BridgeService.findFileByName( + bucketId, + Hash.hasher(relativePath.replace(/\//g, '\\')) + ) + } + if (maybeNetworkId) { await File.removeFile(bucketId, maybeNetworkId) await Database.dbFiles.remove({ key: filePath }) @@ -302,6 +317,7 @@ async function uploadFile(storj, filePath, nCurrent, nTotal, item) { const bucketId = fileInfo.value.bucket const fileId = fileInfo.value.fileId const folderId = fileInfo.value.folder_id + const folderRoot = await Database.Get('xPath') // Encrypted filename const originalFileName = path.basename(filePath) @@ -360,8 +376,9 @@ async function uploadFile(storj, filePath, nCurrent, nTotal, item) { if (!fs.existsSync(tempPath)) { mkdirp.sync(tempPath) } - - const tempFile = path.join(tempPath, Hash.hasher(filePath)) + let relativePath = path.relative(folderRoot, filePath) + relativePath = relativePath.replace(/\\/g, '/') + const tempFile = path.join(tempPath, Hash.hasher(relativePath)) if (fs.existsSync(tempFile)) { fs.unlinkSync(tempFile) } @@ -371,7 +388,6 @@ async function uploadFile(storj, filePath, nCurrent, nTotal, item) { // Upload new file return new Promise((resolve, reject) => { const state = storj.storeFile(bucketId, tempFile, { - filename: finalName, progressCallback: function(progress, uploadedBytes, totalBytes) { let progressPtg = progress * 100 progressPtg = progressPtg.toFixed(2) From 97b69f54af2232a43c155bd6ca19495639b6e1d3 Mon Sep 17 00:00:00 2001 From: zhihao Date: Thu, 11 Feb 2021 09:20:25 +0100 Subject: [PATCH 2/5] disable console.log when ignore system file --- src/renderer/logic/tree.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/logic/tree.js b/src/renderer/logic/tree.js index b36dd7ef7..d55c26d6e 100644 --- a/src/renderer/logic/tree.js +++ b/src/renderer/logic/tree.js @@ -31,8 +31,6 @@ function getListFromFolder(folderPath) { if (typeof invalid === 'undefined') { results.push(data.fullPath) - } else { - console.log('ignored') } }) .on('warn', warn => Logger.error('READDIRP non-fatal error', warn)) From 6c31ff622f0e1275164b8825c57b1f09f561bfec Mon Sep 17 00:00:00 2001 From: zhihao Date: Thu, 11 Feb 2021 10:02:14 +0100 Subject: [PATCH 3/5] changed identify of segment --- src/renderer/components/LoginPage.vue | 5 +---- src/renderer/logic/sync/OneWayUpload.js | 8 +++++++- src/renderer/logic/sync/TwoWaySync.js | 7 ++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/renderer/components/LoginPage.vue b/src/renderer/components/LoginPage.vue index a3cd6f20d..5184125c6 100644 --- a/src/renderer/components/LoginPage.vue +++ b/src/renderer/components/LoginPage.vue @@ -261,10 +261,7 @@ export default { .identify({ userId: undefined, platform: 'desktop', - email: 'email', - traits: { - storage_used: ConfigStore.get('usage') - } + email: 'email' }) .then(() => { analytics.track({ diff --git a/src/renderer/logic/sync/OneWayUpload.js b/src/renderer/logic/sync/OneWayUpload.js index 223d3c696..00336d58a 100644 --- a/src/renderer/logic/sync/OneWayUpload.js +++ b/src/renderer/logic/sync/OneWayUpload.js @@ -12,6 +12,7 @@ import ConfigStore from '../../../main/config-store' import SpaceUsage from '../utils/spaceusage' import analytics from '../utils/analytics' +import { listenerCount } from 'nedb' /* * Sync Method: One Way, from LOCAL to CLOUD (Only Upload) @@ -214,13 +215,18 @@ async function SyncLogic(callback) { next => Uploader.uploadNewFiles() .then(() => { + const limit = ConfigStore.get('limit') / 1024 + const used = ConfigStore.get('usage') / 1024 + const usage = Math.round(1000 * used / limit) / 10 analytics .identify({ userId: undefined, platform: 'desktop', email: 'email', traits: { - storage_used: ConfigStore.get('usage') + storage_used: used, + storage_limit: limit, + storage_usage: usage } }) .catch(err => { diff --git a/src/renderer/logic/sync/TwoWaySync.js b/src/renderer/logic/sync/TwoWaySync.js index b7f57d7a8..484a0e051 100644 --- a/src/renderer/logic/sync/TwoWaySync.js +++ b/src/renderer/logic/sync/TwoWaySync.js @@ -233,13 +233,18 @@ async function SyncLogic(callback) { // Search new files in local folder, and upload them Uploader.uploadNewFiles() .then(() => { + const limit = ConfigStore.get('limit') / 1024 + const used = ConfigStore.get('usage') / 1024 + const usage = Math.round(1000 * used / limit) / 10 analytics .identify({ userId: undefined, platform: 'desktop', email: 'email', traits: { - storage_used: ConfigStore.get('usage') + storage_used: used, + storage_limit: limit, + storage_usage: usage } }) .catch(err => { From 065d1aea466ba2f353d7f426e998805e69697be9 Mon Sep 17 00:00:00 2001 From: zhihao Date: Thu, 11 Feb 2021 10:22:30 +0100 Subject: [PATCH 4/5] only set syncstop to true if is syncing logout when is not syncing setted syncstop to true, so if you login again the sync will stop immediate --- src/renderer/logic/sync/OneWayUpload.js | 6 ++++-- src/renderer/logic/sync/TwoWaySync.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/renderer/logic/sync/OneWayUpload.js b/src/renderer/logic/sync/OneWayUpload.js index 00336d58a..520711f9f 100644 --- a/src/renderer/logic/sync/OneWayUpload.js +++ b/src/renderer/logic/sync/OneWayUpload.js @@ -28,8 +28,10 @@ let lastSyncFailed = false let timeoutInstance = null function syncStop() { - ConfigStore.set('isSyncing', false) - ConfigStore.set('stopSync', true) + if (ConfigStore.get('isSyncing')) { + ConfigStore.set('isSyncing', false) + ConfigStore.set('stopSync', true) + } app.emit('sync-off') } diff --git a/src/renderer/logic/sync/TwoWaySync.js b/src/renderer/logic/sync/TwoWaySync.js index 484a0e051..0bbe0b8f4 100644 --- a/src/renderer/logic/sync/TwoWaySync.js +++ b/src/renderer/logic/sync/TwoWaySync.js @@ -27,8 +27,10 @@ let timeoutInstance = null const { app } = electron.remote function syncStop() { - ConfigStore.set('isSyncing', false) - ConfigStore.set('stopSync', true) + if (ConfigStore.get('isSyncing')) { + ConfigStore.set('isSyncing', false) + ConfigStore.set('stopSync', true) + } app.emit('sync-off') } From 328eb09a82ed5a1c1a16cf8079d95f255cf3c285 Mon Sep 17 00:00:00 2001 From: zhihao Date: Thu, 11 Feb 2021 11:49:44 +0100 Subject: [PATCH 5/5] hide some item of traymenu when user is not sign-in --- src/main/traymenu.js | 191 ++++++++++++++++++++++--------------------- 1 file changed, 99 insertions(+), 92 deletions(-) diff --git a/src/main/traymenu.js b/src/main/traymenu.js index ee873b05b..c79767ee9 100644 --- a/src/main/traymenu.js +++ b/src/main/traymenu.js @@ -75,115 +75,122 @@ class TrayMenu { const userFooter = [ { type: 'separator' - }, - { - label: 'Change sync folder', - click: function() { - const newDir = dialog.showOpenDialogSync({ - properties: ['openDirectory'] - }) - if (newDir && newDir.length > 0 && fs.existsSync(newDir[0])) { - app.emit('new-folder-path', newDir[0]) - } else { - Logger.info('Sync folder change error or cancelled') - } - } } ] + if (userEmail) { + userFooter.push( + { + label: 'Change sync folder', + click: function () { + const newDir = dialog.showOpenDialogSync({ + properties: ['openDirectory'] + }) + if (newDir && newDir.length > 0 && fs.existsSync(newDir[0])) { + app.emit('new-folder-path', newDir[0]) + } else { + Logger.info('Sync folder change error or cancelled') + } + } + }) + } userMenu = Array.concat(userEmailDisplay, userUsage, userFooter) } - const contextMenuTemplate = [ - { + const contextMenuTemplate = [] + if (userEmail) { + contextMenuTemplate.push({ label: 'Open folder', - click: function() { + click: function () { app.emit('open-folder') } - }, - { - label: 'Sync options', - enabled: true, - submenu: [ - { - label: 'Two Way Sync', - type: 'radio', - enabled: true, - checked: ConfigStore.get('syncMode') === 'two-way', - click: () => { - Logger.info('User switched to two way sync mode') - ConfigStore.set('syncMode', 'two-way') - app.emit('sync-stop') - app.emit('switch-mode') - } - }, - { - label: 'Upload Only Mode', - type: 'radio', - enabled: true, - checked: ConfigStore.get('syncMode') === 'one-way-upload', - click: () => { - Logger.info('User switched to one way upload mode') - ConfigStore.set('syncMode', 'one-way-upload') - app.emit('sync-stop') - } + }) + } + contextMenuTemplate.push({ + label: 'Sync options', + enabled: true, + submenu: [ + { + label: 'Two Way Sync', + type: 'radio', + enabled: true, + checked: ConfigStore.get('syncMode') === 'two-way', + click: () => { + Logger.info('User switched to two way sync mode') + ConfigStore.set('syncMode', 'two-way') + app.emit('sync-stop') + app.emit('switch-mode') } - ] - }, - { - label: 'Force sync', - click: function() { - app.emit('force-sync') - } - }, - { - label: 'Open logs', - click: function() { - try { - const logFile = electronLog.transports.file.getFile().path - const logPath = path.dirname(logFile) - shell.openItem(logPath) - } catch (e) { - Logger.error('Error opening log path: %s', e.message) + }, + { + label: 'Upload Only Mode', + type: 'radio', + enabled: true, + checked: ConfigStore.get('syncMode') === 'one-way-upload', + click: () => { + Logger.info('User switched to one way upload mode') + ConfigStore.set('syncMode', 'one-way-upload') + app.emit('sync-stop') } } - }, - { - label: 'Billing', - click: function() { - shell.openExternal(`${process.env.API_URL}/storage`) - } - }, - { - label: 'Launch at login', - type: 'checkbox', - checked: ConfigStore.get('autoLaunch'), - click: function(check) { - ConfigStore.set('autoLaunch', check.checked) - console.log(check.checked) - app.emit('change-auto-launch') + ] + }) + if (userEmail) { + contextMenuTemplate.push({ + label: 'Force sync', + click: function () { + app.emit('force-sync') } - }, - { - label: 'Contact Support', - click: function() { - shell.openExternal(`mailto:support@internxt.zohodesk.eu?subject=Support Ticket&body=If you want to upload log files to our tech teams. Please, find them on the Open Logs option in the menu.`) + }) + } + contextMenuTemplate.push({ + label: 'Open logs', + click: function () { + try { + const logFile = electronLog.transports.file.getFile().path + const logPath = path.dirname(logFile) + shell.openItem(logPath) + } catch (e) { + Logger.error('Error opening log path: %s', e.message) } - }, - { - type: 'separator' - }, - { + } + }, { + label: 'Billing', + click: function () { + shell.openExternal(`${process.env.API_URL}/storage`) + } + }, { + label: 'Launch at login', + type: 'checkbox', + checked: ConfigStore.get('autoLaunch'), + click: function (check) { + ConfigStore.set('autoLaunch', check.checked) + console.log(check.checked) + app.emit('change-auto-launch') + } + }, { + label: 'Contact Support', + click: function () { + shell.openExternal(`mailto:support@internxt.zohodesk.eu?subject=Support Ticket&body=If you want to upload log files to our tech teams. Please, find them on the Open Logs option in the menu.`) + } + }, + { + type: 'separator' + }) + + if (userEmail) { + contextMenuTemplate.push({ label: 'Log out', - click: function() { + click: function () { app.emit('user-logout') } - }, - { - label: 'Quit', - click: this.appClose - } - ] + }) + } + contextMenuTemplate.push({ + label: 'Quit', + click: this.appClose + }) + return Menu.buildFromTemplate(Array.concat(userMenu, contextMenuTemplate)) }