Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
338
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
23
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
Service Desk
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
TransFem.org
Sharkey
Commits
e0e4bdbd
Unverified
Commit
e0e4bdbd
authored
6 years ago
by
syuilo
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' of
https://github.com/syuilo/misskey
into develop
parents
b3daf79b
81aa2191
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/prelude/xml.ts
+41
-0
41 additions, 0 deletions
src/prelude/xml.ts
src/server/well-known.ts
+48
-22
48 additions, 22 deletions
src/server/well-known.ts
with
89 additions
and
22 deletions
src/prelude/xml.ts
0 → 100644
+
41
−
0
View file @
e0e4bdbd
const
map
:
Record
<
string
,
string
>
=
{
'
&
'
:
'
&
'
,
'
<
'
:
'
<
'
,
'
>
'
:
'
>
'
,
'
"
'
:
'
"
'
,
'
\'
'
:
'
'
'
};
const
beginingOfCDATA
=
'
<![CDATA[
'
;
const
endOfCDATA
=
'
]]>
'
;
export
function
escapeValue
(
x
:
string
):
string
{
let
insideOfCDATA
=
false
;
let
builder
=
''
;
for
(
let
i
=
0
;
i
<
x
.
length
;
)
{
if
(
insideOfCDATA
)
{
if
(
x
.
slice
(
i
,
i
+
beginingOfCDATA
.
length
)
===
beginingOfCDATA
)
{
insideOfCDATA
=
true
;
i
+=
beginingOfCDATA
.
length
;
}
else
{
builder
+=
x
[
i
++
];
}
}
else
{
if
(
x
.
slice
(
i
,
i
+
endOfCDATA
.
length
)
===
endOfCDATA
)
{
insideOfCDATA
=
false
;
i
+=
endOfCDATA
.
length
;
}
else
{
const
b
=
x
[
i
++
];
builder
+=
map
[
b
]
||
b
;
}
}
}
return
builder
;
}
export
function
escapeAttribute
(
x
:
string
):
string
{
return
Object
.
entries
(
map
).
reduce
((
a
,
[
k
,
v
])
=>
a
.
replace
(
k
,
v
),
x
);
}
This diff is collapsed.
Click to expand it.
src/server/well-known.ts
+
48
−
22
View file @
e0e4bdbd
...
...
@@ -6,27 +6,37 @@ import parseAcct from '../misc/acct/parse';
import
User
from
'
../models/user
'
;
import
Acct
from
'
../misc/acct/type
'
;
import
{
links
}
from
'
./nodeinfo
'
;
import
{
escapeAttribute
,
escapeValue
}
from
'
../prelude/xml
'
;
// Init router
const
router
=
new
Router
();
const
XRD
=
(...
x
:
{
element
:
string
,
value
?:
string
,
attributes
?:
Record
<
string
,
string
>
}[])
=>
`<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
${
x
.
map
(({
element
,
value
,
attributes
})
=>
`<
${
Object
.
entries
(
typeof
attributes
===
'
object
'
&&
attributes
||
{}).
reduce
((
a
,
[
k
,
v
])
=>
`
${
a
}
${
k
}
="
${
escapeAttribute
(
v
)}
"`
,
element
)
}${
typeof
value
===
'
string
'
?
`>
${
escapeValue
(
value
)}
</
${
element
}
`
:
'
/
'
}
>`
).
reduce
((
a
,
c
)
=>
a
+
c
,
''
)}
</XRD>`
;
const
webFingerPath
=
'
/.well-known/webfinger
'
;
const
jrd
=
'
application/jrd+json
'
;
const
xrd
=
'
application/xrd+xml
'
;
router
.
get
(
'
/.well-known/host-meta
'
,
async
ctx
=>
{
ctx
.
set
(
'
Content-Type
'
,
'
application/xrd+xml
'
);
ctx
.
body
=
`<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" type="application/xrd+xml" template="
${
config
.
url
}${
webFingerPath
}
?resource={uri}"/>
</XRD>
`
;
ctx
.
set
(
'
Content-Type
'
,
xrd
);
ctx
.
body
=
XRD
({
element
:
'
Link
'
,
attributes
:
{
type
:
xrd
,
template
:
`
${
config
.
url
}${
webFingerPath
}
?resource={uri}`
}});
});
router
.
get
(
'
/.well-known/host-meta.json
'
,
async
ctx
=>
{
ctx
.
set
(
'
Content-Type
'
,
'
application/jrd+json
'
);
ctx
.
set
(
'
Content-Type
'
,
jrd
);
ctx
.
body
=
{
links
:
[{
rel
:
'
lrdd
'
,
type
:
'
application/xrd+xml
'
,
type
:
jrd
,
template
:
`
${
config
.
url
}${
webFingerPath
}
?resource={uri}`
}]
};
...
...
@@ -75,22 +85,38 @@ router.get(webFingerPath, async ctx => {
return
;
}
ctx
.
body
=
{
subject
:
`acct:
${
user
.
username
}
@
${
config
.
host
}
`
,
links
:
[{
rel
:
'
self
'
,
type
:
'
application/activity+json
'
,
href
:
`
${
config
.
url
}
/users/
${
user
.
_id
}
`
},
{
rel
:
'
http://webfinger.net/rel/profile-page
'
,
type
:
'
text/html
'
,
href
:
`
${
config
.
url
}
/@
${
user
.
username
}
`
},
{
rel
:
'
http://ostatus.org/schema/1.0/subscribe
'
,
template
:
`
${
config
.
url
}
/authorize-follow?acct={uri}`
}]
const
subject
=
`acct:
${
user
.
username
}
@
${
config
.
host
}
`
;
const
self
=
{
rel
:
'
self
'
,
type
:
'
application/activity+json
'
,
href
:
`
${
config
.
url
}
/users/
${
user
.
_id
}
`
};
const
profilePage
=
{
rel
:
'
http://webfinger.net/rel/profile-page
'
,
type
:
'
text/html
'
,
href
:
`
${
config
.
url
}
/@
${
user
.
username
}
`
};
const
subscribe
=
{
rel
:
'
http://ostatus.org/schema/1.0/subscribe
'
,
template
:
`
${
config
.
url
}
/authorize-follow?acct={uri}`
};
if
(
ctx
.
accepts
(
jrd
,
xrd
)
===
xrd
)
{
ctx
.
body
=
XRD
(
{
element
:
'
Subject
'
,
value
:
subject
},
{
element
:
'
Link
'
,
attributes
:
self
},
{
element
:
'
Link
'
,
attributes
:
profilePage
},
{
element
:
'
Link
'
,
attributes
:
subscribe
});
ctx
.
type
=
xrd
;
}
else
{
ctx
.
body
=
{
subject
,
links
:
[
self
,
profilePage
,
subscribe
]
};
ctx
.
type
=
jrd
;
}
ctx
.
vary
(
'
Accept
'
);
ctx
.
set
(
'
Cache-Control
'
,
'
public, max-age=180
'
);
});
...
...
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