Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions core/frontend/src/components/cloud/CloudTrayMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ export default Vue.extend({
this.operation_error_title = title
this.operation_error_message = String(error)
},
async cleanMajorTomToken(): Promise<void> {
async cleanMajorTomBagToken(): Promise<void> {
const data = await bag.getData('major_tom')
if (data && data.token) {
delete data.token
}
await bag.setData('major_tom', { ...data })
},
async cleanMajorTomFileToken(): Promise<void> {
await filebrowser.deleteFile(MAJOR_TOM_CLOUD_TOKEN_FILE)
},
async fetchMajorTomData(): Promise<InstalledExtensionData> {
Expand Down Expand Up @@ -319,18 +321,35 @@ export default Vue.extend({
}

if (!await this.isMajorTomTokenValid(tokenToUse, true)) {
await this.cleanMajorTomToken()
/** We do not remove the token since it may be used in other parts as a developer token */
tokenToUse = undefined
} else if (tokenToUse !== undefined && tokenToUse !== fileToken) {
/** Copy bag token to file token, migrating to new token system */
await this.updateMajorTomToken(tokenToUse)
}

this.local_token = tokenToUse ?? ''
},
async updateMajorTomToken(token: string): Promise<void> {
async updateMajorTomBagToken(token: string): Promise<void> {
await this.cleanMajorTomBagToken()

const tomData = await bag.getData('major_tom')
await bag.setData('major_tom', { ...tomData, token })
},
async updateMajorTomFileToken(token: string): Promise<void> {
try {
await this.cleanMajorTomFileToken()
} catch {
/** When updating the token, the file may not exist so we can ignore the error */
}

await filebrowser.createFile(MAJOR_TOM_CLOUD_TOKEN_FILE.path, true)
await filebrowser.writeToFile(MAJOR_TOM_CLOUD_TOKEN_FILE.path, token)
},
async updateMajorTomToken(token: string): Promise<void> {
await this.updateMajorTomBagToken(token)
await this.updateMajorTomFileToken(token)
},
async fetchExtensions(): Promise<void> {
if (this.operation_in_progress) {
return
Expand Down
6 changes: 3 additions & 3 deletions core/frontend/src/libs/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Filebrowser {
}

async createFile(folder_path: string, override: Boolean = false): Promise<void> {
back_axios({
await back_axios({
method: 'post',
url: `${filebrowser_url}/resources${folder_path}?override=${override}`,
timeout: 10000,
Expand All @@ -88,7 +88,7 @@ class Filebrowser {
}

async writeToFile(file: string, content: string): Promise<void> {
back_axios({
await back_axios({
method: 'put',
url: `/file-browser/api/resources${file}`,
timeout: 10000,
Expand All @@ -108,7 +108,7 @@ class Filebrowser {
* @param file - FilebrowserFile object to be deleted
* */
async deleteFile(file: FilebrowserFile): Promise<void> {
back_axios({
await back_axios({
method: 'delete',
url: `/file-browser/api/resources${file.path}`,
timeout: 10000,
Expand Down
Loading