ap

package
v0.0.0-...-48dcf97 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: AGPL-3.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ap provides ActivityPub resource endpoints for users and notes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeliveryGate

type DeliveryGate interface {
	CanFetchOptionalRemoteData(host string) bool
}

DeliveryGate reports whether this server federates with a host: it is not blocked, not outside the federation allowlist, and not an instance an admin suspended (the same decision as delivery), answering false when that cannot be decided. Implemented by instance.Service.

type FetchSignerAuthenticator

type FetchSignerAuthenticator interface {
	AuthenticateFetch(req *http.Request) (*model.User, error)
}

FetchSignerAuthenticator identifies the remote user who signed a GET for an ActivityPub object (#3914). Implemented by federation.SignedFetchAuthenticator, which only uses keys already stored in the database.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles ActivityPub resource endpoints.

func NewHandler

func NewHandler(
	renderer *activitypub.Renderer,
	userService *coreuser.Service,
	queryService *corenote.QueryService,
	keypairRepo repository.UserKeypairRepository,
	idGen id.Generator,
	noteHider *notehide.Hider,
	entityPacker *entity.Packer,
	hostBlocker HostBlockChecker,
	localHost string,
	softwareBlocker SoftwareSuspensionChecker,
	detailExtras userpack.DetailExtras,
) *Handler

NewHandler constructs a Handler.

noteHider applies the per-viewer hideNote gate to the notes this handler packs (#3786) and entityPacker is the Packer it packs entities with (#3790). hostBlocker and localHost are the federation-policy checker and the local hostname APIShow uses to reject lookups of blocked / non-federated hosts (#1557). softwareBlocker is the meta.inboxSuspendedSoftware checker APIShow uses (#3563). detailExtras fills pinnedNotes / pinnedPage / movedTo / alsoKnownAs for ap/show (#3330).

func (*Handler) APIGet

func (h *Handler) APIGet(c *echo.Context) error

APIGet handles POST /api/ap/get — Admin専用。URIからActivityPubオブジェクトを取得。

func (*Handler) APIShow

func (h *Handler) APIShow(c *echo.Context) error

APIShow handles POST /api/ap/show — URIからUser/Noteを解決して返す。

func (*Handler) Featured

func (h *Handler) Featured(c *echo.Context) error

Featured handles GET /users/:id/collections/featured, serving the local user's pinned notes as an OrderedCollection (upstream ActivityPubServerService.featured, #1876)。actor が advertise する featured URI に 対応する。pinned note は inline 出力 (pagination 無し、upstream と同じ)。

upstream と同じく !localOnly かつ visibility ∈ {public, home} の note のみ serve し、 followers/specified/localOnly な pinned note を unauthenticated AP へ leak させない。

func (*Handler) Followers

func (h *Handler) Followers(c *echo.Context) error

Followers handles GET /users/:id/followers (#1877)。

func (*Handler) Following

func (h *Handler) Following(c *echo.Context) error

Following handles GET /users/:id/following (#1877)。

func (*Handler) Note

func (h *Handler) Note(c *echo.Context) error

Note handles GET /notes/:id with ActivityPub content negotiation. AP clients receive the AS Note object; browser reloads are handed off to the frontend fallback so the SPA renders the note permalink.

func (*Handler) NoteActivity

func (h *Handler) NoteActivity(c *echo.Context) error

NoteActivity handles GET /notes/:id/activity (upstream ActivityPubServerService の /notes/:note/activity、#2507)。

renderer は Create / Announce の activity id として `<note URI>/activity` を **外向きに広告している** (RenderCreate / RenderAnnounce)。この route が無いと、 広告した id を dereference しに来た他サーバーが 404 を受け取る。

func (*Handler) Outbox

func (h *Handler) Outbox(c *echo.Context) error

Outbox handles GET /users/:id/outbox, serving the local user's public/home (non-localOnly) notes as Create/Announce activities in an OrderedCollection (upstream ActivityPubServerService.outbox, #1878)。

func (*Handler) QuoteAuthorization

func (h *Handler) QuoteAuthorization(c *echo.Context) error

QuoteAuthorization handles GET /notes/:id/quote-authorizations/:authId, the FEP-044f approval stamp for a quote of a local note (#3234).

**公開範囲では絞らない。** followers 限定の投稿への引用でも、第三者 (引用を 表示するサーバー) はこれを取得して確かめる。出すのは URI だけで、投稿の中身は 埋め込まない (FEP の MUST NOT) ので、見る権限の無い相手に中身は渡らない。 プラグインの配送先の条件では絞る (ローカルのノートの /notes/:id と同じ答えにする)。

func (*Handler) SetExternalRedirectPolicy

func (h *Handler) SetExternalRedirectPolicy(allow func() bool, selfURL string)

SetExternalRedirectPolicy wires meta.allowExternalApRedirect. allow is read on every redirect so the setting takes effect without a restart. selfURL is this server's URL (config.url); a redirect is local only when its scheme and host (with the port) match it.

func (*Handler) SetFetchSigner

func (h *Handler) SetFetchSigner(a FetchSignerAuthenticator, delivery DeliveryGate, deliverSoftware SoftwareSuspensionChecker)

SetFetchSigner wires what lets a signed GET of /notes/:id and /notes/:id/activity return followers-only and specified notes to a remote user allowed to see them (#3914): the authenticator, and the two delivery decisions a signer's host must pass (delivery, and deliverSoftware for meta.deliverSuspendedSoftware). Without them only public and home notes are served, as before.

func (*Handler) SetFollowingRepo

func (h *Handler) SetFollowingRepo(r repository.FollowingRepository)

SetFollowingRepo wires the repository used by the followers/following AP collection endpoints (#1877)。

func (*Handler) SetKeypairExtraRepo

func (h *Handler) SetKeypairExtraRepo(r repository.UserKeypairExtraRepository)

SetKeypairExtraRepo wires the Ed25519 keypair repository so that actor JSON responses can include `assertionMethod[]` Multikey entries for users that own an Ed25519 keypair (#1067 / #1069). Optional: 未配線でも RSA only で 動き、upstream Misskey TS と同一の actor JSON shape を維持する。

func (*Handler) SetLocalFederationObserver

func (h *Handler) SetLocalFederationObserver(observer activitypub.LocalFederationObserver)

SetLocalFederationObserver wires account-level availability and first-reference tracking.

func (*Handler) SetModeratorChecker

func (h *Handler) SetModeratorChecker(m ModeratorChecker)

SetModeratorChecker wires the check ap/show uses to decide whether the viewer may see suspended and deleted local users, as users/show does.

func (*Handler) SetNonAPFallback

func (h *Handler) SetNonAPFallback(fn echo.HandlerFunc)

SetNonAPFallback registers a handler to serve when the incoming Accept header does not request an ActivityPub document. Typically the SPA HTML frontend is registered here so that browser reloads on actor/note URLs render the frontend instead of returning a bare 404 JSON. Echo does not re-dispatch errored handlers to the catch-all route, so this delegation has to happen inside the AP handler itself.

func (*Handler) SetNoteDeliveryRules

func (h *Handler) SetNoteDeliveryRules(r *notedelivery.Registry)

SetNoteDeliveryRules wires the plugins that narrow which remote hosts may fetch local notes (#4199). nil で絞らない (初期状態)。

func (*Handler) SetNoteRepo

func (h *Handler) SetNoteRepo(r repository.NoteRepository)

SetNoteRepo wires the repository used by the outbox AP collection endpoint (#1878)。

func (*Handler) SetQuoteAuthorizationStore

func (h *Handler) SetQuoteAuthorizationStore(s QuoteAuthorizationStore)

SetQuoteAuthorizationStore wires the store serving QuoteAuthorization.

func (*Handler) SetRelationRepos

func (h *Handler) SetRelationRepos(r userrelation.Repos)

SetRelationRepos wires the repositories used to populate the viewer relation block on ap/show user responses (#1778)。

func (*Handler) SetRemote

func (h *Handler) SetRemote(fetcher RemoteFetcher, resolver RemoteResolver)

SetRemote attaches remote AP fetcher and resolver.

func (*Handler) User

func (h *Handler) User(c *echo.Context) error

User handles GET /users/:id with ActivityPub content negotiation. AP clients (Accept: application/activity+json) receive the Person document; browser callers are 302-redirected to the canonical `/@<username>` permalink so the SPA's userPage route can resolve.

Misskey TS の ClientServerService.ts と同じ挙動: 共有 frontend は `/users/:id` の SPA ルートを持たず `/@:acct` のみなので、QR code (frontend が自分の id で組み立てる) や AP federation 由来のリンクから来た訪問者を 確実に SPA で開けるよう backend で redirect する (#691)。リモート user の場合は SPA 側でも canonical な remote URI を開かせるため Host 付きで `/@username@host` 形式に redirect する。

func (*Handler) UserByAcct

func (h *Handler) UserByAcct(c *echo.Context) error

UserByAcct handles GET /@:acct with ActivityPub content negotiation. When the Accept header prefers application/activity+json (which is how other AP implementations resolve actors that they discovered via WebFinger or a raw link), return the Person document. Otherwise delegate to the non-AP fallback so browser reloads render the SPA frontend instead of a bare 404.

type HostBlockChecker

type HostBlockChecker interface {
	IsBlocked(host string) bool
	IsAllowed(host string) bool
	// FederationDisabled reports whether the instance federation mode is
	// "none" (fully isolated)。true のとき AP serve handler は 403 を返す
	// (upstream ActivityPubServerService の federation==='none' gate、#1879)。
	FederationDisabled() bool
}

HostBlockChecker reports whether a remote host is blocked / federation-allowed under the running instance's federation policy (none / specified / blockedHosts)。 APIShow uses it to reject lookups of non-federated hosts (#1557、upstream UtilityService.isFederationAllowedUri)。

type KeyedNoteResolver

type KeyedNoteResolver interface {
	ResolveNoteAllowCrossHostWithKey(uri string, key *activitypub.PrivateKey) (*model.Note, error)
}

KeyedNoteResolver resolves a remote note, retrying with the given key when the instance actor cannot see it (#3915). Implemented by federation.Resolver.

type KeyedRemoteFetcher

type KeyedRemoteFetcher interface {
	FetchObjectSignedBy(uri string, key *activitypub.PrivateKey) ([]byte, error)
}

KeyedRemoteFetcher fetches a remote object with a GET signed by the given key, without an unsigned fallback (#3915). Implemented by federation.APFetcher.

type ModeratorChecker

type ModeratorChecker interface {
	IsModerator(userID string) bool
}

ModeratorChecker reports whether a user is a moderator. *role.Service satisfies it.

type QuoteAuthorizationStore

type QuoteAuthorizationStore interface {
	FindByIDAndNoteID(id, noteID string) (*model.NoteQuoteAuthorization, error)
}

QuoteAuthorizationStore looks up quote approvals (#3234).

type RemoteFetcher

type RemoteFetcher interface {
	FetchObject(uri string) ([]byte, error)
}

RemoteFetcher fetches remote ActivityPub objects.

type RemoteResolver

type RemoteResolver interface {
	ResolveActor(uri string) (*model.User, error)
	ResolveNote(uri string) (*model.Note, error)
	// *AllowCrossHost variants relax the request-url ↔ id host binding for
	// user-initiated /api/ap/show lookups (upstream CrossOrigin softfail、#1828)。
	// federation-loop の解決は Strict な ResolveActor / ResolveNote を使う。
	ResolveActorAllowCrossHost(uri string) (*model.User, error)
	ResolveNoteAllowCrossHost(uri string) (*model.Note, error)
}

RemoteResolver resolves remote actors and notes.

type SoftwareSuspensionChecker

type SoftwareSuspensionChecker interface {
	IsSuspended(host string) bool
}

SoftwareSuspensionChecker reports whether a host runs software listed in meta.inboxSuspendedSoftware (#3362)。実装は core/federation.NewInboxSuspendedChecker。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL