@stackend/api
Version:
JS bindings to api.stackend.com
454 lines • 15.4 kB
TypeScript
import type { PaginatedCollection } from '../api/PaginatedCollection';
import { XcapJsonResult, Config, Thunk, XcapOptionalParameters } from '../api';
import XcapObject from '../api/XcapObject';
import DescriptionAware from '../api/DescriptionAware';
import CreatorUserIdAware from '../api/CreatorUserIdAware';
import ModifiedDateAware from '../api/ModifiedDateAware';
import ReferenceIdAware from '../api/ReferenceIdAware';
import Reference from '../api/Reference';
/**
* Image
*/
export declare enum MediaStatus {
OK = "OK",
NOT_OK = "NOT_OK",
NOT_PROCESSED = "NOT_PROCESSED",
TEMPORARY = "TEMPORARY"
}
export interface Media extends XcapObject, DescriptionAware, CreatorUserIdAware, ModifiedDateAware, ReferenceIdAware<XcapObject> {
createdDate: number;
originalName: string;
status: MediaStatus;
title: string;
mediaType: MediaTypeNames;
/** Mime type: image/jpg etc */
mimeType: string;
/** File size in bytes */
bytes: number;
/** File size as string 46.1KB */
size: string;
/** Url to original media file */
url: string;
}
export interface Image extends Media {
__type: 'net.josh.community.media.Image';
width: number;
height: number;
}
export interface Video extends Media {
__type: 'net.josh.community.media.Video';
width: number;
height: number;
/** Length in seconds */
length: number;
}
export interface Document extends Media {
__type: 'net.josh.community.media.Document';
}
export interface Audio extends Media {
__type: 'net.josh.community.media.Audio';
/** Length in seconds */
length: number;
}
/**
* Image, Document, Video or Audio
*/
export declare type MediaObject = Image | Document | Video | Audio;
export interface Thumbnail {
id: number;
/** Media object id */
mediaId: number;
/** Url to the thumbnail file */
url: string;
}
/**
* Image thumbnail
*/
export interface ImageThumbnail extends Thumbnail {
/** Actual thumbnail width (as opposed to requested width in the ThubnailConfig) */
width: number;
/** Actual thumbnail height (as opposed to requested width in the ThubnailConfig) */
height: number;
/** Size in bytes*/
bytes: number;
/**
* Media type id
*/
mediaType: MediaTypeNames;
/**
* Created date
*/
createdDate: number;
/**
* Thumbnail configuration
*/
config: ThumbnailConfig;
}
/**
* Thumbnail configuration
*/
export interface ThumbnailConfig {
width: number;
height: number;
create: boolean;
type: string;
gravity: string;
paddingColor: string;
method: number;
}
/**
* Media types
*/
export declare enum MediaType {
/**
* Image files. Will be presented as an <img>-element
*/
IMAGE = "IMAGE",
/**
* Video files. Will be presented as a <video>-element
*/
VIDEO = "VIDEO",
/**
* Audio files. Will be presented as an <audio>-element.
*/
AUDIO = "AUDIO",
/**
* Other types of files that may be stored and will be presented as a link when inserted in text.
*/
DOCUMENT = "DOCUMENT"
}
/**
* Media type ids
*/
export declare enum MediaTypeId {
IMAGE = 1,
VIDEO = 2,
AUDIO = 3,
DOCUMENT = 4
}
/**
* Media type ids
*/
export declare type MediaTypeIds = 1 | 2 | 3 | 4;
export declare type MediaTypeNames = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT';
/**
* Media type names
*/
export declare const MediaTypeName: {
[mediaTypeId: number]: MediaTypeNames;
};
/**
* Media list ordering
*/
export declare enum MediaListOrder {
LATEST_UPDATED_DESC = 1,
LATEST_UPDATED_ASC = 2,
CREATED_DESC = 3,
CREATED_ASC = 4,
CATEGORY_DESC = 5,
CATEGORY_ASC = 6,
TITLE_DESC = 7,
TITLE_ASC = 8,
USER_DESC = 9,
USER_ASC = 10,
RANDOM = 11
}
/**
* Standard ImageThumbnailConfig names
* @type {{TINY: string, SMALL: string, MEDIUM: string, LARGE: string}}
*/
export declare const ThumbnailSize: {
TINY: string;
SMALL: string;
MEDIUM: string;
LARGE: string;
};
/**
* Orientation: Landscape or portrait?
*/
export declare enum Orientation {
LANDSCAPE = "LANDSCAPE",
PORTRAIT = "PORTRAIT"
}
/**
* Given an url, get an url to a thumbnail of the desired size.
* Effectively inserting the size into the url.
* @param url
* @param size
*/
export declare function getThumbnailUrl({ url, size }: {
url?: string | null;
size?: string;
}): string | null;
/**
* Get the context prefix
* @param config
* @param communityPermalink
*/
export declare function getContextPrefix({ config, communityPermalink }: {
config: Config;
communityPermalink?: string;
}): string;
/**
* Get the absolute context prefix, including server.
* @param config
* @param communityPermalink
* @param context
*/
export declare function getAbsoluteContextPrefix({ config, communityPermalink, context }: {
config: Config;
communityPermalink?: string;
context?: string;
}): string;
/**
* Get the url used to upload a media file.
* @param config API config
* @param referenceId {number} Id of another object referencing this media object.
* @param communityPermalink {string} Community permalink (optional, defaults to current community)
* @param context {string} Community context
* @param temporary {Boolean} Mark the media as temporary? Temporary images are subject to automatic removal.
* @param thumbnail {String} Optional thumbnail configuration name. Determines the size of the returned image
* @param maxWidth {number} Optional max width. Typically detected from the width of a container element.
* @param maxHeight {number} Optional max height. Typically detected from the height of a container element.
*/
export declare function getMediaUploadUrl({ config, referenceId, communityPermalink, context, temporary, thumbnail, maxWidth, maxHeight }: {
config: Config;
referenceId?: number;
communityPermalink?: string;
context: string;
temporary?: boolean;
thumbnail?: string;
maxWidth?: number;
maxHeight?: number;
}): string;
/**
* Get the url used to upload a media file.
* @param referenceId {number} Id of another object referencing this media object.
* @param config API config
* @param communityPermalink {string} Community permalink (optional, defaults to current community)
* @param context {string} Community context
* @param temporary {Boolean} Mark the media as temporary? Temporary images are subject to automatic removal.
* @param thumbnail {String} Optional thumbnail configuration name. Determines the size of the returned image
* @param maxWidth {number} Optional max width. Typically detected from the width of a container element.
* @param maxHeight {number} Optional max height. Typically detected from the height of a container element.
* @param responsive {Boolean} Optional responsive. Sets widht:100%; max-width: <PICTURE WIDTH>px; height: auto
*/
export declare function getContextMediaUploadUrl({ config, referenceId, communityPermalink, context, temporary, thumbnail, maxWidth, maxHeight, responsive }: {
config: Config;
referenceId?: number;
communityPermalink?: string;
context?: string;
temporary?: boolean;
thumbnail?: string;
maxWidth?: number;
maxHeight?: number;
responsive?: boolean;
}): string;
export interface UploadMediaFileResult {
/**
* Error message, if not successful
*/
error?: string;
/**
* Array of media objects
*/
files: Array<MediaObject>;
/**
* Maps from media id to thumbnail. Only present if the thumbnail parameter is set.
*/
thumbnails?: {
[id: string]: Thumbnail;
};
/**
* Maps from media id to html used for embedding the media object
*/
html: {
[id: string]: string;
};
}
export interface UploadMediaFileRequest {
file: File;
communityPermalink?: string;
context?: string;
referenceId?: number;
temporary?: boolean;
thumbnail?: string;
maxWidth?: number;
maxHeight?: number;
responsive?: boolean;
}
/**
* Upload a media file. Browser only.
*
* @param config API config
* @param file {File} file object
* @param communityPermalink {string} Community permalink (optional, defaults to current community)
* @param context {string} Community context
* @param referenceId {number} Id of another object referencing this media object.
* @param temporary {Boolean} Mark the media as temporary? Temporary images are subject to automatic removal.
* @param thumbnail {String} Optional thumbnail configuration name. Determines the size of the returned image
* @param maxWidth {number} Optional max width. Typically detected from the width of a container element.
* @param maxHeight {number} Optional max height. Typically detected from the height of a container element.
* @param responsive {Boolean} Optional responsive. Sets widht:100%; max-width: <PICTURE WIDTH>px; height: auto
* @return {Promise}
*/
export declare function uploadMediaFile({ config, file, communityPermalink, context, referenceId, temporary, thumbnail, maxWidth, maxHeight, responsive }: {
config: Config;
} & UploadMediaFileRequest & XcapOptionalParameters): Promise<UploadMediaFileResult>;
/**
* Upload a media file. Browser only.
*
* @param config API config
* @param file {File} file object
* @param communityPermalink {string} Community permalink (optional, defaults to current community)
* @param context {string} Community context
* @param referenceId {number} Id of another object referencing this media object.
* @param temporary {Boolean} Mark the media as temporary? Temporary images are subject to automatic removal.
* @param thumbnail {String} Optional thumbnail configuration name. Determines the size of the returned image
* @param maxWidth {number} Optional max width. Typically detected from the width of a container element.
* @param maxHeight {number} Optional max height. Typically detected from the height of a container element.
* @param responsive {Boolean} Optional responsive. Sets widht:100%; max-width: <PICTURE WIDTH>px; height: auto
* @return {Promise}
*/
export declare function upload({ file, context, referenceId, temporary, thumbnail, maxWidth, maxHeight, responsive, communityPermalink }: UploadMediaFileRequest & XcapOptionalParameters): Thunk<Promise<UploadMediaFileResult>>;
export interface ListResult extends XcapJsonResult {
mediaPaginated: PaginatedCollection<MediaObject>;
thumbnailsByMediaId?: {
[mediaId: string]: Thumbnail;
} | null;
}
/**
* List my media files.
*
* @param context {string} Context (excluding community)
* @param thumbnailConfigName {string} Thumbnail config name
* @param mediaType {MediaTypeId} Media type id (optional)
* @param referenceId {number} Reference id (optional)
* @param categoryId {number} Category id (optional)
* @param order {MediaListOrder} Sort order (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
export declare function listMy({ context, thumbnailConfigName, mediaType, referenceId, categoryId, order, pageSize, p }: {
context: string;
thumbnailConfigName?: string;
mediaType?: MediaTypeId;
referenceId?: number;
categoryId?: number;
order?: MediaListOrder;
pageSize?: number;
p?: number;
} & XcapOptionalParameters): Thunk<Promise<ListResult>>;
/**
* List media files.
*
* @param context {string} Context (excluding community)
* @param thumbnailConfigName {string} Thumbnail config name
* @param mediaType {MediaTypeId} Media type id (optional)
* @param referenceId {number} Reference id (optional)
* @param categoryId {number} Category id (optional)
* @param order {MediaListOrder} Sort order (optional)
* @param p Page number (optional)
* @param pageSize Page size (optional)
*/
export declare function list({ context, thumbnailConfigName, mediaType, referenceId, categoryId, order, pageSize, p }: {
context: string;
thumbnailConfigName?: string;
mediaType?: MediaTypeId;
referenceId?: number;
categoryId?: number;
order?: number;
pageSize?: number;
p?: number;
} & XcapOptionalParameters): Thunk<Promise<ListResult>>;
/**
* Remove a media object (by setting modstatus).
*
* @param communityPermalink {string} Community permalink (optional, defaults to current community)
* @param context {string} Context (excluding community)
* @param id {number} Media id
*/
export declare function remove({ communityPermalink, context, id }: {
communityPermalink?: string;
context: string;
id: number;
} & XcapOptionalParameters): Thunk<Promise<XcapJsonResult>>;
export interface GetMediaResult extends XcapJsonResult {
media: MediaObject | null;
/** Thumbnail, if thumbnailConfigName is set */
thumbnail: ImageThumbnail | null;
/** Html for embedding */
html: string | null;
}
/**
* Get a media file.
*
* @param context {string} Context (excluding community)
* @param thumbnailConfigName {string} Thumbnail config name (optional)
* @param id {number} id (optional)
* @param permalink {string} permalink (optional)
* @param responsive {boolean} Generate responsive html
* @return {Thunk<*>}
*/
export declare function get({ context, thumbnailConfigName, id, permalink, responsive }: {
context: string;
thumbnailConfigName?: string;
id?: number;
permalink?: string;
responsive?: boolean;
} & XcapOptionalParameters): Thunk<Promise<GetMediaResult>>;
export interface EmbedResult extends XcapJsonResult {
mimeType: string;
maxWidth: number;
richContentEmbedding: 'NOT_SUPPORTED' | 'LINK' | 'EMBED';
html: string;
data: null | {
image?: Image;
thumbnail?: ImageThumbnail;
title?: string;
description?: string;
textsample?: string;
};
}
/**
* Validate a html fragment, a link, iframe, video for embedding in rich content.
*
* Url - Create some sample data from the site.
* Video url - the corresponding embed code is created (youtube, vimeo).
* Iframe/img tags - The src is checked against the whitelist.
*
* @param context {string} Context (excluding community)
* @param embedCode
* @param thumbnailConfigName {string} Thumbnail config name (optional)
* @param maxWidth (optional)
* @param responsive Use responsive layout: 100% width, or smaller if smaller.
* @param communityPermalink {string} Community permalink (optional, defaults to current community)
*/
export declare function embed({ context, embedCode, thumbnailConfigName, maxWidth, responsive, communityPermalink }: {
context: string;
embedCode: string;
thumbnailConfigName?: string;
maxWidth?: number;
responsive?: boolean;
communityPermalink?: string;
} & XcapOptionalParameters): Thunk<Promise<EmbedResult>>;
export interface SearchUsesResult extends XcapJsonResult {
uses: Array<Reference>;
}
/**
* Search for media uses
*
* @param mediaId
* @param context
*/
export declare function searchUses({ context, mediaId }: {
context: string;
mediaId?: number;
} & XcapOptionalParameters): Thunk<Promise<SearchUsesResult>>;
/**
* Construct a fake image thumbnail
* @param image
* @returns ImageThumbnail
*/
export declare function constructImageThumbnail(image: Image, thumbnailConfig: string): ImageThumbnail | null;
//# sourceMappingURL=index.d.ts.map