fedimbed: fix attachments for mastoapi
This commit is contained in:
		
							parent
							
								
									4b6ebea322
								
							
						
					
					
						commit
						5ab26c461f
					
				
					 1 changed files with 38 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -182,10 +182,34 @@ async function processUrl(msg, url) {
 | 
			
		|||
        };
 | 
			
		||||
        timestamp = postData2.created_at;
 | 
			
		||||
        for (const attachment of postData2.media_attachments) {
 | 
			
		||||
          attachments.push({
 | 
			
		||||
            url: attachment.url,
 | 
			
		||||
            desc: attachment.description,
 | 
			
		||||
          });
 | 
			
		||||
          const fileType =
 | 
			
		||||
            attachment.pleroma?.mime_type ??
 | 
			
		||||
            attachment.type +
 | 
			
		||||
              (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ??
 | 
			
		||||
              attachment.type == "image"
 | 
			
		||||
                ? "png"
 | 
			
		||||
                : attachment.type == "video"
 | 
			
		||||
                ? "mp4"
 | 
			
		||||
                : "mpeg");
 | 
			
		||||
          if (attachment.type == "image") {
 | 
			
		||||
            images.push({
 | 
			
		||||
              url: attachment.url,
 | 
			
		||||
              desc: attachment.description,
 | 
			
		||||
              type: fileType,
 | 
			
		||||
            });
 | 
			
		||||
          } else if (attachment.type == "video") {
 | 
			
		||||
            videos.push({
 | 
			
		||||
              url: attachment.url,
 | 
			
		||||
              desc: attachment.description,
 | 
			
		||||
              type: fileType,
 | 
			
		||||
            });
 | 
			
		||||
          } else if (attachment.type == "audio") {
 | 
			
		||||
            audios.push({
 | 
			
		||||
              url: attachment.url,
 | 
			
		||||
              desc: attachment.description,
 | 
			
		||||
              type: fileType,
 | 
			
		||||
            });
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -261,7 +285,12 @@ async function processUrl(msg, url) {
 | 
			
		|||
 | 
			
		||||
  let desc = "";
 | 
			
		||||
  let MAX_LENGTH = 3999;
 | 
			
		||||
  if (cw != "" && (images.length == 0 && videos.length == 0 && audios.length == 0)) {
 | 
			
		||||
  if (
 | 
			
		||||
    cw != "" &&
 | 
			
		||||
    images.length == 0 &&
 | 
			
		||||
    videos.length == 0 &&
 | 
			
		||||
    audios.length == 0
 | 
			
		||||
  ) {
 | 
			
		||||
    desc += "\u26a0 " + cw + "\n\n||" + content + "||";
 | 
			
		||||
    MAX_LENGTH -= 8 - cw.length;
 | 
			
		||||
  } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -427,7 +456,10 @@ async function processUrl(msg, url) {
 | 
			
		|||
    .catch(() => {});
 | 
			
		||||
 | 
			
		||||
  await msg.channel.createMessage({
 | 
			
		||||
    content: cw && (images.length > 0 || videos.length > 0 || audios.length > 0) ? `:warning: ${cw} || ${url} ||` : "",
 | 
			
		||||
    content:
 | 
			
		||||
      cw && (images.length > 0 || videos.length > 0 || audios.length > 0)
 | 
			
		||||
        ? `:warning: ${cw} || ${url} ||`
 | 
			
		||||
        : "",
 | 
			
		||||
    embeds,
 | 
			
		||||
    files,
 | 
			
		||||
    allowedMentions: {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue