Type Definitions

Basic Data for Publishing Content#

First, we define a series of types as the communication foundation for the extension to publish content.

When you need to publish content, you need to organize data of type SyncData, then call the funcPublish function to publish.

export interface SyncData {
  platforms: SyncDataPlatform[];
  isAutoPublish: boolean;
  data: DynamicData | ArticleData | VideoData | PodcastData;
}

export interface SyncDataPlatform {
  name: string;
  injectUrl?: string;
  extraConfig?:
    | {
        customInjectUrls?: string[]; // Beta feature for custom injection URLs
      }
    | unknown;
}

Organization of Publishing Data#

Publishing data needs to be organized according to platform type — dynamic, article, video, podcast, etc.

For example, when you want to publish a dynamic post, you put a DynamicData value into the data field of SyncData.

// DynamicData — payload for a dynamic post
export interface DynamicData {
  title: string; // Title
  content: string; // Content
  images: FileData[]; // Images
  videos: FileData[]; // Videos — only used by platforms that allow image+video posts (Instagram, X, ...)
  tags?: string[]; // Hashtags / topics; publishers turn these into #tag# or #tag per platform
  scheduledPublishTime?: number; // Scheduled publish time in ms; requires platform support
}

// ArticleData — payload for a long-form article
// Publishers consume HTML or Markdown depending on what the destination accepts
export interface ArticleData {
  title: string; // Title
  digest: string; // Summary
  cover: FileData; // Cover image
  htmlContent: string; // Rendered HTML
  markdownContent: string; // Source Markdown
  images?: FileData[]; // Images
  tags?: string[]; // Tags
  category?: string | number; // Platform category id or name
  original?: boolean; // Mark as original work
  allowComment?: boolean; // Allow comments
  scheduledPublishTime?: number; // Scheduled publish time in ms
}

// VideoData — payload for a video post
export interface VideoData {
  title: string; // Title
  content: string; // Body / description text
  video: FileData; // Video file
  cover?: FileData; // Default cover
  verticalCover?: FileData; // Portrait cover when the platform supports it
  horizontalCover?: FileData; // Landscape cover when the platform supports it
  tags?: string[]; // Tags
  scheduledPublishTime?: number; // Scheduled publish time in ms
  category?: string | number; // Platform partition id (e.g. Bilibili tid, YouTube category)
  original?: boolean; // Mark as original work
  collectionId?: string | number; // Collection / series id (e.g. Bilibili list_id)
  description?: string; // Description field (independent of `content`; preferred by some platforms)
}

// PodcastData — payload for a podcast episode
export interface PodcastData {
  title: string; // Title
  description: string; // Show notes / description
  audio: FileData; // Audio file
  cover?: FileData; // Cover image
  tags?: string[]; // Tags
  category?: string | number; // Platform category
}

// FileData — basic file payload
export interface FileData {
  name: string; // File name
  url: string; // File link, usually a blob link; extension scripts can fetch from any blob link
  type?: string; // MIME type
  size?: number; // File size in bytes
  originUrl?: string; // Original https URL, when known
}

Platform Information#

When you organize SyncData data, you need to get basic platform information, such as platform name, injection URL, etc.

For ease of management, we define data of type PlatformInfo to organize platform information.

// PlatformInfo is platform information, used to organize platform information
export interface PlatformInfo {
  type: 'DYNAMIC' | 'VIDEO' | 'ARTICLE' | 'PODCAST'; // Platform type
  name: string; // Platform name
  homeUrl: string; // Platform homepage
  faviconUrl?: string; // Platform icon
  iconifyIcon?: string; // Platform icon
  platformName: string; // Platform name
  username?: string; // Username
  userAvatarUrl?: string; // User avatar
  injectUrl: string; // Platform publishing page
  injectFunction: (data: SyncData) => Promise<void>; // Platform publishing function
  tags?: string[]; // Platform tags
  accountKey: string; // Platform account identifier
  accountInfo?: AccountInfo; // Platform account information
}

// AccountInfo is account information, used to organize account information
export interface AccountInfo {
  provider: string; // Account provider
  accountId: string; // Account ID
  username: string; // Account name
  description?: string; // Account description
  profileUrl?: string; // Account link
  avatarUrl?: string; // Account avatar
  extraData: unknown; // Account extra data
}

Tab Management#

Tab management is another important feature of the extension, used to manage tabs created during the publishing process.

We define data of type TabManagerMessage to organize tab management data.

export interface TabManagerMessage {
  syncData: SyncData;
  tabs: {
    tab: chrome.tabs.Tab;
    platformInfo: SyncDataPlatform;
  }[];
}

Extension Interface#

Extension interface is another important feature of the extension. We allow developers to call the extension's content publishing functionality through the extension interface.

We define data of types ExtensionExternalRequest and ExtensionExternalResponse to organize extension interface data.

For more information, refer to API Documentation

export type ExtensionExternalRequest<T> = {
  type: 'request';
  traceId: string;
  action: string;
  data: T;
};

export interface ExtensionExternalResponse<T> {
  type: 'response';
  traceId: string;
  action: string;
  code: number;
  message: string;
  data: T;
}