Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
onTime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
onTime InnoLab
onTime
Commits
68df2013
Commit
68df2013
authored
1 year ago
by
doodlezucc
Browse files
Options
Downloads
Patches
Plain Diff
use Set-Cookie response
parent
a4c68ccd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/fetching/cacheable.dart
+4
-0
4 additions, 0 deletions
lib/fetching/cacheable.dart
lib/untis/fetch.dart
+27
-15
27 additions, 15 deletions
lib/untis/fetch.dart
with
31 additions
and
15 deletions
lib/fetching/cacheable.dart
+
4
−
0
View file @
68df2013
...
@@ -21,6 +21,10 @@ abstract class Cacheable<T> {
...
@@ -21,6 +21,10 @@ abstract class Cacheable<T> {
return
_cached
!
;
return
_cached
!
;
}
}
void
invalidateCache
()
{
_cached
=
null
;
}
Future
<
Json
>
_request
()
{
Future
<
Json
>
_request
()
{
return
untis
.
requestOptions
(
request
);
return
untis
.
requestOptions
(
request
);
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/untis/fetch.dart
+
27
−
15
View file @
68df2013
...
@@ -11,8 +11,7 @@ import 'element_type.dart';
...
@@ -11,8 +11,7 @@ import 'element_type.dart';
import
'lecture.dart'
;
import
'lecture.dart'
;
typedef
RequestOptions
=
(
String
path
,
String
method
,
Json
params
);
typedef
RequestOptions
=
(
String
path
,
String
method
,
Json
params
);
typedef
SimpleCookieMap
=
Map
<
String
,
String
>;
typedef
JsonWithCookies
=
(
Json
json
,
List
<
Cookie
>
cookies
);
typedef
JsonWithCookies
=
(
Json
json
,
SimpleCookieMap
cookies
);
class
UntisFetch
{
class
UntisFetch
{
static
const
String
apiBase
=
'/WebUntis/api/public'
;
static
const
String
apiBase
=
'/WebUntis/api/public'
;
...
@@ -25,7 +24,7 @@ class UntisFetch {
...
@@ -25,7 +24,7 @@ class UntisFetch {
final
HttpClient
client
=
HttpClient
();
final
HttpClient
client
=
HttpClient
();
final
Uri
serverHost
=
Uri
.
https
(
'poly.webuntis.com'
);
final
Uri
serverHost
=
Uri
.
https
(
'poly.webuntis.com'
);
final
Simple
Cookie
Map
_sessionCookies
=
{}
;
final
List
<
Cookie
>
_sessionCookies
=
[]
;
late
PageConfig
<
Class
>
allClasses
=
PageConfig
(
late
PageConfig
<
Class
>
allClasses
=
PageConfig
(
this
,
this
,
...
@@ -60,10 +59,7 @@ class UntisFetch {
...
@@ -60,10 +59,7 @@ class UntisFetch {
final
request
=
await
client
.
openUrl
(
method
,
uri
);
final
request
=
await
client
.
openUrl
(
method
,
uri
);
request
.
cookies
.
add
(
Cookie
(
'schoolname'
,
idHsReutlingen
));
request
.
cookies
.
add
(
Cookie
(
'schoolname'
,
idHsReutlingen
));
request
.
cookies
.
addAll
(
request
.
cookies
.
addAll
(
_sessionCookies
);
_sessionCookies
.
entries
.
map
((
entry
)
=
>
Cookie
(
entry
.
key
,
entry
.
value
)),
);
final
response
=
await
request
.
close
();
final
response
=
await
request
.
close
();
return
response
;
return
response
;
}
}
...
@@ -71,21 +67,42 @@ class UntisFetch {
...
@@ -71,21 +67,42 @@ class UntisFetch {
Future
<
JsonWithCookies
>
_requestJson
(
RequestOptions
options
)
async
{
Future
<
JsonWithCookies
>
_requestJson
(
RequestOptions
options
)
async
{
final
(
_
,
String
method
,
_
)
=
options
;
final
(
_
,
String
method
,
_
)
=
options
;
final
before
=
DateTime
.
now
();
final
response
=
await
_request
(
method
,
_makeUri
(
options
));
final
response
=
await
_request
(
method
,
_makeUri
(
options
));
final
cookies
=
response
.
cookies
;
final
cookies
=
response
.
cookies
;
final
SimpleCookieMap
cookieMap
=
{}
;
final
resultCookies
=
<
Cookie
>[]
;
for
(
final
cookie
in
cookies
)
{
for
(
final
cookie
in
cookies
)
{
if
(
_sessionCookieNames
.
contains
(
cookie
.
name
))
{
if
(
_sessionCookieNames
.
contains
(
cookie
.
name
))
{
cookieMap
[
cookie
.
name
]
=
cookie
.
value
;
resultCookies
.
add
(
cookie
)
;
}
}
}
}
final
afterDownloadStart
=
DateTime
.
now
();
final
responseTime
=
afterDownloadStart
.
difference
(
before
);
final
responseString
=
await
utf8
.
decodeStream
(
response
);
final
responseString
=
await
utf8
.
decodeStream
(
response
);
final
afterDownloadEnd
=
DateTime
.
now
();
final
downloadTime
=
afterDownloadEnd
.
difference
(
afterDownloadStart
);
final
bodyJson
=
jsonDecode
(
responseString
);
final
bodyJson
=
jsonDecode
(
responseString
);
return
(
bodyJson
as
Json
,
cookieMap
);
final
afterDecode
=
DateTime
.
now
();
final
decodeTime
=
afterDecode
.
difference
(
afterDownloadEnd
);
final
timeStats
=
{
'Ping'
:
responseTime
,
'Download'
:
downloadTime
,
'JSON'
:
decodeTime
,
};
print
(
timeStats
.
entries
.
map
((
e
)
=
>
'
${e.key}
:
${e.value.inMilliseconds}
ms'
)
.
join
(
', '
));
return
(
bodyJson
as
Json
,
resultCookies
);
}
}
Future
<
Json
>
requestOptions
(
RequestOptions
options
)
async
{
Future
<
Json
>
requestOptions
(
RequestOptions
options
)
async
{
...
@@ -95,14 +112,9 @@ class UntisFetch {
...
@@ -95,14 +112,9 @@ class UntisFetch {
final
methodPadded
=
method
.
padRight
(
8
);
final
methodPadded
=
method
.
padRight
(
8
);
print
(
'
$methodPadded
$uri
'
);
print
(
'
$methodPadded
$uri
'
);
final
before
=
DateTime
.
now
();
final
(
result
,
cookies
)
=
await
compute
(
_requestJson
,
options
);
final
(
result
,
cookies
)
=
await
compute
(
_requestJson
,
options
);
_sessionCookies
.
addAll
(
cookies
);
_sessionCookies
.
addAll
(
cookies
);
final
after
=
DateTime
.
now
();
final
totalTime
=
after
.
difference
(
before
);
print
(
'(Fetching/parsing took
${totalTime.inMilliseconds}
ms)'
);
return
result
;
return
result
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment