Commit 907f385e authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent a7cede6c
{ {
"name": "mycard-mobile", "name": "mycard-mobile",
"version": "1.0.32", "version": "1.0.33",
"license": "UNLISENCED", "license": "UNLISENCED",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
......
import { EventEmitter, Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import * as path from 'path'; import * as path from 'path';
import * as webdav from 'webdav'; import * as webdav from 'webdav';
import { LoginService } from './login.service'; import { LoginService } from './login.service';
import { BehaviorSubject } from 'rxjs';
interface DirectoryStats { interface DirectoryStats {
filename: string; filename: string;
...@@ -27,7 +28,7 @@ export class StorageService { ...@@ -27,7 +28,7 @@ export class StorageService {
app_id = 'ygopro'; app_id = 'ygopro';
client = webdav('https://api.mycard.moe/storage/', this.login.user.username, this.login.user.external_id.toString()); client = webdav('https://api.mycard.moe/storage/', this.login.user.username, this.login.user.external_id.toString());
working = new EventEmitter(); working = new BehaviorSubject(false);
constructor(private login: LoginService) {} constructor(private login: LoginService) {}
...@@ -111,11 +112,11 @@ export class StorageService { ...@@ -111,11 +112,11 @@ export class StorageService {
// fixme: 如果远端和本地同时没有,但是 localStorage 里有,要删除 // fixme: 如果远端和本地同时没有,但是 localStorage 里有,要删除
// console.log('sync', 'done'); // console.log('sync', 'done');
this.working.emit(false); this.working.next(false);
} }
async download(local_path: string, remote_path: string, index_path: string, time: number) { async download(local_path: string, remote_path: string, index_path: string, time: number) {
this.working.emit(true); this.working.next(true);
// console.log('download', local_path, remote_path, index_path, time); // console.log('download', local_path, remote_path, index_path, time);
const data: ArrayBuffer = await this.client.getFileContents(remote_path); const data: ArrayBuffer = await this.client.getFileContents(remote_path);
window.ygopro.writeFile(local_path, Buffer.from(data).toString('base64')); window.ygopro.writeFile(local_path, Buffer.from(data).toString('base64'));
...@@ -125,7 +126,7 @@ export class StorageService { ...@@ -125,7 +126,7 @@ export class StorageService {
} }
async upload(local_path: string, remote_path: string, index_path: string) { async upload(local_path: string, remote_path: string, index_path: string) {
this.working.emit(true); this.working.next(true);
// console.log('upload', local_path, remote_path, index_path); // console.log('upload', local_path, remote_path, index_path);
const data = this.read_local(local_path); const data = this.read_local(local_path);
await this.client.putFileContents(remote_path, data); await this.client.putFileContents(remote_path, data);
...@@ -141,13 +142,13 @@ export class StorageService { ...@@ -141,13 +142,13 @@ export class StorageService {
} }
remove_local(local_path: string, remote_path: string, index_path: string) { remove_local(local_path: string, remote_path: string, index_path: string) {
this.working.emit(true); this.working.next(true);
window.ygopro.unlink(local_path); window.ygopro.unlink(local_path);
localStorage.removeItem(index_path); localStorage.removeItem(index_path);
} }
async remove_remote(local_path: string, remote_path: string, index_path: string) { async remove_remote(local_path: string, remote_path: string, index_path: string) {
this.working.emit(true); this.working.next(true);
await this.client.deleteFile(remote_path); await this.client.deleteFile(remote_path);
localStorage.removeItem(index_path); localStorage.removeItem(index_path);
} }
...@@ -157,7 +158,7 @@ export class StorageService { ...@@ -157,7 +158,7 @@ export class StorageService {
const remote_path = path.join(root, local_path); const remote_path = path.join(root, local_path);
const index_path = '_FILE_' + remote_path; const index_path = '_FILE_' + remote_path;
this.working.emit(true); this.working.next(true);
window.ygopro.unlink(local_path); window.ygopro.unlink(local_path);
await this.client.deleteFile(remote_path); await this.client.deleteFile(remote_path);
localStorage.removeItem(index_path); localStorage.removeItem(index_path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment