fedimbed: add AFM fallback to mastodon
This commit is contained in:
		
							parent
							
								
									70f8d71593
								
							
						
					
					
						commit
						c689c7c5d5
					
				
					 1 changed files with 17 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -97,7 +97,7 @@ async function processUrl(msg, url) {
 | 
			
		|||
 | 
			
		||||
  if (!postData) {
 | 
			
		||||
    // We failed to get post.
 | 
			
		||||
    // If we're fetching from Pleroma, assume it was due to AMF and use MastoAPI
 | 
			
		||||
    // If we're fetching from Pleroma, assume it was due to AFM and use MastoAPI
 | 
			
		||||
    if (PATH_REGEX.pleroma.test(urlObj.pathname)) {
 | 
			
		||||
      url = await fetch(url, {
 | 
			
		||||
        method: "HEAD",
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +112,19 @@ async function processUrl(msg, url) {
 | 
			
		|||
      urlObj = new URL(url);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let redirUrl;
 | 
			
		||||
    if (PATH_REGEX.pleroma2.test(urlObj.pathname)) {
 | 
			
		||||
      redirUrl = url.replace("notice", "api/v1/statuses");
 | 
			
		||||
    } else if (PATH_REGEX.mastodon.test(urlObj.pathName)) {
 | 
			
		||||
      redirUrl = url.replace(/@(.+?)\//, "api/v1/statuses/");
 | 
			
		||||
    } else {
 | 
			
		||||
      logger.error(
 | 
			
		||||
        "fedimbed",
 | 
			
		||||
        `Missing MastoAPI replacement for "${platform}"`
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (redirUrl) {
 | 
			
		||||
      const postData2 = await fetch(url.replace("notice", "api/v1/statuses"), {
 | 
			
		||||
        headers: {
 | 
			
		||||
          "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -132,7 +144,10 @@ async function processUrl(msg, url) {
 | 
			
		|||
          `Bailing trying to re-embed "${url}": Failed to get post from both AS2 and MastoAPI.`
 | 
			
		||||
        );
 | 
			
		||||
      } else if (postData2.error) {
 | 
			
		||||
        logger.error("fedimbed", `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`);
 | 
			
		||||
        logger.error(
 | 
			
		||||
          "fedimbed",
 | 
			
		||||
          `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${postData2.error}`
 | 
			
		||||
        );
 | 
			
		||||
      } else {
 | 
			
		||||
        cw = postData2.spoiler_warning;
 | 
			
		||||
        content =
 | 
			
		||||
| 
						 | 
				
			
			@ -153,11 +168,6 @@ async function processUrl(msg, url) {
 | 
			
		|||
          });
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      logger.error(
 | 
			
		||||
        "fedimbed",
 | 
			
		||||
        `Redirect from /object did not give us /notice. (${urlObj.pathname})`
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    content = postData.content;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue