mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00:00 
			
		
		
		
	fix mastodon media attachment conversion (resolves #495)
This commit is contained in:
		
							parent
							
								
									1e43162ba7
								
							
						
					
					
						commit
						daf715578e
					
				
					 1 changed files with 38 additions and 7 deletions
				
			
		| 
						 | 
					@ -102,6 +102,10 @@ export class MastoConverters {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public encodeFile(f: Packed<'DriveFile'>): MastodonEntity.Attachment {
 | 
						public encodeFile(f: Packed<'DriveFile'>): MastodonEntity.Attachment {
 | 
				
			||||||
 | 
							const { width, height } = f.properties;
 | 
				
			||||||
 | 
							const size = (width && height) ? `${width}x${height}` : undefined;
 | 
				
			||||||
 | 
							const aspect = (width && height) ? (width / height) : undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return {
 | 
							return {
 | 
				
			||||||
			id: f.id,
 | 
								id: f.id,
 | 
				
			||||||
			type: this.fileType(f.type),
 | 
								type: this.fileType(f.type),
 | 
				
			||||||
| 
						 | 
					@ -110,11 +114,19 @@ export class MastoConverters {
 | 
				
			||||||
			preview_url: f.thumbnailUrl,
 | 
								preview_url: f.thumbnailUrl,
 | 
				
			||||||
			text_url: f.url,
 | 
								text_url: f.url,
 | 
				
			||||||
			meta: {
 | 
								meta: {
 | 
				
			||||||
				width: f.properties.width,
 | 
									original: {
 | 
				
			||||||
				height: f.properties.height,
 | 
										width,
 | 
				
			||||||
 | 
										height,
 | 
				
			||||||
 | 
										size,
 | 
				
			||||||
 | 
										aspect,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									width,
 | 
				
			||||||
 | 
									height,
 | 
				
			||||||
 | 
									size,
 | 
				
			||||||
 | 
									aspect,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			description: f.comment ? f.comment : null,
 | 
								description: f.comment ?? null,
 | 
				
			||||||
			blurhash: f.blurhash ? f.blurhash : null,
 | 
								blurhash: f.blurhash ?? null,
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -295,7 +307,7 @@ export class MastoConverters {
 | 
				
			||||||
			sensitive: status.sensitive,
 | 
								sensitive: status.sensitive,
 | 
				
			||||||
			spoiler_text: note.cw ?? '',
 | 
								spoiler_text: note.cw ?? '',
 | 
				
			||||||
			visibility: status.visibility,
 | 
								visibility: status.visibility,
 | 
				
			||||||
			media_attachments: status.media_attachments,
 | 
								media_attachments: status.media_attachments.map(a => convertAttachment(a)),
 | 
				
			||||||
			mentions: mentions,
 | 
								mentions: mentions,
 | 
				
			||||||
			tags: tags,
 | 
								tags: tags,
 | 
				
			||||||
			card: null, //FIXME
 | 
								card: null, //FIXME
 | 
				
			||||||
| 
						 | 
					@ -342,8 +354,27 @@ export function convertAccount(account: Entity.Account) {
 | 
				
			||||||
export function convertAnnouncement(announcement: Entity.Announcement) {
 | 
					export function convertAnnouncement(announcement: Entity.Announcement) {
 | 
				
			||||||
	return simpleConvert(announcement);
 | 
						return simpleConvert(announcement);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export function convertAttachment(attachment: Entity.Attachment) {
 | 
					export function convertAttachment(attachment: Entity.Attachment): MastodonEntity.Attachment {
 | 
				
			||||||
	return simpleConvert(attachment);
 | 
						const { width, height } = attachment.meta?.original ?? attachment.meta ?? {};
 | 
				
			||||||
 | 
						const size = (width && height) ? `${width}x${height}` : undefined;
 | 
				
			||||||
 | 
						const aspect = (width && height) ? (width / height) : undefined;
 | 
				
			||||||
 | 
						return {
 | 
				
			||||||
 | 
							...attachment,
 | 
				
			||||||
 | 
							meta: attachment.meta ? {
 | 
				
			||||||
 | 
								...attachment.meta,
 | 
				
			||||||
 | 
								original: attachment.meta.original ?? {
 | 
				
			||||||
 | 
									width: attachment.meta.width,
 | 
				
			||||||
 | 
									height: attachment.meta.height,
 | 
				
			||||||
 | 
									size,
 | 
				
			||||||
 | 
									aspect,
 | 
				
			||||||
 | 
									frame_rate: String(attachment.meta.fps),
 | 
				
			||||||
 | 
									duration: attachment.meta.duration,
 | 
				
			||||||
 | 
									bitrate: attachment.meta.audio_bitrate ? parseInt(attachment.meta.audio_bitrate) : undefined,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								size,
 | 
				
			||||||
 | 
								aspect,
 | 
				
			||||||
 | 
							} : null,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export function convertFilter(filter: Entity.Filter) {
 | 
					export function convertFilter(filter: Entity.Filter) {
 | 
				
			||||||
	return simpleConvert(filter);
 | 
						return simpleConvert(filter);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue