From 22516d86ea552c5a648e785347b2d051d6ed8ef6 Mon Sep 17 00:00:00 2001 From: stephanebottin Date: Thu, 6 Feb 2025 22:57:34 +0100 Subject: [PATCH] Enable aspect ratio for external links --- lexicons/app/bsky/embed/external.json | 15 ++++++++++-- packages/api/src/client/lexicons.ts | 24 +++++++++++++++++++ .../client/types/app/bsky/embed/external.ts | 21 ++++++++++++++++ packages/bsky/src/lexicon/lexicons.ts | 24 +++++++++++++++++++ .../lexicon/types/app/bsky/embed/external.ts | 21 ++++++++++++++++ packages/ozone/src/lexicon/lexicons.ts | 24 +++++++++++++++++++ .../lexicon/types/app/bsky/embed/external.ts | 21 ++++++++++++++++ packages/pds/src/lexicon/lexicons.ts | 24 +++++++++++++++++++ .../lexicon/types/app/bsky/embed/external.ts | 21 ++++++++++++++++ 9 files changed, 193 insertions(+), 2 deletions(-) diff --git a/lexicons/app/bsky/embed/external.json b/lexicons/app/bsky/embed/external.json index b9930dff2b0..9bb0cfd2f49 100644 --- a/lexicons/app/bsky/embed/external.json +++ b/lexicons/app/bsky/embed/external.json @@ -24,7 +24,17 @@ "type": "blob", "accept": ["image/*"], "maxSize": 1000000 - } + }, + "aspectRatio": {"type": "ref", "ref": "#aspectRatio"} + } + }, + "aspectRatio": { + "type": "object", + "description": "width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit.", + "required": ["width", "height"], + "properties": { + "width": {"type": "integer", "minimum": 1}, + "height": {"type": "integer", "minimum": 1} } }, "view": { @@ -44,7 +54,8 @@ "uri": { "type": "string", "format": "uri" }, "title": { "type": "string" }, "description": { "type": "string" }, - "thumb": { "type": "string", "format": "uri" } + "thumb": { "type": "string", "format": "uri" }, + "aspectRatio": {"type": "ref", "ref": "#aspectRatio"} } } } diff --git a/packages/api/src/client/lexicons.ts b/packages/api/src/client/lexicons.ts index 6e709774761..1c907303dcd 100644 --- a/packages/api/src/client/lexicons.ts +++ b/packages/api/src/client/lexicons.ts @@ -5134,6 +5134,26 @@ export const schemaDict = { accept: ['image/*'], maxSize: 1000000, }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, + }, + }, + aspectRatio: { + type: 'object', + description: + 'width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit.', + required: ['width', 'height'], + properties: { + width: { + type: 'integer', + minimum: 1, + }, + height: { + type: 'integer', + minimum: 1, + }, }, }, view: { @@ -5164,6 +5184,10 @@ export const schemaDict = { type: 'string', format: 'uri', }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, }, }, }, diff --git a/packages/api/src/client/types/app/bsky/embed/external.ts b/packages/api/src/client/types/app/bsky/embed/external.ts index 5832cbb3987..7092f299aaa 100644 --- a/packages/api/src/client/types/app/bsky/embed/external.ts +++ b/packages/api/src/client/types/app/bsky/embed/external.ts @@ -30,6 +30,7 @@ export interface External { title: string description: string thumb?: BlobRef + aspectRatio?: AspectRatio [k: string]: unknown } @@ -45,6 +46,25 @@ export function validateExternal(v: unknown): ValidationResult { return lexicons.validate('app.bsky.embed.external#external', v) } +/** width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit. */ +export interface AspectRatio { + width: number + height: number + [k: string]: unknown +} + +export function isAspectRatio(v: unknown): v is AspectRatio { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'app.bsky.embed.external#aspectRatio' + ) +} + +export function validateAspectRatio(v: unknown): ValidationResult { + return lexicons.validate('app.bsky.embed.external#aspectRatio', v) +} + export interface View { external: ViewExternal [k: string]: unknown @@ -67,6 +87,7 @@ export interface ViewExternal { title: string description: string thumb?: string + aspectRatio?: AspectRatio [k: string]: unknown } diff --git a/packages/bsky/src/lexicon/lexicons.ts b/packages/bsky/src/lexicon/lexicons.ts index f0392dccfde..f8cd530e5f4 100644 --- a/packages/bsky/src/lexicon/lexicons.ts +++ b/packages/bsky/src/lexicon/lexicons.ts @@ -5134,6 +5134,26 @@ export const schemaDict = { accept: ['image/*'], maxSize: 1000000, }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, + }, + }, + aspectRatio: { + type: 'object', + description: + 'width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit.', + required: ['width', 'height'], + properties: { + width: { + type: 'integer', + minimum: 1, + }, + height: { + type: 'integer', + minimum: 1, + }, }, }, view: { @@ -5164,6 +5184,10 @@ export const schemaDict = { type: 'string', format: 'uri', }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, }, }, }, diff --git a/packages/bsky/src/lexicon/types/app/bsky/embed/external.ts b/packages/bsky/src/lexicon/types/app/bsky/embed/external.ts index b137ee4b6f5..705e1616edf 100644 --- a/packages/bsky/src/lexicon/types/app/bsky/embed/external.ts +++ b/packages/bsky/src/lexicon/types/app/bsky/embed/external.ts @@ -30,6 +30,7 @@ export interface External { title: string description: string thumb?: BlobRef + aspectRatio?: AspectRatio [k: string]: unknown } @@ -45,6 +46,25 @@ export function validateExternal(v: unknown): ValidationResult { return lexicons.validate('app.bsky.embed.external#external', v) } +/** width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit. */ +export interface AspectRatio { + width: number + height: number + [k: string]: unknown +} + +export function isAspectRatio(v: unknown): v is AspectRatio { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'app.bsky.embed.external#aspectRatio' + ) +} + +export function validateAspectRatio(v: unknown): ValidationResult { + return lexicons.validate('app.bsky.embed.external#aspectRatio', v) +} + export interface View { external: ViewExternal [k: string]: unknown @@ -67,6 +87,7 @@ export interface ViewExternal { title: string description: string thumb?: string + aspectRatio?: AspectRatio [k: string]: unknown } diff --git a/packages/ozone/src/lexicon/lexicons.ts b/packages/ozone/src/lexicon/lexicons.ts index 6e709774761..1c907303dcd 100644 --- a/packages/ozone/src/lexicon/lexicons.ts +++ b/packages/ozone/src/lexicon/lexicons.ts @@ -5134,6 +5134,26 @@ export const schemaDict = { accept: ['image/*'], maxSize: 1000000, }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, + }, + }, + aspectRatio: { + type: 'object', + description: + 'width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit.', + required: ['width', 'height'], + properties: { + width: { + type: 'integer', + minimum: 1, + }, + height: { + type: 'integer', + minimum: 1, + }, }, }, view: { @@ -5164,6 +5184,10 @@ export const schemaDict = { type: 'string', format: 'uri', }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, }, }, }, diff --git a/packages/ozone/src/lexicon/types/app/bsky/embed/external.ts b/packages/ozone/src/lexicon/types/app/bsky/embed/external.ts index b137ee4b6f5..705e1616edf 100644 --- a/packages/ozone/src/lexicon/types/app/bsky/embed/external.ts +++ b/packages/ozone/src/lexicon/types/app/bsky/embed/external.ts @@ -30,6 +30,7 @@ export interface External { title: string description: string thumb?: BlobRef + aspectRatio?: AspectRatio [k: string]: unknown } @@ -45,6 +46,25 @@ export function validateExternal(v: unknown): ValidationResult { return lexicons.validate('app.bsky.embed.external#external', v) } +/** width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit. */ +export interface AspectRatio { + width: number + height: number + [k: string]: unknown +} + +export function isAspectRatio(v: unknown): v is AspectRatio { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'app.bsky.embed.external#aspectRatio' + ) +} + +export function validateAspectRatio(v: unknown): ValidationResult { + return lexicons.validate('app.bsky.embed.external#aspectRatio', v) +} + export interface View { external: ViewExternal [k: string]: unknown @@ -67,6 +87,7 @@ export interface ViewExternal { title: string description: string thumb?: string + aspectRatio?: AspectRatio [k: string]: unknown } diff --git a/packages/pds/src/lexicon/lexicons.ts b/packages/pds/src/lexicon/lexicons.ts index 6e709774761..1c907303dcd 100644 --- a/packages/pds/src/lexicon/lexicons.ts +++ b/packages/pds/src/lexicon/lexicons.ts @@ -5134,6 +5134,26 @@ export const schemaDict = { accept: ['image/*'], maxSize: 1000000, }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, + }, + }, + aspectRatio: { + type: 'object', + description: + 'width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit.', + required: ['width', 'height'], + properties: { + width: { + type: 'integer', + minimum: 1, + }, + height: { + type: 'integer', + minimum: 1, + }, }, }, view: { @@ -5164,6 +5184,10 @@ export const schemaDict = { type: 'string', format: 'uri', }, + aspectRatio: { + type: 'ref', + ref: 'lex:app.bsky.embed.external#aspectRatio', + }, }, }, }, diff --git a/packages/pds/src/lexicon/types/app/bsky/embed/external.ts b/packages/pds/src/lexicon/types/app/bsky/embed/external.ts index b137ee4b6f5..705e1616edf 100644 --- a/packages/pds/src/lexicon/types/app/bsky/embed/external.ts +++ b/packages/pds/src/lexicon/types/app/bsky/embed/external.ts @@ -30,6 +30,7 @@ export interface External { title: string description: string thumb?: BlobRef + aspectRatio?: AspectRatio [k: string]: unknown } @@ -45,6 +46,25 @@ export function validateExternal(v: unknown): ValidationResult { return lexicons.validate('app.bsky.embed.external#external', v) } +/** width:height represents an aspect ratio. It may be approximate, and may not correspond to absolute dimensions in any given unit. */ +export interface AspectRatio { + width: number + height: number + [k: string]: unknown +} + +export function isAspectRatio(v: unknown): v is AspectRatio { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'app.bsky.embed.external#aspectRatio' + ) +} + +export function validateAspectRatio(v: unknown): ValidationResult { + return lexicons.validate('app.bsky.embed.external#aspectRatio', v) +} + export interface View { external: ViewExternal [k: string]: unknown @@ -67,6 +87,7 @@ export interface ViewExternal { title: string description: string thumb?: string + aspectRatio?: AspectRatio [k: string]: unknown }