-
Notifications
You must be signed in to change notification settings - Fork 868
/
Copy pathOneDrivePage.vue
116 lines (114 loc) · 3.42 KB
/
OneDrivePage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<div>
<div>
<div class="text warning" v-show="needEncryption">
{{ i18n.encryption_required }}
</div>
<div v-show="backupToken">
<div style="margin: 10px 0px 0px 20px; overflow-wrap: break-word">
{{ i18n.account }} - {{ email }}
</div>
</div>
<a-button v-show="backupToken" @click="backupLogout()">
{{ i18n.log_out }}
</a-button>
<a-button
v-show="!backupToken && !needEncryption"
@click="getBackupToken()"
>
{{ i18n.sign_in }}
</a-button>
<a-button
v-show="!backupToken && !needEncryption"
@click="getBackupToken(true)"
>
{{ i18n.sign_in_business }}
</a-button>
<div class="text" v-show="!backupToken && !needEncryption">
<a
v-on:click="openLink('https://otp.ee/onedriveperms')"
href="https://otp.ee/onedriveperms"
>{{ i18n.onedrive_business_perms }}</a
>
</div>
<a-button v-show="backupToken && !needEncryption" @click="backupUpload()">
{{ i18n.manual_dropbox }}
</a-button>
</div>
</div>
</template>
<script lang="ts">
import Vue from "vue";
import { OneDrive } from "../../models/backup";
import { UserSettings } from "../../models/settings";
const service = "onedrive";
export default Vue.extend({
data: function () {
return {
email: this.i18n.loading,
};
},
created() {
UserSettings.updateItems();
},
computed: {
defaultEncryption: function () {
return this.$store.state.accounts.defaultEncryption;
},
allEntriesEncrypted: function (): boolean {
return this.$store.getters["accounts/allEntriesEncrypted"];
},
needEncryption: function (): boolean {
return !this.defaultEncryption || !this.allEntriesEncrypted;
},
backupToken: function (): string | undefined {
return this.$store.state.backup.oneDriveToken;
},
},
methods: {
openLink(url: string) {
window.open(url, "_blank");
return;
},
getBackupToken(business?: boolean) {
UserSettings.items.oneDriveBusiness = Boolean(business);
UserSettings.commitItems();
chrome.runtime.sendMessage({ action: service });
},
async backupLogout() {
UserSettings.items.oneDriveToken = undefined;
UserSettings.items.oneDriveRefreshToken = undefined;
UserSettings.commitItems();
this.$store.commit("backup/setToken", { service, value: false });
this.$store.commit("style/hideInfo");
},
async backupUpload() {
const oneDrive = new OneDrive();
const response = await oneDrive.upload(
this.$store.state.accounts.encryption
);
if (response === true) {
this.$store.commit("notification/alert", this.i18n.updateSuccess);
} else if (UserSettings.items.oneDriveRevoked === true) {
this.$store.commit(
"notification/alert",
chrome.i18n.getMessage("token_revoked", ["OneDrive"])
);
UserSettings.removeItem("oneDriveRevoked");
this.$store.commit("backup/setToken", { service, value: false });
} else {
this.$store.commit("notification/alert", this.i18n.updateFailure);
}
},
async getUser() {
const oneDrive = new OneDrive();
return await oneDrive.getUser();
},
},
mounted: async function () {
if (this.backupToken) {
this.email = await this.getUser();
}
},
});
</script>