Commit 1c12b52c authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent 6d3ff1fe
{ {
"name": "mycard-mobile", "name": "mycard-mobile",
"version": "1.0.23", "version": "1.0.24",
"license": "UNLISENCED", "license": "UNLISENCED",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
......
...@@ -4,21 +4,20 @@ import * as webdav from 'webdav'; ...@@ -4,21 +4,20 @@ import * as webdav from 'webdav';
import { LoginService } from './login.service'; import { LoginService } from './login.service';
interface DirectoryStats { interface DirectoryStats {
'filename': string; filename: string;
'basename': string; basename: string;
'lastmod': string; lastmod: string;
'size': 0; size: 0;
'type': 'directory'; type: 'directory';
} }
interface FileStats { interface FileStats {
'filename': string; filename: string;
'basename': string; basename: string;
'lastmod': string; lastmod: string;
'size': number; size: number;
'type': 'file'; type: 'file';
'mime': string; mime: string;
} }
type Stats = DirectoryStats | FileStats; type Stats = DirectoryStats | FileStats;
...@@ -27,11 +26,9 @@ type Stats = DirectoryStats | FileStats; ...@@ -27,11 +26,9 @@ type Stats = DirectoryStats | FileStats;
export class StorageService { export class StorageService {
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: boolean; working: boolean;
constructor(private login: LoginService) { constructor(private login: LoginService) {}
}
async sync(app_id: string) { async sync(app_id: string) {
if (!window.ygopro || !window.ygopro.getFileLastModified) { if (!window.ygopro || !window.ygopro.getFileLastModified) {
...@@ -119,8 +116,8 @@ export class StorageService { ...@@ -119,8 +116,8 @@ export class StorageService {
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 = true; this.working = true;
// console.log('download', local_path, remote_path, index_path, time); // console.log('download', local_path, remote_path, index_path, time);
const data: Uint8Array = await this.client.getFileContents(remote_path); const data: ArrayBuffer = await this.client.getFileContents(remote_path);
window.ygopro.writeFile(local_path, Buffer.from(<ArrayBuffer>data.buffer).toString('base64')); window.ygopro.writeFile(local_path, Buffer.from(data).toString('base64'));
window.ygopro.setFileLastModified(local_path, time); window.ygopro.setFileLastModified(local_path, time);
// console.log(local_path, time); // console.log(local_path, time);
localStorage.setItem(index_path, time.toString()); localStorage.setItem(index_path, time.toString());
...@@ -165,7 +162,7 @@ export class StorageService { ...@@ -165,7 +162,7 @@ export class StorageService {
.map(file => path.join(directory, file)); .map(file => path.join(directory, file));
} }
async * walk(dir: string): AsyncIterable<Stats> { async *walk(dir: string): AsyncIterable<Stats> {
const items: Stats[] = await this.client.getDirectoryContents(dir); const items: Stats[] = await this.client.getDirectoryContents(dir);
// console.log('取远端目录', dir, items); // console.log('取远端目录', dir, items);
for (const item of items) { for (const item of items) {
......
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