You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-18 23:07:45 +02:00
@ -13,6 +13,7 @@ class OneDriveApi {
|
||||
this.clientId_ = clientId;
|
||||
this.clientSecret_ = clientSecret;
|
||||
this.auth_ = null;
|
||||
this.accountProperties_ = null;
|
||||
this.isPublic_ = isPublic;
|
||||
this.listeners_ = {
|
||||
authRefreshed: [],
|
||||
@ -73,14 +74,15 @@ class OneDriveApi {
|
||||
}
|
||||
|
||||
async appDirectory() {
|
||||
const r = await this.execJson('GET', '/drive/special/approot');
|
||||
const driveId = this.accountProperties_.driveId;
|
||||
const r = await this.execJson('GET', `/me/drives/${driveId}/special/approot`);
|
||||
return `${r.parentReference.path}/${r.name}`;
|
||||
}
|
||||
|
||||
authCodeUrl(redirectUri) {
|
||||
const query = {
|
||||
client_id: this.clientId_,
|
||||
scope: 'files.readwrite offline_access',
|
||||
scope: 'files.readwrite offline_access sites.readwrite.all',
|
||||
response_type: 'code',
|
||||
redirect_uri: redirectUri,
|
||||
};
|
||||
@ -320,6 +322,29 @@ class OneDriveApi {
|
||||
throw new Error(`Could not execute request after multiple attempts: ${method} ${url}`);
|
||||
}
|
||||
|
||||
setAccountProperties(accountProperties) {
|
||||
this.accountProperties_ = accountProperties;
|
||||
}
|
||||
|
||||
async execAccountPropertiesRequest() {
|
||||
const response = await shim.fetch('https://graph.microsoft.com/v1.0/me/drive', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': this.token(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Could not retrieve account details (drive ID, Account type): ${response.status}: ${response.statusText}: ${text}`);
|
||||
} else {
|
||||
const data = await response.json();
|
||||
const accountProperties = { accountType: data.driveType, driveId: data.id };
|
||||
return accountProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async execJson(method, path, query, data) {
|
||||
const response = await this.exec(method, path, query, data);
|
||||
const errorResponseText = await response.text();
|
||||
|
Reference in New Issue
Block a user