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
xiaoye
mycard
Commits
0474e72a
Commit
0474e72a
authored
Sep 11, 2021
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
d097bd50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
104 deletions
+79
-104
src/app/download.service.ts
src/app/download.service.ts
+70
-101
src/app/ygopro/ygopro.component.ts
src/app/ygopro/ygopro.component.ts
+9
-3
No files found.
src/app/download.service.ts
View file @
0474e72a
/**
* Created by weijian on 2016/10/26.
*/
import
{
EventEmitter
,
Injectable
,
NgZone
}
from
'
@angular/core
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
// import {error} from 'util';
// import Timer = NodeJS.Timer;
// const Logger = {
// 'error': (message: string) => {
// console.error('DownloadService: ', message);
// }
// };
import
{
EventEmitter
,
Injectable
,
NgZone
}
from
'
@angular/core
'
;
import
Aria2
from
'
aria2
'
;
const
MAX_LIST_NUM
=
1000
;
...
...
@@ -18,33 +10,48 @@ const ARIA2_INTERVAL = 500;
export
class
DownloadStatus
{
completedLength
:
number
;
downloadSpeed
:
number
;
gid
:
string
;
status
:
string
;
totalLength
:
number
;
totalLengthText
:
string
;
errorCode
:
string
;
errorMessage
:
string
;
constructor
(
item
?:
any
)
{
if
(
item
)
{
this
.
completedLength
=
parseInt
(
item
.
completedLength
)
||
0
;
this
.
downloadSpeed
=
parseInt
(
item
.
downloadSpeed
)
||
0
;
this
.
totalLength
=
parseInt
(
item
.
totalLength
)
||
0
;
this
.
gid
=
item
.
gid
;
this
.
status
=
item
.
status
;
this
.
errorCode
=
item
.
errorCode
;
this
.
errorMessage
=
item
.
errorMessage
;
}
else
{
this
.
completedLength
=
0
;
this
.
downloadSpeed
=
0
;
this
.
totalLength
=
0
;
}
}
get
downloadSpeedText
():
string
{
get
downloadSpeedText
():
string
{
if
(
!
isNaN
(
this
.
downloadSpeed
)
&&
this
.
downloadSpeed
!==
0
)
{
const
speedUnit
=
[
'
Byte/s
'
,
'
KB/s
'
,
'
MB/s
'
,
'
GB/s
'
,
'
TB/s
'
];
let
currentUnit
=
Math
.
floor
(
Math
.
log
(
this
.
downloadSpeed
)
/
Math
.
log
(
1024
));
return
(
this
.
downloadSpeed
/
1024
**
currentUnit
).
toFixed
(
1
)
+
'
'
+
speedUnit
[
currentUnit
];
}
return
''
;
};
gid
:
string
;
status
:
string
;
totalLength
:
number
;
totalLengthText
:
string
;
errorCode
:
string
;
errorMessage
:
string
;
}
combine
(...
others
:
DownloadStatus
[]):
DownloadStatus
{
combine
(...
others
:
DownloadStatus
[]):
DownloadStatus
{
const
priority
=
{
undefined
:
-
1
,
''
:
-
1
,
'
active
'
:
0
,
'
complete
'
:
0
,
'
paused
'
:
1
,
'
waiting
'
:
1
,
'
removed
'
:
2
,
'
error
'
:
3
active
:
0
,
complete
:
0
,
paused
:
1
,
waiting
:
1
,
removed
:
2
,
error
:
3
,
};
let
status
=
Object
.
assign
(
new
DownloadStatus
(),
this
);
for
(
let
o
of
others
)
{
...
...
@@ -58,57 +65,49 @@ export class DownloadStatus {
status
.
totalLength
+=
o
.
totalLength
;
status
.
completedLength
+=
o
.
completedLength
;
}
}
return
status
;
}
// 0相等. 1不想等
compareTo
(
other
:
DownloadStatus
):
number
{
if
(
this
.
status
!==
other
.
status
||
compareTo
(
other
:
DownloadStatus
):
number
{
if
(
this
.
status
!==
other
.
status
||
this
.
downloadSpeed
!==
other
.
downloadSpeed
||
this
.
completedLength
!==
other
.
completedLength
||
this
.
totalLength
!==
other
.
totalLength
)
{
this
.
totalLength
!==
other
.
totalLength
)
{
return
1
;
}
else
{
return
0
;
}
}
constructor
(
item
?:
any
)
{
if
(
item
)
{
this
.
completedLength
=
parseInt
(
item
.
completedLength
)
||
0
;
this
.
downloadSpeed
=
parseInt
(
item
.
downloadSpeed
)
||
0
;
this
.
totalLength
=
parseInt
(
item
.
totalLength
)
||
0
;
this
.
gid
=
item
.
gid
;
this
.
status
=
item
.
status
;
this
.
errorCode
=
item
.
errorCode
;
this
.
errorMessage
=
item
.
errorMessage
;
}
else
{
this
.
completedLength
=
0
;
this
.
downloadSpeed
=
0
;
this
.
totalLength
=
0
;
}
}
}
@
Injectable
({
providedIn
:
'
root
'
providedIn
:
'
root
'
,
})
export
class
DownloadService
{
// 强制指定IPv4,接到过一个反馈无法监听v6的。默认的host值是localhost,会连v6。
aria2
=
new
Aria2
({
host
:
'
127.0.0.1
'
});
aria2
=
new
Aria2
({
host
:
'
127.0.0.1
'
});
open
=
this
.
aria2
.
open
();
updateEmitter
=
new
EventEmitter
<
void
>
();
downloadList
:
Map
<
string
,
DownloadStatus
>
=
new
Map
();
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
);
constructor
(
private
ngZone
:
NgZone
)
{
ngZone
.
runOutsideAngular
(
async
()
=>
{
await
this
.
open
;
setInterval
(
async
()
=>
{
await
this
.
refreshDownloadList
();
},
ARIA2_INTERVAL
);
});
}
async
refreshDownloadList
()
{
let
activeList
=
await
this
.
aria2
.
call
(
'
tellActive
'
);
let
waitList
=
await
this
.
aria2
.
call
(
'
tellWaiting
'
,
0
,
MAX_LIST_NUM
);
let
stoppedList
=
await
this
.
aria2
.
call
(
'
tellStopped
'
,
0
,
MAX_LIST_NUM
);
this
.
downloadList
.
clear
();
for
(
let
item
of
activeList
)
{
this
.
downloadList
.
set
(
item
.
gid
,
new
DownloadStatus
(
item
));
...
...
@@ -122,47 +121,26 @@ export class DownloadService {
this
.
updateEmitter
.
emit
();
}
constructor
(
private
ngZone
:
NgZone
)
{
ngZone
.
runOutsideAngular
(
async
()
=>
{
await
this
.
open
;
setInterval
(
async
()
=>
{
await
this
.
refreshDownloadList
();
},
ARIA2_INTERVAL
);
});
}
private
createId
():
string
{
function
s4
()
{
return
Math
.
floor
((
1
+
Math
.
random
())
*
0x10000
)
.
toString
(
16
)
.
substring
(
1
);
}
return
s4
()
+
s4
()
+
'
-
'
+
s4
()
+
'
-
'
+
s4
()
+
'
-
'
+
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
)
{
let
allStatus
:
DownloadStatus
;
let
subscription
=
this
.
updateEmitter
.
subscribe
(()
=>
{
try
{
let
status
:
DownloadStatus
=
new
DownloadStatus
();
// 合并每个状态信息
status
=
gids
!
.
map
((
value
,
index
,
array
)
=>
{
status
=
gids
!
.
map
((
value
,
index
,
array
)
=>
{
let
s
=
this
.
downloadList
.
get
(
value
);
if
(
!
s
)
{
throw
'
Gid not exists
'
;
}
return
s
;
})
.
reduce
((
previousValue
,
currentValue
,
currentIndex
,
array
)
=>
{
return
previousValue
.
combine
(
currentValue
);
},
status
);
.
reduce
((
previousValue
,
currentValue
,
currentIndex
,
array
)
=>
{
return
previousValue
.
combine
(
currentValue
);
},
status
);
if
(
!
allStatus
)
{
allStatus
=
status
;
}
else
{
...
...
@@ -178,7 +156,6 @@ export class DownloadService {
}
else
{
callback
(
allStatus
);
}
}
catch
(
e
)
{
reject
(
e
);
subscription
.
unsubscribe
();
...
...
@@ -190,19 +167,19 @@ export class DownloadService {
});
}
async
getFiles
(
id
:
string
):
Promise
<
string
[]
>
{
async
getFiles
(
id
:
string
):
Promise
<
string
[]
>
{
let
gids
=
this
.
taskMap
.
get
(
id
)
!
;
let
files
:
string
[]
=
[];
for
(
let
gid
of
gids
)
{
let
file
=
await
this
.
aria2
.
getFiles
(
gid
);
let
file
=
await
this
.
aria2
.
call
(
'
getFiles
'
,
gid
);
files
.
push
(
file
[
0
].
path
);
}
return
files
;
}
async
addMetalink
(
metalink
:
string
,
library
:
string
):
Promise
<
string
>
{
let
encodedMeta4
=
Buffer
.
from
(
(
metalink
)
).
toString
(
'
base64
'
);
let
gidList
=
await
this
.
aria2
.
addMetalink
(
encodedMeta4
,
{
dir
:
library
});
async
addMetalink
(
metalink
:
string
,
library
:
string
):
Promise
<
string
>
{
let
encodedMeta4
=
Buffer
.
from
(
metalink
).
toString
(
'
base64
'
);
let
gidList
=
await
this
.
aria2
.
call
(
'
addMetalink
'
,
encodedMeta4
,
{
dir
:
library
});
let
taskId
=
this
.
createId
();
this
.
taskMap
.
set
(
taskId
,
gidList
);
// 每次添加任务,刷新一下本地任务列表
...
...
@@ -210,21 +187,13 @@ export class DownloadService {
return
taskId
;
}
async
addUri
(
url
:
string
,
destination
:
string
):
Promise
<
string
>
{
await
this
.
open
;
let
taskId
=
this
.
createId
();
let
gid
=
await
this
.
aria2
.
addUri
([
url
],
{
dir
:
destination
});
this
.
taskMap
.
set
(
taskId
,
[
gid
]);
return
taskId
;
}
async
pause
(
id
:
string
):
Promise
<
void
>
{
await
this
.
open
;
try
{
await
this
.
aria2
.
pause
(
id
);
}
catch
(
e
)
{
private
createId
():
string
{
function
s4
()
{
return
Math
.
floor
((
1
+
Math
.
random
())
*
0x10000
)
.
toString
(
16
)
.
substring
(
1
);
}
}
return
s4
()
+
s4
()
+
'
-
'
+
s4
()
+
'
-
'
+
s4
()
+
'
-
'
+
s4
()
+
'
-
'
+
s4
()
+
s4
()
+
s4
();
}
}
src/app/ygopro/ygopro.component.ts
View file @
0474e72a
...
...
@@ -26,9 +26,9 @@ import { SettingsService } from '../settings.service';
import
_
from
'
lodash-es
'
;
import
fg
from
'
fast-glob
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
import
{
lastValueFrom
,
Subscription
}
from
'
rxjs
'
;
import
WillNavigateEvent
=
Electron
.
WillNavigateEvent
;
import
Timer
=
NodeJS
.
Timer
;
import
{
lastValueFrom
,
Subscription
}
from
'
rxjs
'
;
interface
SystemConf
{
use_d3d
:
string
;
...
...
@@ -300,6 +300,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
if
(
_
.
isArray
(
objValue
))
{
return
objValue
.
concat
(
srcValue
);
}
return
;
});
}
}
...
...
@@ -602,7 +603,12 @@ export class YGOProComponent implements OnInit, OnDestroy {
system_conf.nickname = this.loginService.user.username;
await this.save_system_conf(system_conf);*/
// return this.start_game(['-h', server.address, '-p', server.port.toString(), '-w', name, '-n', this.loginService.user.username, '-d', this.current_deck, '-j']);
return
this
.
start_game
(
'
main
'
,
{
server
,
password
:
name
,
username
:
this
.
loginService
.
user
.
username
,
deck
:
this
.
current_deck
});
return
this
.
start_game
(
'
main
'
,
{
server
,
password
:
name
,
username
:
this
.
loginService
.
user
.
username
,
deck
:
this
.
current_deck
,
});
}
async
edit_deck
(
deck
:
string
)
{
...
...
@@ -709,7 +715,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
data
.
exp_rank_ex
=
exp_rank_ex
;
data
.
arena_rank_ex
=
arena_rank_ex
;
// if (start_time !== data.start_time) {
this
.
appsService
.
showResult
(
'
projects/ygopro-result/end_YGOPro_single.html
'
,
data
,
202
,
222
);
this
.
appsService
.
showResult
(
'
projects/ygopro-result/end_YGOPro_single.html
'
,
data
,
202
,
222
);
// }
});
}
catch
(
error
)
{
...
...
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