fedimbed: attempt to fix images
This commit is contained in:
		
							parent
							
								
									fd98ba3667
								
							
						
					
					
						commit
						6f8596a55f
					
				
					 1 changed files with 13 additions and 16 deletions
				
			
		| 
						 | 
					@ -1062,20 +1062,21 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
				
			||||||
      for (const attachment of attachments) {
 | 
					      for (const attachment of attachments) {
 | 
				
			||||||
        const type = attachment.type?.toLowerCase();
 | 
					        const type = attachment.type?.toLowerCase();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const attDesc = attachment.description ?? attachment.comment;
 | 
				
			||||||
        if (type.startsWith("image")) {
 | 
					        if (type.startsWith("image")) {
 | 
				
			||||||
          images.push({
 | 
					          images.push({
 | 
				
			||||||
            media: {url: attachment.url},
 | 
					            media: {url: attachment.url},
 | 
				
			||||||
            description: attachment.description ?? attachment.comment,
 | 
					            description: attDesc?.length > 0 ? attDesc : null,
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        } else if (type.startsWith("video")) {
 | 
					        } else if (type.startsWith("video")) {
 | 
				
			||||||
          videos.push({
 | 
					          videos.push({
 | 
				
			||||||
            media: {url: attachment.url},
 | 
					            media: {url: attachment.url},
 | 
				
			||||||
            description: attachment.description ?? attachment.comment,
 | 
					            description: attDesc?.length > 0 ? attDesc : null,
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        } else if (type.startsWith("audio")) {
 | 
					        } else if (type.startsWith("audio")) {
 | 
				
			||||||
          audios.push({
 | 
					          audios.push({
 | 
				
			||||||
            url: attachment.url,
 | 
					            url: attachment.url,
 | 
				
			||||||
            description: attachment.description ?? attachment.comment,
 | 
					            description: attDesc?.length > 0 ? attDesc : null,
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -1142,7 +1143,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
            .then((res) => res.json())
 | 
					            .then((res) => res.json())
 | 
				
			||||||
            .catch((err) => {
 | 
					            .catch((err) => {
 | 
				
			||||||
              /*if (platform !== "cohost")*/ logger.error("fedimbed", `Failed to get author for "${url}": ${err}`);
 | 
					              logger.error("fedimbed", `Failed to get author for "${url}": ${err}`);
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (authorData) {
 | 
					          if (authorData) {
 | 
				
			||||||
| 
						 | 
					@ -1186,20 +1187,21 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          const attDesc = attachment.name ?? attachment.description ?? attachment.comment;
 | 
				
			||||||
          if (type.startsWith("image")) {
 | 
					          if (type.startsWith("image")) {
 | 
				
			||||||
            images.push({
 | 
					            images.push({
 | 
				
			||||||
              media: {url: attUrl},
 | 
					              media: {url: attUrl},
 | 
				
			||||||
              description: attachment.name ?? attachment.description ?? attachment.comment,
 | 
					              description: attDesc?.length > 0 ? attDesc : null,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
          } else if (type.startsWith("video")) {
 | 
					          } else if (type.startsWith("video")) {
 | 
				
			||||||
            videos.push({
 | 
					            videos.push({
 | 
				
			||||||
              media: {url: attUrl},
 | 
					              media: {url: attUrl},
 | 
				
			||||||
              description: attachment.name ?? attachment.description ?? attachment.comment,
 | 
					              description: attDesc?.length > 0 ? attDesc : null,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
          } else if (type.startsWith("audio")) {
 | 
					          } else if (type.startsWith("audio")) {
 | 
				
			||||||
            audios.push({
 | 
					            audios.push({
 | 
				
			||||||
              url: attUrl,
 | 
					              url: attUrl,
 | 
				
			||||||
              description: attachment.name ?? attachment.description ?? attachment.comment,
 | 
					              description: attDesc?.length > 0 ? attDesc : null,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
| 
						 | 
					@ -1403,10 +1405,10 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return `> **${o.name}** (${numberFormatter.format(o.count)}, ${Math.round(
 | 
					            return `> **${o.name}** (${numberFormatter.format(o.count)}, ${Math.round(
 | 
				
			||||||
              percent * 100
 | 
					              percent * 100
 | 
				
			||||||
            )}%)> \n\`${"\u2588".repeat(bar)}${" ".repeat(32 - bar)}\``;
 | 
					            )}%\n> \`${"\u2588".repeat(bar)}${" ".repeat(32 - bar)}\``;
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
          .join("> \n> \n") +
 | 
					          .join("\n> \n> ") +
 | 
				
			||||||
        `> \n> \n${poll.total} votes \u2022 End${pollTime > now ? "s" : "ed"} <t:${Math.floor(pollTime / 1000)}:R>`,
 | 
					        `\n> \n> ${poll.total} votes \u2022 End${pollTime > now ? "s" : "ed"} <t:${Math.floor(pollTime / 1000)}:R>`,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1425,11 +1427,6 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
				
			||||||
      url,
 | 
					      url,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					 | 
				
			||||||
  for (const image in images) {
 | 
					 | 
				
			||||||
    if (image.description?.length === 0) image.description = null;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (images.length > 0) {
 | 
					  if (images.length > 0) {
 | 
				
			||||||
    if (images.length > 10) {
 | 
					    if (images.length > 10) {
 | 
				
			||||||
      while (images.length > 10) {
 | 
					      while (images.length > 10) {
 | 
				
			||||||
| 
						 | 
					@ -1491,7 +1488,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    response: {
 | 
					    response: {
 | 
				
			||||||
      flags: 1 << 15,
 | 
					      flags: 1 << 15,
 | 
				
			||||||
      components: [cw.length > 0 ? warningText : false, container].filter((x) => !!x),
 | 
					      components: [cw.length > 0 && warningText, container].filter((x) => !!x),
 | 
				
			||||||
      allowedMentions: {
 | 
					      allowedMentions: {
 | 
				
			||||||
        repliedUser: false,
 | 
					        repliedUser: false,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue