fedimbed: fixes for mastodon redir
This commit is contained in:
		
							parent
							
								
									ce90b0ca86
								
							
						
					
					
						commit
						7087a9bae5
					
				
					 1 changed files with 19 additions and 19 deletions
				
			
		| 
						 | 
					@ -131,14 +131,11 @@ async function processUrl(msg, url) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (redirUrl) {
 | 
					    if (redirUrl) {
 | 
				
			||||||
      logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`);
 | 
					      logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`);
 | 
				
			||||||
      const rawPostData2 = await fetch(
 | 
					      const rawPostData2 = await fetch(redirUrl, {
 | 
				
			||||||
        redirUrl,
 | 
					        headers: {
 | 
				
			||||||
        {
 | 
					          "User-Agent": FRIENDLY_USERAGENT,
 | 
				
			||||||
          headers: {
 | 
					        },
 | 
				
			||||||
            "User-Agent": FRIENDLY_USERAGENT,
 | 
					      })
 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
        .then((res) => res.text())
 | 
					        .then((res) => res.text())
 | 
				
			||||||
        .catch((err) => {
 | 
					        .catch((err) => {
 | 
				
			||||||
          logger.error(
 | 
					          logger.error(
 | 
				
			||||||
| 
						 | 
					@ -151,7 +148,10 @@ async function processUrl(msg, url) {
 | 
				
			||||||
      if (rawPostData2.startsWith("{")) {
 | 
					      if (rawPostData2.startsWith("{")) {
 | 
				
			||||||
        postData2 = JSON.parse(rawPostData2);
 | 
					        postData2 = JSON.parse(rawPostData2);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        logger.warn("fedimbed", `Got non-JSON for "${url}" as MastoAPI: ${rawPostData2}`);
 | 
					        logger.warn(
 | 
				
			||||||
 | 
					          "fedimbed",
 | 
				
			||||||
 | 
					          `Got non-JSON for "${url}" as MastoAPI: ${rawPostData2}`
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!postData2) {
 | 
					      if (!postData2) {
 | 
				
			||||||
| 
						 | 
					@ -165,14 +165,14 @@ async function processUrl(msg, url) {
 | 
				
			||||||
          `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`
 | 
					          `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        cw = postData2.spoiler_warning;
 | 
					        cw = postData2.spoiler_warning ?? postData2.spoiler_text;
 | 
				
			||||||
        content =
 | 
					        content =
 | 
				
			||||||
          postData2.akkoma?.source?.content ??
 | 
					          postData2.akkoma?.source?.content ??
 | 
				
			||||||
          postData2.pleroma?.content?.["text/plain"] ??
 | 
					          postData2.pleroma?.content?.["text/plain"] ??
 | 
				
			||||||
          postData2.content;
 | 
					          postData2.content;
 | 
				
			||||||
        author = {
 | 
					        author = {
 | 
				
			||||||
          name: postData2.account.display_name,
 | 
					          name: postData2.account.display_name,
 | 
				
			||||||
          handle: postData2.account.fqn,
 | 
					          handle: postData2.account.fqn ?? `${postData2.account.username}@${urlObj.hostname}`,
 | 
				
			||||||
          url: postData2.account.url,
 | 
					          url: postData2.account.url,
 | 
				
			||||||
          avatar: postData2.account.avatar,
 | 
					          avatar: postData2.account.avatar,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
| 
						 | 
					@ -289,13 +289,13 @@ async function processUrl(msg, url) {
 | 
				
			||||||
  const embeds = [];
 | 
					  const embeds = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (attachments.length > 0) {
 | 
					  if (attachments.length > 0) {
 | 
				
			||||||
  for (const attachment of attachments) {
 | 
					    for (const attachment of attachments) {
 | 
				
			||||||
    const embed = Object.assign({}, baseEmbed);
 | 
					      const embed = Object.assign({}, baseEmbed);
 | 
				
			||||||
    embed.image = {
 | 
					      embed.image = {
 | 
				
			||||||
      url: attachment.url,
 | 
					        url: attachment.url,
 | 
				
			||||||
    };
 | 
					      };
 | 
				
			||||||
    embeds.push(embed);
 | 
					      embeds.push(embed);
 | 
				
			||||||
  }
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    embeds.push(baseEmbed);
 | 
					    embeds.push(baseEmbed);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -313,7 +313,7 @@ async function processUrl(msg, url) {
 | 
				
			||||||
    .catch(() => {});
 | 
					    .catch(() => {});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  await msg.channel.createMessage({
 | 
					  await msg.channel.createMessage({
 | 
				
			||||||
    content: cw && attachments.length > 0 ? ":warning: " + cw + " || ||": "",
 | 
					    content: cw && attachments.length > 0 ? ":warning: " + cw + " || ||" : "",
 | 
				
			||||||
    embeds,
 | 
					    embeds,
 | 
				
			||||||
    allowedMentions: {
 | 
					    allowedMentions: {
 | 
				
			||||||
      repliedUser: false,
 | 
					      repliedUser: false,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue