fedimbed: set headers if posting
This commit is contained in:
		
							parent
							
								
									f96ee62da7
								
							
						
					
					
						commit
						5851a5a51d
					
				
					 1 changed files with 10 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -118,6 +118,7 @@ async function processUrl(msg, url) {
 | 
			
		|||
 | 
			
		||||
    let redirUrl;
 | 
			
		||||
    const options = {};
 | 
			
		||||
    const headers = {};
 | 
			
		||||
    if (PATH_REGEX.pleroma2.test(urlObj.pathname)) {
 | 
			
		||||
      redirUrl = url.replace("notice", "api/v1/statuses");
 | 
			
		||||
    } else if (PATH_REGEX.mastodon.test(urlObj.pathname)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -130,6 +131,7 @@ async function processUrl(msg, url) {
 | 
			
		|||
      redirUrl = urlObj.origin + "/api/notes/show/";
 | 
			
		||||
      options.method = "POST";
 | 
			
		||||
      options.body = JSON.stringify({noteId});
 | 
			
		||||
      headers["Content-Type"] = "application/json";
 | 
			
		||||
    } else {
 | 
			
		||||
      logger.error(
 | 
			
		||||
        "fedimbed",
 | 
			
		||||
| 
						 | 
				
			
			@ -141,14 +143,11 @@ async function processUrl(msg, url) {
 | 
			
		|||
      logger.verbose("fedimbed", `Redirecting "${url}" to "${redirUrl}"`);
 | 
			
		||||
      const rawPostData2 = await fetch(
 | 
			
		||||
        redirUrl,
 | 
			
		||||
        Object.assign(
 | 
			
		||||
          {
 | 
			
		||||
            headers: {
 | 
			
		||||
              "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
            },
 | 
			
		||||
          },
 | 
			
		||||
          options
 | 
			
		||||
        )
 | 
			
		||||
        Object.assign(options, {
 | 
			
		||||
          headers: Object.assign(headers, {
 | 
			
		||||
            "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
          }),
 | 
			
		||||
        })
 | 
			
		||||
      )
 | 
			
		||||
        .then((res) => res.text())
 | 
			
		||||
        .catch((err) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +175,9 @@ async function processUrl(msg, url) {
 | 
			
		|||
      } else if (postData2.error) {
 | 
			
		||||
        logger.error(
 | 
			
		||||
          "fedimbed",
 | 
			
		||||
          `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${JSON.stringify(postData2.error)}`
 | 
			
		||||
          `Bailing trying to re-embed "${url}", MastoAPI gave us error: ${JSON.stringify(
 | 
			
		||||
            postData2.error
 | 
			
		||||
          )}`
 | 
			
		||||
        );
 | 
			
		||||
      } else {
 | 
			
		||||
        cw =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue