Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
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
syntax_j
mycard
Commits
bcbcdcf7
Commit
bcbcdcf7
authored
Dec 15, 2016
by
wudizhanche1000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复若干问题
1. 导入失败时正确重置 2. 本地下载列表可能与aria2不一致的问题
parent
781f6231
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
88 deletions
+41
-88
app/app-detail.component.ts
app/app-detail.component.ts
+12
-7
app/apps.service.ts
app/apps.service.ts
+6
-1
app/download.service.ts
app/download.service.ts
+22
-79
package.json
package.json
+1
-1
No files found.
app/app-detail.component.ts
View file @
bcbcdcf7
...
...
@@ -151,13 +151,18 @@ export class AppDetailComponent implements OnInit {
$
(
'
#import-modal
'
).
modal
(
'
hide
'
);
let
dir
=
path
.
dirname
(
this
.
import_path
);
// TODO: 执行依赖和references安装
await
this
.
appsService
.
importApp
(
targetApp
,
dir
,
option
);
for
(
let
[
id
,
install
]
of
Object
.
entries
(
referencesInstall
))
{
if
(
install
)
{
let
reference
=
targetApp
.
references
.
get
(
id
)
!
;
console
.
log
(
"
reference install
"
,
id
,
targetApp
,
targetApp
.
references
,
reference
);
await
this
.
appsService
.
install
(
reference
,
option
);
try
{
await
this
.
appsService
.
importApp
(
targetApp
,
dir
,
option
);
for
(
let
[
id
,
install
]
of
Object
.
entries
(
referencesInstall
))
{
if
(
install
)
{
let
reference
=
targetApp
.
references
.
get
(
id
)
!
;
console
.
log
(
"
reference install
"
,
id
,
targetApp
,
targetApp
.
references
,
reference
);
await
this
.
appsService
.
install
(
reference
,
option
);
}
}
}
catch
(
e
)
{
console
.
error
(
e
);
new
Notification
(
targetApp
.
name
,
{
body
:
"
导入失败
"
});
}
}
...
...
@@ -172,7 +177,7 @@ export class AppDetailComponent implements OnInit {
}
}
catch
(
e
)
{
new
Notification
(
app
.
name
,
{
body
:
"
校验失败
"
});
console
.
log
(
e
);
console
.
error
(
e
);
}
}
...
...
app/apps.service.ts
View file @
bcbcdcf7
...
...
@@ -539,7 +539,12 @@ export class AppsService {
Logger
.
info
(
"
Update Finished:
"
,
app
);
}
catch
(
e
)
{
Logger
.
error
(
"
Update Failed:
"
,
e
);
app
.
status
.
status
=
"
ready
"
;
// 如果导入失败,根据是否安装重置status
if
(
app
.
local
!
.
files
)
{
app
.
status
.
status
=
"
ready
"
;
}
else
{
app
.
reset
();
}
throw
e
;
}
}
...
...
app/download.service.ts
View file @
bcbcdcf7
...
...
@@ -13,7 +13,7 @@ const Logger = {
const
Aria2
=
require
(
'
aria2
'
);
const
MAX_LIST_NUM
=
1000
;
const
ARIA2_INTERVAL
=
10
00
;
const
ARIA2_INTERVAL
=
5
00
;
export
class
DownloadStatus
{
completedLength
:
number
;
...
...
@@ -103,24 +103,28 @@ export class DownloadService {
taskMap
:
Map
<
string
,
string
[]
>
=
new
Map
();
async
refreshDownloadList
()
{
let
activeList
=
await
this
.
aria2
.
tellActive
();
let
waitList
=
await
this
.
aria2
.
tellWaiting
(
0
,
MAX_LIST_NUM
);
let
stoppedList
=
await
this
.
aria2
.
tellStopped
(
0
,
MAX_LIST_NUM
);
this
.
downloadList
.
clear
();
for
(
let
item
of
activeList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
}
for
(
let
item
of
waitList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
}
for
(
let
item
of
stoppedList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
}
this
.
updateEmitter
.
emit
();
}
constructor
(
private
ngZone
:
NgZone
,
private
http
:
Http
)
{
ngZone
.
runOutsideAngular
(
async
()
=>
{
await
this
.
open
;
setInterval
(
async
()
=>
{
let
activeList
=
await
this
.
aria2
.
tellActive
();
let
waitList
=
await
this
.
aria2
.
tellWaiting
(
0
,
MAX_LIST_NUM
);
let
stoppedList
=
await
this
.
aria2
.
tellStopped
(
0
,
MAX_LIST_NUM
);
this
.
downloadList
.
clear
();
for
(
let
item
of
activeList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
}
for
(
let
item
of
waitList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
}
for
(
let
item
of
stoppedList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
}
this
.
updateEmitter
.
emit
();
await
this
.
refreshDownloadList
();
},
ARIA2_INTERVAL
);
})
}
...
...
@@ -136,7 +140,7 @@ export class DownloadService {
s4
()
+
'
-
'
+
s4
()
+
s4
()
+
s4
();
}
async
progress
(
id
:
string
,
callback
:
(
downloadStatus
:
DownloadStatus
)
=>
void
)
{
async
progress
(
id
:
string
,
callback
:
(
downloadStatus
:
DownloadStatus
)
=>
void
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
gids
=
this
.
taskMap
.
get
(
id
);
if
(
gids
)
{
...
...
@@ -184,69 +188,6 @@ export class DownloadService {
})
}
// downloadProgress(id: string): Observable<any> {
// let progress = this.progressList.get(id);
// if (progress) {
// return progress;
// } else {
// return Observable.create((observer: Observer<any>) => {
// let status = '';
// let completedLength = 0;
// let totalLength = 0;
// let downloadSpeed = 0;
//
// let gidList = this.taskMap.get(id) !;
// this.updateEmitter.subscribe((value: string) => {
// let statusList = new Array(gidList.length);
// let newCompletedLength = 0;
// let newTotalLength = 0;
// let newDownloadSpeed = 0;
// for (let [index,gid] of gidList.entries()) {
// let task = this.downloadList.get(gid)!;
// if (task) {
// statusList[index] = task.status;
// newCompletedLength += parseInt(task.completedLength);
// newTotalLength += parseInt(task.totalLength);
// newDownloadSpeed += parseInt(task.downloadSpeed);
// }
// }
// if (newCompletedLength !== completedLength || newTotalLength !== totalLength) {
// completedLength = newCompletedLength;
// totalLength = newTotalLength;
// downloadSpeed = newDownloadSpeed;
// observer.next({
// status: status,
// completedLength: completedLength,
// totalLength: totalLength,
// downloadSpeed: downloadSpeed
// });
// }
// status = statusList.reduce((value, current) => {
// if (value === "complete" && current === "complete") {
// return "complete";
// }
// if (current != "complete" && current != "active") {
// return "error";
// }
// });
// if (status === "complete") {
// observer.complete();
// } else if (status == "error") {
// observer.error("Download Error");
// }
// return () => {
//
// }
// }, () => {
//
// }, () => {
//
// })
// });
//
// }
// }
async
getFiles
(
id
:
string
):
Promise
<
string
[]
>
{
let
gids
=
this
.
taskMap
.
get
(
id
)
!
;
let
files
:
string
[]
=
[];
...
...
@@ -262,6 +203,8 @@ export class DownloadService {
let
gidList
=
await
this
.
aria2
.
addMetalink
(
encodedMeta4
,
{
dir
:
library
});
let
taskId
=
this
.
createId
();
this
.
taskMap
.
set
(
taskId
,
gidList
);
// 每次添加任务,刷新一下本地任务列表
await
this
.
refreshDownloadList
();
return
taskId
;
}
...
...
package.json
View file @
bcbcdcf7
{
"name"
:
"mycard"
,
"version"
:
"3.0.
6
"
,
"version"
:
"3.0.
7
"
,
"description"
:
"mycard"
,
"keywords"
:
[],
"author"
:
"zh99998 <zh99998@gmail.com>"
,
...
...
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