Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010357
url.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
url.ts
View Options
import
{
URL
}
from
"url"
;
import
type
{
ValidationResult
}
from
"../../../chip-types/field.js"
;
import
{
Field
,
Context
}
from
"../../../main.js"
;
export
type
UrlParams
=
Partial
<
{
allowed_origins
:
string
[];
allowed_protocols
:
string
[];
}
>
;
export
default
class
Url
extends
Field
<
string
>
{
typeName
=
"url"
;
params
:
UrlParams
;
constructor
(
params
:
UrlParams
=
{})
{
super
();
this
.
params
=
params
;
}
async
isProperValue
(
context
:
Context
,
value
:
string
)
:
Promise
<
ValidationResult
>
{
const
allowed_protocols
=
this
.
params
.
allowed_protocols
?
this
.
params
.
allowed_protocols
.
map
((
protocol
)
=>
`
${
protocol
}
:`
)
:
[];
let
url
;
try
{
url
=
new
URL
(
value
);
}
catch
(
err
)
{
return
Field
.
invalid
(
err
);
}
if
(
this
.
params
.
allowed_origins
&&
!
this
.
params
.
allowed_origins
.
includes
(
url
.
hostname
)
)
{
return
Field
.
invalid
(
context
.
app
.
i18n
(
"not_allowed_domain"
,
[
url
.
hostname
,
this
.
params
.
allowed_origins
,
])
);
}
if
(
this
.
params
.
allowed_protocols
&&
!
allowed_protocols
.
includes
(
url
.
protocol
)
)
{
return
Field
.
invalid
(
context
.
app
.
i18n
(
"not_allowed_protocol"
,
[
url
.
protocol
,
this
.
params
.
allowed_protocols
,
])
);
}
return
Field
.
valid
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:41 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
636292
Default Alt Text
url.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment