33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import type { IStorage } from '../types.d. ts'
6+ import type { IStorage } from '../types.ts'
77
88import axios from '@nextcloud/axios'
99import { loadState } from '@nextcloud/initial-state'
1010import { addPasswordConfirmationInterceptors , PwdConfirmationMode } from '@nextcloud/password-confirmation'
1111import { generateUrl } from '@nextcloud/router'
1212import { defineStore } from 'pinia'
1313import { ref , toRaw } from 'vue'
14+ import { MountOptionsCheckFilesystem } from '../types.ts'
1415
1516const { isAdmin } = loadState < { isAdmin : boolean } > ( 'files_external' , 'settings' )
1617
@@ -30,7 +31,7 @@ export const useStorages = defineStore('files_external--storages', () => {
3031 toRaw ( storage ) ,
3132 { confirmPassword : PwdConfirmationMode . Strict } ,
3233 )
33- globalStorages . value . push ( data )
34+ globalStorages . value . push ( parseStorage ( data ) )
3435 }
3536
3637 /**
@@ -45,7 +46,7 @@ export const useStorages = defineStore('files_external--storages', () => {
4546 toRaw ( storage ) ,
4647 { confirmPassword : PwdConfirmationMode . Strict } ,
4748 )
48- userStorages . value . push ( data )
49+ userStorages . value . push ( parseStorage ( data ) )
4950 }
5051
5152 /**
@@ -77,7 +78,7 @@ export const useStorages = defineStore('files_external--storages', () => {
7778 { confirmPassword : PwdConfirmationMode . Strict } ,
7879 )
7980
80- overrideStorage ( data )
81+ overrideStorage ( parseStorage ( data ) )
8182 }
8283
8384 /**
@@ -87,7 +88,7 @@ export const useStorages = defineStore('files_external--storages', () => {
8788 */
8889 async function reloadStorage ( storage : IStorage ) {
8990 const { data } = await axios . get ( getUrl ( storage ) )
90- overrideStorage ( data )
91+ overrideStorage ( parseStorage ( data ) )
9192 }
9293
9394 // initialize the store
@@ -111,6 +112,7 @@ export const useStorages = defineStore('files_external--storages', () => {
111112 const url = `apps/files_external/${ type } `
112113 const { data } = await axios . get < Record < number , IStorage > > ( generateUrl ( url ) )
113114 return Object . values ( data )
115+ . map ( parseStorage )
114116 }
115117
116118 /**
@@ -150,3 +152,45 @@ export const useStorages = defineStore('files_external--storages', () => {
150152 }
151153 }
152154} )
155+
156+ /**
157+ * @param storage - The storage from API
158+ */
159+ function parseStorage ( storage : IStorage ) {
160+ return {
161+ ...storage ,
162+ mountOptions : parseMountOptions ( storage . mountOptions ) ,
163+ }
164+ }
165+
166+ /**
167+ * Parse the mount options and convert string boolean values to
168+ * actual booleans and numeric strings to numbers
169+ *
170+ * @param options - The mount options to parse
171+ */
172+ export function parseMountOptions ( options : IStorage [ 'mountOptions' ] ) {
173+ const mountOptions = { ...options }
174+ mountOptions . encrypt = convertBooleanOptions ( mountOptions . encrypt , true )
175+ mountOptions . previews = convertBooleanOptions ( mountOptions . previews , true )
176+ mountOptions . enable_sharing = convertBooleanOptions ( mountOptions . enable_sharing , false )
177+ mountOptions . filesystem_check_changes = typeof mountOptions . filesystem_check_changes === 'string'
178+ ? Number . parseInt ( mountOptions . filesystem_check_changes )
179+ : ( mountOptions . filesystem_check_changes ?? MountOptionsCheckFilesystem . OncePerRequest )
180+ mountOptions . encoding_compatibility = convertBooleanOptions ( mountOptions . encoding_compatibility , false )
181+ mountOptions . readonly = convertBooleanOptions ( mountOptions . readonly , false )
182+ return mountOptions
183+ }
184+
185+ /**
186+ * Convert backend encoding of boolean options
187+ *
188+ * @param option - The option value from API
189+ * @param fallback - The fallback (default) value
190+ */
191+ function convertBooleanOptions ( option : unknown , fallback = false ) {
192+ if ( option === undefined ) {
193+ return fallback
194+ }
195+ return option === true || option === 'true' || option === '1'
196+ }
0 commit comments