Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mycard Mobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mycard Mobile
Commits
d4f06b95
Commit
d4f06b95
authored
Jul 26, 2017
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
02d676bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
81 deletions
+38
-81
package.json
package.json
+3
-3
src/app/o.ts
src/app/o.ts
+0
-46
src/app/storage.service.ts
src/app/storage.service.ts
+34
-31
src/index.html
src/index.html
+1
-1
No files found.
package.json
View file @
d4f06b95
{
"name"
:
"mycard-mobile"
,
"version"
:
"1.0.1
2
"
,
"version"
:
"1.0.1
4
"
,
"license"
:
"UNLISENCED"
,
"scripts"
:
{
"ng"
:
"ng"
,
"start"
:
"ng serve --base-href /mobile/ --deploy-url /mobile --locale zh-CN --output-path mobile --open"
,
"start:wild"
:
"npm run start -- --host 0.0.0.0 --public-host 192.168.1.131:4200"
,
"build"
:
"ng build --base-href /mobile/ --locale zh-CN --aot --build-optimizer --extract-css --
sourcemaps --
prod"
,
"build"
:
"ng build --base-href /mobile/ --locale zh-CN --aot --build-optimizer --extract-css --prod"
,
"postinstall"
:
"./fuck.sh"
,
"build:dev"
:
"ng build --base-href /mobile2/ --locale zh-CN --aot --build-optimizer --extract-css
--sourcemaps
"
,
"build:dev"
:
"ng build --base-href /mobile2/ --locale zh-CN --aot --build-optimizer --extract-css"
,
"lint"
:
"ng lint"
,
"publish"
:
"npm run build && ./ossutil cp -rf dist oss://mycard/mobile"
,
"publish:dev"
:
"npm run build:dev && ./ossutil cp -rf dist oss://mycard/mobile2"
...
...
src/app/o.ts
deleted
100644 → 0
View file @
02d676bf
// import { Observable } from 'rxjs/Observable';
//
// declare module 'rxjs/Observable' {
// interface Observable<T> {
// [Symbol.asyncIterator](): AsyncIterator<T>;
// }
// }
//
// class Deferred<T> extends Promise<T> {
// resolve;
// reject;
//
// constructor() {
// let a, b;
// super((resolve, reject) => {
// a = resolve;
// b = reject;
// });
// this.resolve = a;
// this.reject = b;
// }
// }
//
// Observable.prototype[Symbol.asyncIterator] = async function*() {
//
// let deferred = new Deferred();
// const completed = Symbol('completed');
//
// this.subscribe({
// next(value){
// deferred.resolve(value);
// },
// error(error){
// deferred.reject(error);
// },
// complete() {
// deferred.resolve(completed);
// },
// });
//
// let value;
// while ((value = await deferred) != completed) {
// deferred = new Deferred();
// yield value;
// }
// };
src/app/storage.service.ts
View file @
d4f06b95
...
...
@@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
import
*
as
path
from
'
path
'
;
import
*
as
webdav
from
'
webdav
'
;
import
{
LoginService
}
from
'
./login.service
'
;
import
'
./o
'
;
interface
DirectoryStats
{
'
filename
'
:
string
,
...
...
@@ -39,9 +38,7 @@ export class StorageService {
return
;
}
console
.
log
(
'
sync
'
,
'
start
'
);
this
.
working
=
true
;
// console.log('sync', 'start');
const
root
=
path
.
join
(
'
/
'
,
app_id
);
...
...
@@ -64,33 +61,32 @@ export class StorageService {
remote_files
.
set
(
local_path
,
true
);
const
local_time
=
window
.
ygopro
.
getFileLastModified
(
local_path
);
// console.log('本地时间', local_path, local_time);
if
(
local_time
)
{
// 远端有,本地有
if
(
local_time
>
remote_time
)
{
// 远端有,本地有,远端>本地,下载
await
this
.
download
(
local_path
,
remote_path
,
index_path
,
remote_time
);
await
this
.
download
(
local_path
,
remote_path
,
index_path
,
remote_time
);
}
else
if
(
local_time
<
remote_time
)
{
// 远端有,本地有,远端<本地,上传
await
this
.
upload
(
local_path
,
remote_path
,
index_path
);
await
this
.
upload
(
local_path
,
remote_path
,
index_path
);
}
}
else
{
// 远端有,本地无
if
(
localStorage
.
getItem
(
index_path
))
{
// 远端有,本地无,记录有,删除远端
await
this
.
client
.
deleteFile
(
remote_path
);
await
this
.
remove_remote
(
local_path
,
remote_path
,
index_path
);
}
else
{
// 远端有,本地无,记录无,下载
await
this
.
download
(
local_path
,
remote_path
,
index_path
,
remote_time
);
await
this
.
download
(
local_path
,
remote_path
,
index_path
,
remote_time
);
}
}
}
// console.log('远端文件扫描完毕', this.local_files());
for
(
const
local_path
of
this
.
local_files
())
{
const
remote_path
=
path
.
join
(
root
,
local_path
);
const
index_path
=
'
_FILE_
'
+
remote_path
;
...
...
@@ -99,35 +95,51 @@ export class StorageService {
// 远端无,本地有
if
(
localStorage
.
getItem
(
index_path
))
{
// 远端无,本地有,记录有,删除本地
window
.
ygopro
.
unlink
(
local
_path
);
await
this
.
remove_local
(
local_path
,
remote_path
,
index
_path
);
}
else
{
// 远端无,本地有,记录无,上传
await
this
.
upload
(
local_path
,
remote_path
,
index_path
);
await
this
.
upload
(
local_path
,
remote_path
,
index_path
);
}
}
}
console
.
log
(
'
sync
'
,
'
done
'
);
//
console.log('sync', 'done');
this
.
working
=
false
;
}
async
download
(
local_path
:
string
,
remote_path
:
string
,
index_path
:
string
,
time
:
number
)
{
console
.
log
(
'
download
'
,
local_path
,
remote_path
,
index_path
,
time
);
this
.
working
=
true
;
// console.log('download', local_path, remote_path, index_path, time);
const
data
:
Uint8Array
=
await
this
.
client
.
getFileContents
(
remote_path
);
window
.
ygopro
.
writeFile
(
local_path
,
Buffer
.
from
(
data
.
buffer
).
toString
(
'
base64
'
));
window
.
ygopro
.
setFileLastModified
(
local_path
,
time
);
localStorage
.
setItem
(
local_path
,
time
.
toString
());
// console.log(local_path, time);
localStorage
.
setItem
(
index_path
,
time
.
toString
());
}
async
upload
(
local_path
:
string
,
remote_path
:
string
,
index_path
:
string
)
{
console
.
log
(
'
upload
'
,
local_path
,
remote_path
,
index_path
);
this
.
working
=
true
;
// console.log('upload', local_path, remote_path, index_path);
const
data
=
Buffer
.
from
(
window
.
ygopro
.
readFile
(
local_path
),
'
base64
'
);
await
this
.
client
.
putFileContents
(
remote_path
,
data
);
const
item
:
FileStats
=
await
this
.
client
.
stat
(
remote_path
);
const
time
=
Date
.
parse
(
item
.
lastmod
);
window
.
ygopro
.
setFileLastModified
(
local_path
,
time
);
localStorage
.
setItem
(
local_path
,
time
.
toString
());
// console.log(local_path, time);
localStorage
.
setItem
(
index_path
,
time
.
toString
());
}
// 其实没必要 async,只是看着整齐一点
async
remove_local
(
local_path
:
string
,
remote_path
:
string
,
index_path
:
string
)
{
this
.
working
=
true
;
window
.
ygopro
.
unlink
(
local_path
);
localStorage
.
removeItem
(
index_path
);
}
async
remove_remote
(
local_path
:
string
,
remote_path
:
string
,
index_path
:
string
)
{
this
.
working
=
true
;
await
this
.
client
.
deleteFile
(
remote_path
);
localStorage
.
removeItem
(
index_path
);
}
local_files
()
{
...
...
@@ -144,8 +156,9 @@ export class StorageService {
.
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
);
// console.log('取远端目录', dir, items);
for
(
let
item
of
items
)
{
if
(
item
.
type
===
'
directory
'
)
{
yield
*
this
.
walk
(
item
.
filename
);
...
...
@@ -154,14 +167,4 @@ export class StorageService {
}
}
}
}
// const local = window.ygopro.getFileStats(item.filename);
// const remote_mtime = Date.parse(item.lastmod);
// if (local.mtime >= remote_mtime) {
// // 本地的较新,上传0
// await client.putFileContents();
//
// }
src/index.html
View file @
d4f06b95
...
...
@@ -11,7 +11,7 @@
<app-root>
<div
id=
"loading"
>
<img
src=
"assets/CubbitLogo.png"
>
<p>
LOADING
2
<span>
.
</span>
<span>
.
</span>
<span>
.
</span></p>
<p>
LOADING
<span>
.
</span>
<span>
.
</span>
<span>
.
</span></p>
</div>
</app-root>
</body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment