fix: Mastodon connector loadAsset/openAsset receive the connection
uploadAll/uploadAsset call the media hooks with (connection, assetId) so implementations can resolve the workspace; the registry adapter threads connection.workspaceId into the resolver.
This commit is contained in:
parent
b8115eec09
commit
3e4fb970c3
1 changed files with 6 additions and 6 deletions
|
|
@ -109,10 +109,10 @@ export interface MastodonConnectorOptions {
|
||||||
sleep?: (ms: number) => Promise<void>;
|
sleep?: (ms: number) => Promise<void>;
|
||||||
/** Secret store. Default: in-memory (dev + contract tests). */
|
/** Secret store. Default: in-memory (dev + contract tests). */
|
||||||
credentials?: CredentialAccessor;
|
credentials?: CredentialAccessor;
|
||||||
/** Resolve a media asset id to its metadata (needed by publish with media). */
|
/** Resolve a media asset id to its metadata (needed by publish with media). Receives the connection so implementations can resolve the workspace. */
|
||||||
loadAsset?: (assetId: string) => Promise<MediaAsset>;
|
loadAsset?: (connection: ConnectorConnection, assetId: string) => Promise<MediaAsset>;
|
||||||
/** Read asset bytes for multipart upload (needed by publish/uploadMedia). */
|
/** Read asset bytes for multipart upload (needed by publish/uploadMedia). Receives the connection so implementations can resolve the workspace. */
|
||||||
openAsset?: (media: MediaAsset) => Promise<{ bytes: Uint8Array; filename: string }>;
|
openAsset?: (connection: ConnectorConnection, media: MediaAsset) => Promise<{ bytes: Uint8Array; filename: string }>;
|
||||||
/** client_name shown on the instance's authorized-apps page. */
|
/** client_name shown on the instance's authorized-apps page. */
|
||||||
clientName?: string;
|
clientName?: string;
|
||||||
/** Public website advertised with the registered app. */
|
/** Public website advertised with the registered app. */
|
||||||
|
|
@ -466,7 +466,7 @@ export function createMastodonConnector(options: MastodonConnectorOptions = {}):
|
||||||
if (options.openAsset === undefined) {
|
if (options.openAsset === undefined) {
|
||||||
throw new ConnectorError("media upload needs an openAsset option", PROVIDER);
|
throw new ConnectorError("media upload needs an openAsset option", PROVIDER);
|
||||||
}
|
}
|
||||||
const { bytes, filename } = await options.openAsset(media);
|
const { bytes, filename } = await options.openAsset(connection, media);
|
||||||
const body = new FormData();
|
const body = new FormData();
|
||||||
body.append("file", new Blob([new Uint8Array(bytes)], { type: media.mimeType }), filename);
|
body.append("file", new Blob([new Uint8Array(bytes)], { type: media.mimeType }), filename);
|
||||||
if (description !== undefined) body.append("description", description);
|
if (description !== undefined) body.append("description", description);
|
||||||
|
|
@ -496,7 +496,7 @@ export function createMastodonConnector(options: MastodonConnectorOptions = {}):
|
||||||
}
|
}
|
||||||
const ids: string[] = [];
|
const ids: string[] = [];
|
||||||
for (const assetId of assetIds) {
|
for (const assetId of assetIds) {
|
||||||
const asset = await options.loadAsset(assetId);
|
const asset = await options.loadAsset(connection, assetId);
|
||||||
ids.push((await uploadAsset(connection, asset, str(altText[assetId]))).remoteId);
|
ids.push((await uploadAsset(connection, asset, str(altText[assetId]))).remoteId);
|
||||||
}
|
}
|
||||||
return ids;
|
return ids;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue