Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
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
Dima Krasner
Sharkey
Commits
8d81bd0d
Unverified
Commit
8d81bd0d
authored
6 years ago
by
syuilo
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1732 from rinsuki/fix/1731
Fix #1731
parents
5773a5bf
7275a481
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server/activitypub.ts
+27
-11
27 additions, 11 deletions
src/server/activitypub.ts
with
27 additions
and
11 deletions
src/server/activitypub.ts
+
27
−
11
View file @
8d81bd0d
...
...
@@ -7,7 +7,7 @@ const httpSignature = require('http-signature');
import
{
createHttp
}
from
'
../queue
'
;
import
pack
from
'
../remote/activitypub/renderer
'
;
import
Note
from
'
../models/note
'
;
import
User
,
{
isLocalUser
,
ILocalUser
}
from
'
../models/user
'
;
import
User
,
{
isLocalUser
,
ILocalUser
,
IUser
}
from
'
../models/user
'
;
import
renderNote
from
'
../remote/activitypub/renderer/note
'
;
import
renderKey
from
'
../remote/activitypub/renderer/key
'
;
import
renderPerson
from
'
../remote/activitypub/renderer/person
'
;
...
...
@@ -41,17 +41,18 @@ function inbox(ctx: Koa.Context) {
ctx
.
status
=
202
;
}
function
isActivityPubReq
(
ctx
:
Router
.
IRouterContext
)
{
const
accepted
=
ctx
.
accepts
(
'
html
'
,
'
application/activity+json
'
,
'
application/ld+json
'
);
return
[
'
application/activity+json
'
,
'
application/ld+json
'
].
includes
(
accepted
as
string
);
}
// inbox
router
.
post
(
'
/inbox
'
,
json
(),
inbox
);
router
.
post
(
'
/users/:user/inbox
'
,
json
(),
inbox
);
// note
router
.
get
(
'
/notes/:note
'
,
async
(
ctx
,
next
)
=>
{
const
accepted
=
ctx
.
accepts
(
'
html
'
,
'
application/activity+json
'
,
'
application/ld+json
'
);
if
(
!
[
'
application/activity+json
'
,
'
application/ld+json
'
].
includes
(
accepted
as
string
))
{
await
next
();
return
;
}
if
(
!
isActivityPubReq
(
ctx
))
return
await
next
();
const
note
=
await
Note
.
findOne
({
_id
:
new
mongo
.
ObjectID
(
ctx
.
params
.
note
)
...
...
@@ -112,6 +113,15 @@ router.get('/users/:user/publickey', async ctx => {
});
// user
function
userInfo
(
ctx
:
Router
.
IRouterContext
,
user
:
IUser
)
{
if
(
user
===
null
)
{
ctx
.
status
=
404
;
return
;
}
ctx
.
body
=
pack
(
renderPerson
(
user
as
ILocalUser
));
}
router
.
get
(
'
/users/:user
'
,
async
ctx
=>
{
const
userId
=
new
mongo
.
ObjectID
(
ctx
.
params
.
user
);
...
...
@@ -120,12 +130,18 @@ router.get('/users/:user', async ctx => {
host
:
null
});
if
(
user
===
null
)
{
ctx
.
status
=
404
;
return
;
}
userInfo
(
ctx
,
user
);
});
ctx
.
body
=
pack
(
renderPerson
(
user
as
ILocalUser
));
router
.
get
(
'
/@:user
'
,
async
(
ctx
,
next
)
=>
{
if
(
!
isActivityPubReq
(
ctx
))
return
await
next
();
const
user
=
await
User
.
findOne
({
usernameLower
:
ctx
.
params
.
user
.
toLowerCase
(),
host
:
null
});
userInfo
(
ctx
,
user
);
});
// follow form
...
...
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