Ensure we replace all matches

This commit is contained in:
Half-Shot 2022-09-05 10:40:45 +01:00
parent 73181e1383
commit b0d08e2182

View File

@ -355,6 +355,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection
log.debug(`Media ${uuid} requested but not used`); log.debug(`Media ${uuid} requested but not used`);
continue; continue;
} }
const regExp = new RegExp(uuid, 'g');
try { try {
const content = await axios.get(mediaurl, { const content = await axios.get(mediaurl, {
timeout: GET_MEDIA_TIMEOUT, timeout: GET_MEDIA_TIMEOUT,
@ -363,9 +364,9 @@ export class GenericHookConnection extends BaseConnection implements IConnection
} }
}) })
const mxcUri = await this.as.botClient.uploadContent(content.data, content.headers['content-type']); const mxcUri = await this.as.botClient.uploadContent(content.data, content.headers['content-type']);
plain = plain.replace(uuid, mxcUri); plain = plain.replace(regExp, mxcUri);
if (transformationResult.html) { if (transformationResult.html) {
transformationResult.html = transformationResult.html.replace(transformationResult.html, mxcUri); transformationResult.html = transformationResult.html.replace(regExp, mxcUri);
} }
} catch (ex) { } catch (ex) {
log.warn(`Failed to fetch media for transformation`, {mediaurl}); log.warn(`Failed to fetch media for transformation`, {mediaurl});