Compare commits
No commits in common. "dec8e60a2f7c04a8730245013f0af254808be618" and "d5a4eac1ae97a078d5be14f8655a025af0a9dc90" have entirely different histories.
dec8e60a2f
...
d5a4eac1ae
75
main.js
75
main.js
|
|
@ -5,17 +5,12 @@ const https = require('https');
|
||||||
|
|
||||||
let store;
|
let store;
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
let fetch;
|
|
||||||
|
|
||||||
// Initialize store and fetch using dynamic import
|
// Initialize store using dynamic import
|
||||||
(async () => {
|
(async () => {
|
||||||
const [Store, { default: nodeFetch }] = await Promise.all([
|
const Store = await import('electron-store');
|
||||||
import('electron-store'),
|
|
||||||
import('node-fetch')
|
|
||||||
]);
|
|
||||||
store = new Store.default();
|
store = new Store.default();
|
||||||
fetch = nodeFetch;
|
console.log('Store initialized');
|
||||||
console.log('Store and fetch initialized');
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
|
|
@ -205,66 +200,8 @@ ipcMain.on('select-folder', (event) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('start-sync', async (event, config) => {
|
ipcMain.on('start-sync', (event, config) => {
|
||||||
console.log('Starting sync with config:', config);
|
console.log('Starting sync with config:', config);
|
||||||
|
// Here you can implement the sync logic using the config.destFolder
|
||||||
try {
|
// and config.onedriveSource parameters
|
||||||
// Get cookies from all relevant domains
|
|
||||||
const cookies = await Promise.all([
|
|
||||||
session.defaultSession.cookies.get({domain: '.onedrive.com'}),
|
|
||||||
session.defaultSession.cookies.get({domain: '.live.com'}),
|
|
||||||
session.defaultSession.cookies.get({domain: '.microsoft.com'})
|
|
||||||
]);
|
|
||||||
|
|
||||||
const allCookies = [].concat(...cookies);
|
|
||||||
console.log('Available cookies:', allCookies.map(c => c.name));
|
|
||||||
|
|
||||||
// Try different possible token cookie names
|
|
||||||
const accessToken = allCookies.find(
|
|
||||||
cookie =>
|
|
||||||
cookie.name === 'access_token' ||
|
|
||||||
cookie.name === 'AccessToken' ||
|
|
||||||
cookie.name.startsWith('AccessToken-') ||
|
|
||||||
cookie.name.includes('Graph')
|
|
||||||
)?.value;
|
|
||||||
|
|
||||||
if (!accessToken) {
|
|
||||||
throw new Error('Access token not found in cookies');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up and encode the OneDrive path
|
|
||||||
const cleanPath = config.onedriveSource
|
|
||||||
.replace(/^\/+|\/+$/g, '') // Remove leading/trailing slashes
|
|
||||||
.split('/')
|
|
||||||
.map(segment => encodeURIComponent(segment))
|
|
||||||
.join('/');
|
|
||||||
|
|
||||||
const url = `https://graph.microsoft.com/v1.0/me/drive/root:/${cleanPath}:/children`;
|
|
||||||
console.log('Querying OneDrive items from:', url);
|
|
||||||
|
|
||||||
// Query OneDrive items using Graph API
|
|
||||||
const response = await fetch(url, {
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Origin': 'https://onedrive.live.com',
|
|
||||||
'Referer': 'https://onedrive.live.com/'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json();
|
|
||||||
console.error('Graph API error details:', errorData);
|
|
||||||
throw new Error(`Graph API error: ${response.status} ${response.statusText}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
console.log('Found items:', data.value.length);
|
|
||||||
|
|
||||||
event.reply('sync-items-found', data.value);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Sync error:', error);
|
|
||||||
event.reply('sync-error', error.message);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-store": "^10.0.0",
|
"electron-store": "^10.0.0"
|
||||||
"node-fetch": "^3.3.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^33.2.1"
|
"electron": "^33.2.1"
|
||||||
|
|
@ -256,14 +255,6 @@
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/data-uri-to-buffer": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
|
||||||
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/debounce-fn": {
|
"node_modules/debounce-fn": {
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/debounce-fn/-/debounce-fn-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/debounce-fn/-/debounce-fn-6.0.0.tgz",
|
||||||
|
|
@ -550,39 +541,6 @@
|
||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fetch-blob": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
|
|
||||||
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/jimmywarting"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "paypal",
|
|
||||||
"url": "https://paypal.me/jimmywarting"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"node-domexception": "^1.0.0",
|
|
||||||
"web-streams-polyfill": "^3.0.3"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "^12.20 || >= 14.13"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/formdata-polyfill": {
|
|
||||||
"version": "4.0.10",
|
|
||||||
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
|
|
||||||
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
|
|
||||||
"dependencies": {
|
|
||||||
"fetch-blob": "^3.1.2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12.20.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/fs-extra": {
|
"node_modules/fs-extra": {
|
||||||
"version": "8.1.0",
|
"version": "8.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
||||||
|
|
@ -825,41 +783,6 @@
|
||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/node-domexception": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/jimmywarting"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://paypal.me/jimmywarting"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10.5.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/node-fetch": {
|
|
||||||
"version": "3.3.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
|
|
||||||
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
|
|
||||||
"dependencies": {
|
|
||||||
"data-uri-to-buffer": "^4.0.0",
|
|
||||||
"fetch-blob": "^3.1.4",
|
|
||||||
"formdata-polyfill": "^4.0.10"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/node-fetch"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/normalize-url": {
|
"node_modules/normalize-url": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||||
|
|
@ -1076,14 +999,6 @@
|
||||||
"node": ">= 4.0.0"
|
"node": ">= 4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/web-streams-polyfill": {
|
|
||||||
"version": "3.3.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
|
|
||||||
"integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/when-exit": {
|
"node_modules/when-exit": {
|
||||||
"version": "2.1.3",
|
"version": "2.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/when-exit/-/when-exit-2.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/when-exit/-/when-exit-2.1.3.tgz",
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
"electron": "^33.2.1"
|
"electron": "^33.2.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-store": "^10.0.0",
|
"electron-store": "^10.0.0"
|
||||||
"node-fetch": "^3.3.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue