Compare commits
2 Commits
d5a4eac1ae
...
dec8e60a2f
| Author | SHA1 | Date |
|---|---|---|
|
|
dec8e60a2f | |
|
|
f149804dba |
75
main.js
75
main.js
|
|
@ -5,12 +5,17 @@ const https = require('https');
|
|||
|
||||
let store;
|
||||
let mainWindow;
|
||||
let fetch;
|
||||
|
||||
// Initialize store using dynamic import
|
||||
// Initialize store and fetch using dynamic import
|
||||
(async () => {
|
||||
const Store = await import('electron-store');
|
||||
const [Store, { default: nodeFetch }] = await Promise.all([
|
||||
import('electron-store'),
|
||||
import('node-fetch')
|
||||
]);
|
||||
store = new Store.default();
|
||||
console.log('Store initialized');
|
||||
fetch = nodeFetch;
|
||||
console.log('Store and fetch initialized');
|
||||
})();
|
||||
|
||||
function createWindow() {
|
||||
|
|
@ -200,8 +205,66 @@ ipcMain.on('select-folder', (event) => {
|
|||
});
|
||||
});
|
||||
|
||||
ipcMain.on('start-sync', (event, config) => {
|
||||
ipcMain.on('start-sync', async (event, config) => {
|
||||
console.log('Starting sync with config:', config);
|
||||
// Here you can implement the sync logic using the config.destFolder
|
||||
// and config.onedriveSource parameters
|
||||
|
||||
try {
|
||||
// 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,7 +9,8 @@
|
|||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"electron-store": "^10.0.0"
|
||||
"electron-store": "^10.0.0",
|
||||
"node-fetch": "^3.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^33.2.1"
|
||||
|
|
@ -255,6 +256,14 @@
|
|||
"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": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/debounce-fn/-/debounce-fn-6.0.0.tgz",
|
||||
|
|
@ -541,6 +550,39 @@
|
|||
"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": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
||||
|
|
@ -783,6 +825,41 @@
|
|||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"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": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||
|
|
@ -999,6 +1076,14 @@
|
|||
"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": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/when-exit/-/when-exit-2.1.3.tgz",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
"electron": "^33.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-store": "^10.0.0"
|
||||
"electron-store": "^10.0.0",
|
||||
"node-fetch": "^3.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue