FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/common/app/services/SkimLinksCache.scala at master · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
common
/
app
/
services
/
SkimLinksCache.scala
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (31 loc) · 1.09 KB
Breadcrumbs
frontend
/
common
/
app
/
services
/
SkimLinksCache.scala
Copy path
File metadata and controls
40 lines (31 loc) · 1.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package
services
import
java
.
net
.
URL
import
java
.
util
.
concurrent
.
atomic
.
AtomicReference
import
app
.
LifecycleComponent
import
common
.
Logging
import
scala
.
concurrent
.
ExecutionContext
import
scala
.
util
.
Try
object
SkimLinksCache
extends
Logging
{
private
val
skimLinkDomains
=
new
AtomicReference
(
Set
[
String
]())
def
populateSkimLinkDomains
()
:
Unit
=
{
log.info(
"
Fetching and caching skimlinks
"
)
val
domains
=
S3
.get(
"
skimlinks/skimlinks-domains.csv
"
).getOrElse{
log.error(
"
Failed to fetch skimlinks from S3
"
)
"
"
}
skimLinkDomains.set(domains.split(
"
,
"
).toSet)
}
def
isSkimLink
(
link
:
String
)
:
Boolean
=
{
val
uri
:
Option
[
URL
]
=
Try
(
new
URL
(link)).toOption
uri.exists(u
=>
{
//
strip the www. subdomain as it is not included in the list of domains from the skimlinks api
val
cleanedHost
=
u.getHost.replace(
"
www.
"
,
"
"
)
skimLinkDomains.get().contains(cleanedHost)
})
}
}
class
SkimLinksCacheLifeCycle
()(
implicit
ec
:
ExecutionContext
)
extends
LifecycleComponent
{
override
def
start
()
:
Unit
=
{
SkimLinksCache
.populateSkimLinkDomains()
}
}
Back
|
FazBrowse Home
|
New Git URL