|
|
@ -6,22 +6,36 @@ type Auth = {
|
|
|
|
pass: string;
|
|
|
|
pass: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type Session = {
|
|
|
|
|
|
|
|
client: WebDAVClient;
|
|
|
|
|
|
|
|
isActive: boolean;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const useWebdavStorage = defineStore('auth', {
|
|
|
|
export const useWebdavStorage = defineStore('auth', {
|
|
|
|
state: () => ({
|
|
|
|
state: () => ({
|
|
|
|
clientList: [] as Array<WebDAVClient>,
|
|
|
|
sessions: [] as Array<Session>,
|
|
|
|
currentClient: null as null | WebDAVClient,
|
|
|
|
currentSession: null as null | Session,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
actions: {
|
|
|
|
actions: {
|
|
|
|
login({ user, pass }: Auth) {
|
|
|
|
login({ user, pass }: Auth): Promise<Session> {
|
|
|
|
console.log(user, pass);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const client = createClient(process.env.VUE_APP_ROOT_WEBDAV as string, {
|
|
|
|
try {
|
|
|
|
|
|
|
|
const client = createClient(
|
|
|
|
|
|
|
|
process.env.VUE_APP_ROOT_WEBDAV as string,
|
|
|
|
|
|
|
|
{
|
|
|
|
authType: AuthType.Digest,
|
|
|
|
authType: AuthType.Digest,
|
|
|
|
username: user as string,
|
|
|
|
username: user as string,
|
|
|
|
password: pass as string,
|
|
|
|
password: pass as string,
|
|
|
|
}) as WebDAVClient;
|
|
|
|
}
|
|
|
|
this.clientList.push(client);
|
|
|
|
) as WebDAVClient;
|
|
|
|
this.currentClient = client;
|
|
|
|
const session = { client, isActive: true } as Session;
|
|
|
|
return client;
|
|
|
|
this.sessions.push(session);
|
|
|
|
|
|
|
|
this.currentSession = session;
|
|
|
|
|
|
|
|
resolve(session);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
reject(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|