@fedify/fedify 2.4.0-dev.1599 → 2.4.0-dev.1634
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{builder-BvCI7Xch.mjs → builder-DYAAegyy.mjs} +24 -2
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-C7Sbmci2.mjs → context-BJXxPElm.mjs} +2 -1
- package/dist/{context-GfQA-CqB.d.ts → context-Zii1f5xS.d.ts} +97 -1
- package/dist/{context-BLe0NPtZ.d.cts → context-lxX6I7as.d.cts} +97 -1
- package/dist/{deno-BCt09TJn.mjs → deno-C30u61BX.mjs} +1 -1
- package/dist/{docloader-BrRjFwOp.mjs → docloader-C8JfZ3bD.mjs} +2 -2
- package/dist/federation/builder.test.mjs +11 -1
- package/dist/federation/handler.test.mjs +6 -4
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +456 -8
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/send.test.mjs +3 -3
- package/dist/federation/tasks/enqueue.test.mjs +2 -2
- package/dist/federation/tasks/tasks.test.mjs +3 -3
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +2 -2
- package/dist/{http-yainOC9t.mjs → http-DJEaNMSB.mjs} +3 -3
- package/dist/{http--wLYmH1x.js → http-D_cl_PbN.js} +1 -1
- package/dist/{http-zJsVCnKu.cjs → http-DiMJDFtd.cjs} +1 -1
- package/dist/{key-DcLwG7x4.mjs → key-C1tsoBAW.mjs} +2 -2
- package/dist/{kv-cache-BPu_M3-N.cjs → kv-cache-BInLi0Ro.cjs} +1 -1
- package/dist/{kv-cache-SZL9uu3V.mjs → kv-cache-D9Tia3Td.mjs} +1 -1
- package/dist/{kv-cache-0TGAGm8S.js → kv-cache-EL9jIFqA.js} +1 -1
- package/dist/{ld-B-jskR-q.mjs → ld-CDBNQmZD.mjs} +3 -3
- package/dist/{metrics-C-pKLuAU.mjs → metrics-De7b7Hgb.mjs} +1 -1
- package/dist/{middleware-D1POKL1d.js → middleware-8oyKaRYF.js} +245 -3
- package/dist/{middleware-DLzOFLD5.cjs → middleware-BPHpdYl4.cjs} +245 -3
- package/dist/{middleware-DGEQ07xT.mjs → middleware-CPlgpBML.mjs} +232 -12
- package/dist/{middleware-HFQkD-r8.mjs → middleware-DloBgcWp.mjs} +1 -1
- package/dist/{mod-Cmr39iWq.d.ts → mod-DLc2Ot6f.d.ts} +1 -1
- package/dist/{mod-B8Efb9qp.d.cts → mod-gOlPDuT8.d.cts} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.d.cts +4 -4
- package/dist/mod.d.ts +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/handler.test.mjs +2 -2
- package/dist/{owner-CeJuB8wq.mjs → owner-CB3dPva0.mjs} +2 -2
- package/dist/{proof-BkQosXrd.cjs → proof-BI4Wn6Ur.cjs} +13 -2
- package/dist/{proof-917XYw_e.mjs → proof-BqDtIxGz.mjs} +16 -4
- package/dist/{proof-Bri1zUVM.js → proof-DT5SgzkH.js} +14 -3
- package/dist/{send-CDi3XQ0V.mjs → send-ClWims8x.mjs} +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +2 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +138 -1
- package/dist/{temporal-jusSJxbN.mjs → temporal-DyITEDcU.mjs} +1 -1
- package/dist/testing/mod.d.mts +96 -0
- package/dist/testing/mod.mjs +2 -2
- package/dist/{testing-C3vgUK0b.mjs → testing-CO7ftO8A.mjs} +1 -1
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
2
|
const require_chunk = require("./chunk-Czpeue4M.cjs");
|
|
3
3
|
const require_transformers = require("./transformers-DGwl-hD1.cjs");
|
|
4
|
-
const require_http = require("./http-
|
|
4
|
+
const require_http = require("./http-DiMJDFtd.cjs");
|
|
5
5
|
const require_temporal_polyfill = require("./temporal-polyfill-BCdTHexd.cjs");
|
|
6
|
-
const require_proof = require("./proof-
|
|
6
|
+
const require_proof = require("./proof-BI4Wn6Ur.cjs");
|
|
7
7
|
const require_types = require("./types-CPym83zc.cjs");
|
|
8
|
-
const require_kv_cache = require("./kv-cache-
|
|
8
|
+
const require_kv_cache = require("./kv-cache-BInLi0Ro.cjs");
|
|
9
9
|
let _logtape_logtape = require("@logtape/logtape");
|
|
10
10
|
let _fedify_uri_template = require("@fedify/uri-template");
|
|
11
11
|
let _fedify_vocab = require("@fedify/vocab");
|
|
@@ -103,6 +103,9 @@ var FederationBuilderImpl = class {
|
|
|
103
103
|
inboxErrorHandler;
|
|
104
104
|
outboxListenerErrorHandler;
|
|
105
105
|
outboxAuthorizePredicate;
|
|
106
|
+
mediaUploaderPath;
|
|
107
|
+
mediaUploaderCallback;
|
|
108
|
+
mediaUploaderAuthorizePredicate;
|
|
106
109
|
sharedInboxKeyDispatcher;
|
|
107
110
|
unverifiedActivityHandler;
|
|
108
111
|
outboxPermanentFailureHandler;
|
|
@@ -155,6 +158,9 @@ var FederationBuilderImpl = class {
|
|
|
155
158
|
f.inboxErrorHandler = this.inboxErrorHandler;
|
|
156
159
|
f.outboxListenerErrorHandler = this.outboxListenerErrorHandler;
|
|
157
160
|
f.outboxAuthorizePredicate = this.outboxAuthorizePredicate;
|
|
161
|
+
f.mediaUploaderPath = this.mediaUploaderPath;
|
|
162
|
+
f.mediaUploaderCallback = this.mediaUploaderCallback;
|
|
163
|
+
f.mediaUploaderAuthorizePredicate = this.mediaUploaderAuthorizePredicate;
|
|
158
164
|
f.sharedInboxKeyDispatcher = this.sharedInboxKeyDispatcher;
|
|
159
165
|
f.unverifiedActivityHandler = this.unverifiedActivityHandler;
|
|
160
166
|
f.outboxPermanentFailureHandler = this.outboxPermanentFailureHandler;
|
|
@@ -233,6 +239,10 @@ var FederationBuilderImpl = class {
|
|
|
233
239
|
if (actor.publicKeyId == null) logger.warn("You configured a key pairs dispatcher, but the actor does not have a publicKey property. Set the property with Context.getActorKeyPairs(identifier).");
|
|
234
240
|
if (actor.assertionMethodId == null) logger.warn("You configured a key pairs dispatcher, but the actor does not have an assertionMethod property. Set the property with Context.getActorKeyPairs(identifier).");
|
|
235
241
|
}
|
|
242
|
+
if (this.mediaUploaderCallback != null) {
|
|
243
|
+
if (actor.endpoints == null || actor.endpoints.uploadMedia == null) logger.warn("You configured a media uploader, but the actor does not have a endpoints.uploadMedia property. Set the property with Context.getMediaUploaderUri(identifier).");
|
|
244
|
+
else if (actor.endpoints.uploadMedia.href != context.getMediaUploaderUri(identifier).href) logger.warn("You configured a media uploader, but the actor's endpoints.uploadMedia property does not match the media upload endpoint URI. Set the property with Context.getMediaUploaderUri(identifier).");
|
|
245
|
+
}
|
|
236
246
|
return actor;
|
|
237
247
|
} };
|
|
238
248
|
this.actorCallbacks = callbacks;
|
|
@@ -445,6 +455,18 @@ var FederationBuilderImpl = class {
|
|
|
445
455
|
};
|
|
446
456
|
return setters;
|
|
447
457
|
}
|
|
458
|
+
setMediaUploader(path, callback) {
|
|
459
|
+
if (this.mediaUploaderCallback != null) throw new _fedify_uri_template.RouterError("Media uploader already set.");
|
|
460
|
+
(0, _fedify_uri_template.assertPath)(path);
|
|
461
|
+
this.router.add(path, "mediaUploader", identifierSingular);
|
|
462
|
+
this.mediaUploaderPath = path;
|
|
463
|
+
this.mediaUploaderCallback = callback;
|
|
464
|
+
const setters = { authorize: (predicate) => {
|
|
465
|
+
this.mediaUploaderAuthorizePredicate = predicate;
|
|
466
|
+
return setters;
|
|
467
|
+
} };
|
|
468
|
+
return setters;
|
|
469
|
+
}
|
|
448
470
|
setFollowingDispatcher(path, dispatcher) {
|
|
449
471
|
if (this.router.has("following")) throw new _fedify_uri_template.RouterError("Following collection dispatcher already set.");
|
|
450
472
|
(0, _fedify_uri_template.assertPath)(path);
|
|
@@ -2020,6 +2042,193 @@ async function handleOutbox(request, { identifier, context: ctx, outboxContextFa
|
|
|
2020
2042
|
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
2021
2043
|
});
|
|
2022
2044
|
}
|
|
2045
|
+
const plainTextHeaders = { "Content-Type": "text/plain; charset=utf-8" };
|
|
2046
|
+
/**
|
|
2047
|
+
* Handles a media upload request (the [ActivityPub Media Upload
|
|
2048
|
+
* extension](https://www.w3.org/wiki/SocialCG/ActivityPub/MediaUpload)).
|
|
2049
|
+
* @template TContextData The context data to pass to the context.
|
|
2050
|
+
* @param request The HTTP request.
|
|
2051
|
+
* @param parameters The parameters for handling the request.
|
|
2052
|
+
* @returns A promise that resolves to an HTTP response.
|
|
2053
|
+
* @since 2.4.0
|
|
2054
|
+
*/
|
|
2055
|
+
async function handleMediaUpload(request, { identifier, context: ctx, mediaUploaderCallback, actorDispatcher, authorizePredicate, isRegisteredObjectUri, onUnauthorized, onNotFound }) {
|
|
2056
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
2057
|
+
"fedify",
|
|
2058
|
+
"federation",
|
|
2059
|
+
"mediaUploader"
|
|
2060
|
+
]);
|
|
2061
|
+
if (request.bodyUsed) {
|
|
2062
|
+
logger.error("Request body has already been read.", { identifier });
|
|
2063
|
+
return new Response("Internal server error.", {
|
|
2064
|
+
status: 500,
|
|
2065
|
+
headers: plainTextHeaders
|
|
2066
|
+
});
|
|
2067
|
+
} else if (request.body?.locked) {
|
|
2068
|
+
logger.error("Request body is locked.", { identifier });
|
|
2069
|
+
return new Response("Internal server error.", {
|
|
2070
|
+
status: 500,
|
|
2071
|
+
headers: plainTextHeaders
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
const contentType = request.headers.get("content-type");
|
|
2075
|
+
if (contentType == null || !contentType.toLowerCase().startsWith("multipart/form-data")) {
|
|
2076
|
+
logger.error("The media upload request is not multipart/form-data (got {contentType}).", {
|
|
2077
|
+
identifier,
|
|
2078
|
+
contentType
|
|
2079
|
+
});
|
|
2080
|
+
return new Response("Unsupported media type.", {
|
|
2081
|
+
status: 415,
|
|
2082
|
+
headers: plainTextHeaders
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
if (actorDispatcher == null) {
|
|
2086
|
+
logger.error("Actor dispatcher is not set.", { identifier });
|
|
2087
|
+
return await onNotFound(request);
|
|
2088
|
+
}
|
|
2089
|
+
const actor = await actorDispatcher(ctx, identifier);
|
|
2090
|
+
if (actor == null || actor instanceof _fedify_vocab.Tombstone) {
|
|
2091
|
+
logger.error("Actor {identifier} not found.", { identifier });
|
|
2092
|
+
return await onNotFound(request);
|
|
2093
|
+
}
|
|
2094
|
+
if (authorizePredicate != null) {
|
|
2095
|
+
let body;
|
|
2096
|
+
try {
|
|
2097
|
+
body = await request.arrayBuffer();
|
|
2098
|
+
} catch (error) {
|
|
2099
|
+
logger.error("Failed to read the multipart/form-data body:\n{error}", {
|
|
2100
|
+
identifier,
|
|
2101
|
+
error
|
|
2102
|
+
});
|
|
2103
|
+
return new Response("Invalid multipart/form-data body.", {
|
|
2104
|
+
status: 400,
|
|
2105
|
+
headers: plainTextHeaders
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
const rebuild = () => new Request(request.url, {
|
|
2109
|
+
method: request.method,
|
|
2110
|
+
headers: request.headers,
|
|
2111
|
+
body: body.byteLength > 0 ? body : void 0
|
|
2112
|
+
});
|
|
2113
|
+
const authorizeContext = ctx.clone(ctx.data);
|
|
2114
|
+
authorizeContext.request = rebuild();
|
|
2115
|
+
if (!await authorizePredicate(authorizeContext, identifier)) return await onUnauthorized(rebuild());
|
|
2116
|
+
request = rebuild();
|
|
2117
|
+
}
|
|
2118
|
+
let form;
|
|
2119
|
+
try {
|
|
2120
|
+
form = await request.formData();
|
|
2121
|
+
} catch (error) {
|
|
2122
|
+
logger.error("Failed to parse the multipart/form-data body:\n{error}", {
|
|
2123
|
+
identifier,
|
|
2124
|
+
error
|
|
2125
|
+
});
|
|
2126
|
+
return new Response("Invalid multipart/form-data body.", {
|
|
2127
|
+
status: 400,
|
|
2128
|
+
headers: plainTextHeaders
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
const file = form.get("file");
|
|
2132
|
+
if (!(file instanceof File)) {
|
|
2133
|
+
logger.error("The media upload request has no file field.", { identifier });
|
|
2134
|
+
return new Response("Missing file field.", {
|
|
2135
|
+
status: 400,
|
|
2136
|
+
headers: plainTextHeaders
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
const objectField = form.get("object");
|
|
2140
|
+
if (objectField == null) {
|
|
2141
|
+
logger.error("The media upload request has no object field.", { identifier });
|
|
2142
|
+
return new Response("Missing object field.", {
|
|
2143
|
+
status: 400,
|
|
2144
|
+
headers: plainTextHeaders
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
let object;
|
|
2148
|
+
try {
|
|
2149
|
+
const objectText = typeof objectField === "string" ? objectField : await objectField.text();
|
|
2150
|
+
object = await _fedify_vocab.Object.fromJsonLd(JSON.parse(objectText), ctx);
|
|
2151
|
+
} catch (error) {
|
|
2152
|
+
logger.error("Failed to parse the object field:\n{error}", {
|
|
2153
|
+
identifier,
|
|
2154
|
+
error
|
|
2155
|
+
});
|
|
2156
|
+
return new Response("Invalid object field.", {
|
|
2157
|
+
status: 400,
|
|
2158
|
+
headers: plainTextHeaders
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
let result;
|
|
2162
|
+
try {
|
|
2163
|
+
result = await mediaUploaderCallback(ctx, identifier, file, object);
|
|
2164
|
+
} catch (error) {
|
|
2165
|
+
logger.error("Failed to process the media upload:\n{error}", {
|
|
2166
|
+
identifier,
|
|
2167
|
+
error
|
|
2168
|
+
});
|
|
2169
|
+
return new Response("Internal server error.", {
|
|
2170
|
+
status: 500,
|
|
2171
|
+
headers: plainTextHeaders
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
if (result == null) {
|
|
2175
|
+
logger.error("The media uploader callback for {identifier} returned null or undefined; it must return an object (201 Created) or a URL (202 Accepted).", { identifier });
|
|
2176
|
+
return new Response("Internal server error.", {
|
|
2177
|
+
status: 500,
|
|
2178
|
+
headers: plainTextHeaders
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
const warnUnlessRegistered = (target) => {
|
|
2182
|
+
if (isRegisteredObjectUri(target)) return;
|
|
2183
|
+
logger.warn("The media uploader callback for {identifier} returned {target}, which does not point at a registered object dispatcher route; derive the returned id/URL from Context.getObjectUri(). The upload still succeeded.", {
|
|
2184
|
+
identifier,
|
|
2185
|
+
target: target.href
|
|
2186
|
+
});
|
|
2187
|
+
};
|
|
2188
|
+
if (result instanceof URL) {
|
|
2189
|
+
warnUnlessRegistered(result);
|
|
2190
|
+
logger.info("The media upload for {identifier} is still being processed; responding 202 Accepted.", {
|
|
2191
|
+
identifier,
|
|
2192
|
+
location: result.href
|
|
2193
|
+
});
|
|
2194
|
+
return new Response(null, {
|
|
2195
|
+
status: 202,
|
|
2196
|
+
headers: { Location: result.href }
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
if (result.id == null) {
|
|
2200
|
+
logger.error("The media uploader callback for {identifier} returned an object without an id, so a 201 Created response cannot include the required Location header. Set the object's id with Context.getObjectUri(), or return the eventual URL to respond 202 Accepted instead.", { identifier });
|
|
2201
|
+
return new Response("Internal server error.", {
|
|
2202
|
+
status: 500,
|
|
2203
|
+
headers: plainTextHeaders
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
warnUnlessRegistered(result.id);
|
|
2207
|
+
let jsonLd;
|
|
2208
|
+
try {
|
|
2209
|
+
jsonLd = await result.toJsonLd(ctx);
|
|
2210
|
+
} catch (error) {
|
|
2211
|
+
logger.error("Failed to serialize the uploaded object to JSON-LD:\n{error}", {
|
|
2212
|
+
identifier,
|
|
2213
|
+
error
|
|
2214
|
+
});
|
|
2215
|
+
return new Response("Internal server error.", {
|
|
2216
|
+
status: 500,
|
|
2217
|
+
headers: plainTextHeaders
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
logger.info("The media upload for {identifier} is ready; responding 201 Created.", {
|
|
2221
|
+
identifier,
|
|
2222
|
+
location: result.id.href
|
|
2223
|
+
});
|
|
2224
|
+
return new Response(JSON.stringify(jsonLd), {
|
|
2225
|
+
status: 201,
|
|
2226
|
+
headers: {
|
|
2227
|
+
"Content-Type": "application/activity+json",
|
|
2228
|
+
Location: result.id.href
|
|
2229
|
+
}
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2023
2232
|
/**
|
|
2024
2233
|
* Handles an inbox request for ActivityPub activities.
|
|
2025
2234
|
* @template TContextData The context data to pass to the context.
|
|
@@ -4527,6 +4736,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
4527
4736
|
benchmarkMode;
|
|
4528
4737
|
benchmarkMetricReader;
|
|
4529
4738
|
benchmarkTriggerOptions;
|
|
4739
|
+
#mediaUploaderNoAuthWarned = false;
|
|
4530
4740
|
#queueDepthGaugeSourceId = `fedify-${(++nextQueueDepthGaugeSourceId).toString(36)}`;
|
|
4531
4741
|
#queueDepthGaugeEntries = [];
|
|
4532
4742
|
#queueDepthGaugeMeterProvider;
|
|
@@ -5842,6 +6052,32 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
5842
6052
|
});
|
|
5843
6053
|
case "benchmarkStats": return await handleBenchmarkStats(request, this.benchmarkMetricReader);
|
|
5844
6054
|
case "benchmarkTrigger": return await handleBenchmarkTrigger(request, context, this.benchmarkTriggerOptions);
|
|
6055
|
+
case "mediaUploader":
|
|
6056
|
+
if (request.method !== "POST" || this.mediaUploaderCallback == null) return new Response("Method not allowed.", {
|
|
6057
|
+
status: 405,
|
|
6058
|
+
headers: {
|
|
6059
|
+
Allow: "POST",
|
|
6060
|
+
"Content-Type": "text/plain; charset=utf-8"
|
|
6061
|
+
}
|
|
6062
|
+
});
|
|
6063
|
+
if (this.mediaUploaderAuthorizePredicate == null && !this.#mediaUploaderNoAuthWarned) {
|
|
6064
|
+
this.#mediaUploaderNoAuthWarned = true;
|
|
6065
|
+
(0, _logtape_logtape.getLogger)([
|
|
6066
|
+
"fedify",
|
|
6067
|
+
"federation",
|
|
6068
|
+
"mediaUploader"
|
|
6069
|
+
]).warn("The media uploader is registered without an authorize() hook, so it accepts uploads from anyone who can reach the endpoint. Protect it with .authorize() unless a public upload endpoint is intended.");
|
|
6070
|
+
}
|
|
6071
|
+
return await handleMediaUpload(request, {
|
|
6072
|
+
identifier: route.values.identifier,
|
|
6073
|
+
context,
|
|
6074
|
+
mediaUploaderCallback: this.mediaUploaderCallback,
|
|
6075
|
+
actorDispatcher: this.actorCallbacks?.dispatcher,
|
|
6076
|
+
authorizePredicate: this.mediaUploaderAuthorizePredicate,
|
|
6077
|
+
isRegisteredObjectUri: (uri) => context.parseUri(uri)?.type === "object",
|
|
6078
|
+
onUnauthorized,
|
|
6079
|
+
onNotFound
|
|
6080
|
+
});
|
|
5845
6081
|
}
|
|
5846
6082
|
if (request.method !== "POST" && !acceptsJsonLd(request)) {
|
|
5847
6083
|
metricState.endpoint = "not_acceptable";
|
|
@@ -6076,6 +6312,7 @@ function getEndpointCategory(routeName) {
|
|
|
6076
6312
|
case "inbox": return "inbox";
|
|
6077
6313
|
case "sharedInbox": return "shared_inbox";
|
|
6078
6314
|
case "outbox": return "outbox";
|
|
6315
|
+
case "mediaUploader": return "media_upload";
|
|
6079
6316
|
case "following": return "following";
|
|
6080
6317
|
case "followers": return "followers";
|
|
6081
6318
|
case "liked": return "liked";
|
|
@@ -6209,6 +6446,11 @@ var ContextImpl = class ContextImpl {
|
|
|
6209
6446
|
if (path == null) throw new _fedify_uri_template.RouterError("No outbox dispatcher registered.");
|
|
6210
6447
|
return new URL(path, this.canonicalOrigin);
|
|
6211
6448
|
}
|
|
6449
|
+
getMediaUploaderUri(identifier) {
|
|
6450
|
+
const path = this.federation.router.build("mediaUploader", { identifier });
|
|
6451
|
+
if (path == null) throw new _fedify_uri_template.RouterError("No media uploader registered.");
|
|
6452
|
+
return new URL(path, this.canonicalOrigin);
|
|
6453
|
+
}
|
|
6212
6454
|
getInboxUri(identifier) {
|
|
6213
6455
|
if (identifier == null) {
|
|
6214
6456
|
const path = this.federation.router.build("sharedInbox", {});
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, n as getDurationMs, o as isAbortError, r as getFederationMetrics, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "./metrics-
|
|
4
|
+
import { n as version, t as name } from "./deno-C30u61BX.mjs";
|
|
5
|
+
import { a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, n as getDurationMs, o as isAbortError, r as getFederationMetrics, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "./metrics-De7b7Hgb.mjs";
|
|
6
6
|
import { t as formatAcceptSignature } from "./accept-8PiolDP7.mjs";
|
|
7
|
-
import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-
|
|
8
|
-
import { l as verifyRequest, o as parseRfc9421SignatureInput, u as verifyRequestDetailed } from "./http-
|
|
9
|
-
import { t as getAuthenticatedDocumentLoader } from "./docloader-
|
|
10
|
-
import { n as kvCache } from "./kv-cache-
|
|
11
|
-
import { _ as wrapContextLoaderForJsonLd, a as compactJsonLd, c as getNormalizationContextLoader, d as isClearlyMalformedContextReference, f as isInvalidUrlTypeError, l as hasSignature, m as verifyCompactJsonLd, p as signJsonLd, r as assertSafeJsonLd, s as detachSignature, t as InvalidContextReferenceError, u as hasSignatureLike } from "./ld-
|
|
12
|
-
import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-
|
|
7
|
+
import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-C1tsoBAW.mjs";
|
|
8
|
+
import { l as verifyRequest, o as parseRfc9421SignatureInput, u as verifyRequestDetailed } from "./http-DJEaNMSB.mjs";
|
|
9
|
+
import { t as getAuthenticatedDocumentLoader } from "./docloader-C8JfZ3bD.mjs";
|
|
10
|
+
import { n as kvCache } from "./kv-cache-D9Tia3Td.mjs";
|
|
11
|
+
import { _ as wrapContextLoaderForJsonLd, a as compactJsonLd, c as getNormalizationContextLoader, d as isClearlyMalformedContextReference, f as isInvalidUrlTypeError, l as hasSignature, m as verifyCompactJsonLd, p as signJsonLd, r as assertSafeJsonLd, s as detachSignature, t as InvalidContextReferenceError, u as hasSignatureLike } from "./ld-CDBNQmZD.mjs";
|
|
12
|
+
import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-CB3dPva0.mjs";
|
|
13
13
|
import { r as normalizeOutgoingActivityJsonLd } from "./outgoing-jsonld-URuqsICz.mjs";
|
|
14
|
-
import { i as verifyObject, n as hasProofLike, r as signObject } from "./proof-
|
|
14
|
+
import { i as verifyObject, n as hasProofLike, r as signObject } from "./proof-BqDtIxGz.mjs";
|
|
15
15
|
import { t as getNodeInfo } from "./client-CjF5IYQS.mjs";
|
|
16
16
|
import { t as nodeInfoToJson } from "./types-CrtdVuDP.mjs";
|
|
17
|
-
import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "./send-
|
|
18
|
-
import { n as FederationBuilderImpl, t as ACTOR_ALIAS_PREFIX } from "./builder-
|
|
17
|
+
import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "./send-ClWims8x.mjs";
|
|
18
|
+
import { n as FederationBuilderImpl, t as ACTOR_ALIAS_PREFIX } from "./builder-DYAAegyy.mjs";
|
|
19
19
|
import { t as CircuitBreaker } from "./circuit-breaker-CBGyz5F7.mjs";
|
|
20
20
|
import { t as buildCollectionSynchronizationHeader } from "./collection-BIhlldqK.mjs";
|
|
21
21
|
import { t as KvKeyCache } from "./keycache-_DHqz5z_.mjs";
|
|
22
22
|
import { t as acceptsJsonLd } from "./negotiation-RuwrPFqi.mjs";
|
|
23
|
-
import { t as hasMalformedKnownTemporalLiteral } from "./temporal-
|
|
23
|
+
import { t as hasMalformedKnownTemporalLiteral } from "./temporal-DyITEDcU.mjs";
|
|
24
24
|
import { t as createExponentialBackoffPolicy } from "./retry-DgFqeS5k.mjs";
|
|
25
25
|
import { t as TaskCodec } from "./codec-BBga-FWI.mjs";
|
|
26
26
|
import { n as ParallelMessageQueue } from "./mq-llHKivST.mjs";
|
|
@@ -1025,6 +1025,193 @@ async function handleOutbox(request, { identifier, context: ctx, outboxContextFa
|
|
|
1025
1025
|
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
1026
1026
|
});
|
|
1027
1027
|
}
|
|
1028
|
+
const plainTextHeaders = { "Content-Type": "text/plain; charset=utf-8" };
|
|
1029
|
+
/**
|
|
1030
|
+
* Handles a media upload request (the [ActivityPub Media Upload
|
|
1031
|
+
* extension](https://www.w3.org/wiki/SocialCG/ActivityPub/MediaUpload)).
|
|
1032
|
+
* @template TContextData The context data to pass to the context.
|
|
1033
|
+
* @param request The HTTP request.
|
|
1034
|
+
* @param parameters The parameters for handling the request.
|
|
1035
|
+
* @returns A promise that resolves to an HTTP response.
|
|
1036
|
+
* @since 2.4.0
|
|
1037
|
+
*/
|
|
1038
|
+
async function handleMediaUpload(request, { identifier, context: ctx, mediaUploaderCallback, actorDispatcher, authorizePredicate, isRegisteredObjectUri, onUnauthorized, onNotFound }) {
|
|
1039
|
+
const logger = getLogger([
|
|
1040
|
+
"fedify",
|
|
1041
|
+
"federation",
|
|
1042
|
+
"mediaUploader"
|
|
1043
|
+
]);
|
|
1044
|
+
if (request.bodyUsed) {
|
|
1045
|
+
logger.error("Request body has already been read.", { identifier });
|
|
1046
|
+
return new Response("Internal server error.", {
|
|
1047
|
+
status: 500,
|
|
1048
|
+
headers: plainTextHeaders
|
|
1049
|
+
});
|
|
1050
|
+
} else if (request.body?.locked) {
|
|
1051
|
+
logger.error("Request body is locked.", { identifier });
|
|
1052
|
+
return new Response("Internal server error.", {
|
|
1053
|
+
status: 500,
|
|
1054
|
+
headers: plainTextHeaders
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
const contentType = request.headers.get("content-type");
|
|
1058
|
+
if (contentType == null || !contentType.toLowerCase().startsWith("multipart/form-data")) {
|
|
1059
|
+
logger.error("The media upload request is not multipart/form-data (got {contentType}).", {
|
|
1060
|
+
identifier,
|
|
1061
|
+
contentType
|
|
1062
|
+
});
|
|
1063
|
+
return new Response("Unsupported media type.", {
|
|
1064
|
+
status: 415,
|
|
1065
|
+
headers: plainTextHeaders
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
if (actorDispatcher == null) {
|
|
1069
|
+
logger.error("Actor dispatcher is not set.", { identifier });
|
|
1070
|
+
return await onNotFound(request);
|
|
1071
|
+
}
|
|
1072
|
+
const actor = await actorDispatcher(ctx, identifier);
|
|
1073
|
+
if (actor == null || actor instanceof Tombstone) {
|
|
1074
|
+
logger.error("Actor {identifier} not found.", { identifier });
|
|
1075
|
+
return await onNotFound(request);
|
|
1076
|
+
}
|
|
1077
|
+
if (authorizePredicate != null) {
|
|
1078
|
+
let body;
|
|
1079
|
+
try {
|
|
1080
|
+
body = await request.arrayBuffer();
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
logger.error("Failed to read the multipart/form-data body:\n{error}", {
|
|
1083
|
+
identifier,
|
|
1084
|
+
error
|
|
1085
|
+
});
|
|
1086
|
+
return new Response("Invalid multipart/form-data body.", {
|
|
1087
|
+
status: 400,
|
|
1088
|
+
headers: plainTextHeaders
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
const rebuild = () => new Request(request.url, {
|
|
1092
|
+
method: request.method,
|
|
1093
|
+
headers: request.headers,
|
|
1094
|
+
body: body.byteLength > 0 ? body : void 0
|
|
1095
|
+
});
|
|
1096
|
+
const authorizeContext = ctx.clone(ctx.data);
|
|
1097
|
+
authorizeContext.request = rebuild();
|
|
1098
|
+
if (!await authorizePredicate(authorizeContext, identifier)) return await onUnauthorized(rebuild());
|
|
1099
|
+
request = rebuild();
|
|
1100
|
+
}
|
|
1101
|
+
let form;
|
|
1102
|
+
try {
|
|
1103
|
+
form = await request.formData();
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
logger.error("Failed to parse the multipart/form-data body:\n{error}", {
|
|
1106
|
+
identifier,
|
|
1107
|
+
error
|
|
1108
|
+
});
|
|
1109
|
+
return new Response("Invalid multipart/form-data body.", {
|
|
1110
|
+
status: 400,
|
|
1111
|
+
headers: plainTextHeaders
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
const file = form.get("file");
|
|
1115
|
+
if (!(file instanceof File)) {
|
|
1116
|
+
logger.error("The media upload request has no file field.", { identifier });
|
|
1117
|
+
return new Response("Missing file field.", {
|
|
1118
|
+
status: 400,
|
|
1119
|
+
headers: plainTextHeaders
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
const objectField = form.get("object");
|
|
1123
|
+
if (objectField == null) {
|
|
1124
|
+
logger.error("The media upload request has no object field.", { identifier });
|
|
1125
|
+
return new Response("Missing object field.", {
|
|
1126
|
+
status: 400,
|
|
1127
|
+
headers: plainTextHeaders
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
let object;
|
|
1131
|
+
try {
|
|
1132
|
+
const objectText = typeof objectField === "string" ? objectField : await objectField.text();
|
|
1133
|
+
object = await Object$1.fromJsonLd(JSON.parse(objectText), ctx);
|
|
1134
|
+
} catch (error) {
|
|
1135
|
+
logger.error("Failed to parse the object field:\n{error}", {
|
|
1136
|
+
identifier,
|
|
1137
|
+
error
|
|
1138
|
+
});
|
|
1139
|
+
return new Response("Invalid object field.", {
|
|
1140
|
+
status: 400,
|
|
1141
|
+
headers: plainTextHeaders
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
let result;
|
|
1145
|
+
try {
|
|
1146
|
+
result = await mediaUploaderCallback(ctx, identifier, file, object);
|
|
1147
|
+
} catch (error) {
|
|
1148
|
+
logger.error("Failed to process the media upload:\n{error}", {
|
|
1149
|
+
identifier,
|
|
1150
|
+
error
|
|
1151
|
+
});
|
|
1152
|
+
return new Response("Internal server error.", {
|
|
1153
|
+
status: 500,
|
|
1154
|
+
headers: plainTextHeaders
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
if (result == null) {
|
|
1158
|
+
logger.error("The media uploader callback for {identifier} returned null or undefined; it must return an object (201 Created) or a URL (202 Accepted).", { identifier });
|
|
1159
|
+
return new Response("Internal server error.", {
|
|
1160
|
+
status: 500,
|
|
1161
|
+
headers: plainTextHeaders
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
const warnUnlessRegistered = (target) => {
|
|
1165
|
+
if (isRegisteredObjectUri(target)) return;
|
|
1166
|
+
logger.warn("The media uploader callback for {identifier} returned {target}, which does not point at a registered object dispatcher route; derive the returned id/URL from Context.getObjectUri(). The upload still succeeded.", {
|
|
1167
|
+
identifier,
|
|
1168
|
+
target: target.href
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
if (result instanceof URL) {
|
|
1172
|
+
warnUnlessRegistered(result);
|
|
1173
|
+
logger.info("The media upload for {identifier} is still being processed; responding 202 Accepted.", {
|
|
1174
|
+
identifier,
|
|
1175
|
+
location: result.href
|
|
1176
|
+
});
|
|
1177
|
+
return new Response(null, {
|
|
1178
|
+
status: 202,
|
|
1179
|
+
headers: { Location: result.href }
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
if (result.id == null) {
|
|
1183
|
+
logger.error("The media uploader callback for {identifier} returned an object without an id, so a 201 Created response cannot include the required Location header. Set the object's id with Context.getObjectUri(), or return the eventual URL to respond 202 Accepted instead.", { identifier });
|
|
1184
|
+
return new Response("Internal server error.", {
|
|
1185
|
+
status: 500,
|
|
1186
|
+
headers: plainTextHeaders
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
warnUnlessRegistered(result.id);
|
|
1190
|
+
let jsonLd;
|
|
1191
|
+
try {
|
|
1192
|
+
jsonLd = await result.toJsonLd(ctx);
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
logger.error("Failed to serialize the uploaded object to JSON-LD:\n{error}", {
|
|
1195
|
+
identifier,
|
|
1196
|
+
error
|
|
1197
|
+
});
|
|
1198
|
+
return new Response("Internal server error.", {
|
|
1199
|
+
status: 500,
|
|
1200
|
+
headers: plainTextHeaders
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
logger.info("The media upload for {identifier} is ready; responding 201 Created.", {
|
|
1204
|
+
identifier,
|
|
1205
|
+
location: result.id.href
|
|
1206
|
+
});
|
|
1207
|
+
return new Response(JSON.stringify(jsonLd), {
|
|
1208
|
+
status: 201,
|
|
1209
|
+
headers: {
|
|
1210
|
+
"Content-Type": "application/activity+json",
|
|
1211
|
+
Location: result.id.href
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1028
1215
|
/**
|
|
1029
1216
|
* Handles an inbox request for ActivityPub activities.
|
|
1030
1217
|
* @template TContextData The context data to pass to the context.
|
|
@@ -2641,6 +2828,7 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
2641
2828
|
benchmarkMode;
|
|
2642
2829
|
benchmarkMetricReader;
|
|
2643
2830
|
benchmarkTriggerOptions;
|
|
2831
|
+
#mediaUploaderNoAuthWarned = false;
|
|
2644
2832
|
#queueDepthGaugeSourceId = `fedify-${(++nextQueueDepthGaugeSourceId).toString(36)}`;
|
|
2645
2833
|
#queueDepthGaugeEntries = [];
|
|
2646
2834
|
#queueDepthGaugeMeterProvider;
|
|
@@ -3956,6 +4144,32 @@ var FederationImpl = class extends FederationBuilderImpl {
|
|
|
3956
4144
|
});
|
|
3957
4145
|
case "benchmarkStats": return await handleBenchmarkStats(request, this.benchmarkMetricReader);
|
|
3958
4146
|
case "benchmarkTrigger": return await handleBenchmarkTrigger(request, context, this.benchmarkTriggerOptions);
|
|
4147
|
+
case "mediaUploader":
|
|
4148
|
+
if (request.method !== "POST" || this.mediaUploaderCallback == null) return new Response("Method not allowed.", {
|
|
4149
|
+
status: 405,
|
|
4150
|
+
headers: {
|
|
4151
|
+
Allow: "POST",
|
|
4152
|
+
"Content-Type": "text/plain; charset=utf-8"
|
|
4153
|
+
}
|
|
4154
|
+
});
|
|
4155
|
+
if (this.mediaUploaderAuthorizePredicate == null && !this.#mediaUploaderNoAuthWarned) {
|
|
4156
|
+
this.#mediaUploaderNoAuthWarned = true;
|
|
4157
|
+
getLogger([
|
|
4158
|
+
"fedify",
|
|
4159
|
+
"federation",
|
|
4160
|
+
"mediaUploader"
|
|
4161
|
+
]).warn("The media uploader is registered without an authorize() hook, so it accepts uploads from anyone who can reach the endpoint. Protect it with .authorize() unless a public upload endpoint is intended.");
|
|
4162
|
+
}
|
|
4163
|
+
return await handleMediaUpload(request, {
|
|
4164
|
+
identifier: route.values.identifier,
|
|
4165
|
+
context,
|
|
4166
|
+
mediaUploaderCallback: this.mediaUploaderCallback,
|
|
4167
|
+
actorDispatcher: this.actorCallbacks?.dispatcher,
|
|
4168
|
+
authorizePredicate: this.mediaUploaderAuthorizePredicate,
|
|
4169
|
+
isRegisteredObjectUri: (uri) => context.parseUri(uri)?.type === "object",
|
|
4170
|
+
onUnauthorized,
|
|
4171
|
+
onNotFound
|
|
4172
|
+
});
|
|
3959
4173
|
}
|
|
3960
4174
|
if (request.method !== "POST" && !acceptsJsonLd(request)) {
|
|
3961
4175
|
metricState.endpoint = "not_acceptable";
|
|
@@ -4190,6 +4404,7 @@ function getEndpointCategory(routeName) {
|
|
|
4190
4404
|
case "inbox": return "inbox";
|
|
4191
4405
|
case "sharedInbox": return "shared_inbox";
|
|
4192
4406
|
case "outbox": return "outbox";
|
|
4407
|
+
case "mediaUploader": return "media_upload";
|
|
4193
4408
|
case "following": return "following";
|
|
4194
4409
|
case "followers": return "followers";
|
|
4195
4410
|
case "liked": return "liked";
|
|
@@ -4323,6 +4538,11 @@ var ContextImpl = class ContextImpl {
|
|
|
4323
4538
|
if (path == null) throw new RouterError("No outbox dispatcher registered.");
|
|
4324
4539
|
return new URL(path, this.canonicalOrigin);
|
|
4325
4540
|
}
|
|
4541
|
+
getMediaUploaderUri(identifier) {
|
|
4542
|
+
const path = this.federation.router.build("mediaUploader", { identifier });
|
|
4543
|
+
if (path == null) throw new RouterError("No media uploader registered.");
|
|
4544
|
+
return new URL(path, this.canonicalOrigin);
|
|
4545
|
+
}
|
|
4326
4546
|
getInboxUri(identifier) {
|
|
4327
4547
|
if (identifier == null) {
|
|
4328
4548
|
const path = this.federation.router.build("sharedInbox", {});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import {
|
|
2
|
+
import { Mt as WebFingerLinksDispatcher, ct as ActorAliasMapper, l as RequestContext, lt as ActorDispatcher, ut as ActorHandleMapper } from "./context-Zii1f5xS.js";
|
|
3
3
|
import { RouterError, RouterOptions, RouterRouteResult } from "@fedify/uri-template";
|
|
4
4
|
import { MeterProvider, Span, Tracer } from "@opentelemetry/api";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import {
|
|
2
|
+
import { Mt as WebFingerLinksDispatcher, ct as ActorAliasMapper, l as RequestContext, lt as ActorDispatcher, ut as ActorHandleMapper } from "./context-lxX6I7as.cjs";
|
|
3
3
|
import { MeterProvider, Span, Tracer } from "@opentelemetry/api";
|
|
4
4
|
import { RouterError, RouterOptions, RouterRouteResult } from "@fedify/uri-template";
|
|
5
5
|
|
package/dist/mod.cjs
CHANGED
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
require("./chunk-Czpeue4M.cjs");
|
|
4
4
|
const require_transformers = require("./transformers-DGwl-hD1.cjs");
|
|
5
5
|
require("./compat/mod.cjs");
|
|
6
|
-
const require_http = require("./http-
|
|
7
|
-
const require_middleware = require("./middleware-
|
|
8
|
-
const require_proof = require("./proof-
|
|
6
|
+
const require_http = require("./http-DiMJDFtd.cjs");
|
|
7
|
+
const require_middleware = require("./middleware-BPHpdYl4.cjs");
|
|
8
|
+
const require_proof = require("./proof-BI4Wn6Ur.cjs");
|
|
9
9
|
const require_types = require("./types-CPym83zc.cjs");
|
|
10
|
-
const require_kv_cache = require("./kv-cache-
|
|
10
|
+
const require_kv_cache = require("./kv-cache-BInLi0Ro.cjs");
|
|
11
11
|
const require_federation_mod = require("./federation/mod.cjs");
|
|
12
12
|
require("./nodeinfo/mod.cjs");
|
|
13
13
|
require("./runtime/mod.cjs");
|