-
Notifications
You must be signed in to change notification settings - Fork 334
Upload images in asset descriptions #14247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
23f3034
7191eb0
c83e3d4
589f7a0
f8644a8
0f356e5
4908d48
937df9d
b85d628
77d84b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -630,7 +630,7 @@ export interface PathResolveResponse extends Omit<AnyRealAsset, 'type' | 'ensoPa | |
|
|
||
| /** Response from "assets/${assetId}" endpoint. */ | ||
| export type AssetDetailsResponse<Id extends AssetId> = | ||
| | (Omit<Asset<AssetTypeFromId<Id>>, 'ensoPath'> & { readonly metadataId: MetadataId }) | ||
| | (Asset<AssetTypeFromId<Id>> & { readonly metadataId: MetadataId }) | ||
| | null | ||
|
|
||
| /** Whether the user is on a plan with multiple seats (i.e. a plan that supports multiple users). */ | ||
|
|
@@ -947,9 +947,7 @@ export interface Asset<Type extends AssetType = AssetType> { | |
| readonly parentsPath: ParentsPath | ||
| readonly virtualParentsPath: VirtualParentsPath | ||
| /** The display path. */ | ||
| // TODO[ao]: As a rule, this should be always defined, but there is one place where we are unable | ||
| // to retrieve directory path easily. | ||
| readonly ensoPath: Type extends AssetType.directory ? EnsoPath | undefined : EnsoPath | ||
| readonly ensoPath: EnsoPath | ||
| } | ||
|
|
||
| /** A convenience alias for {@link Asset}<{@link AssetType.directory}>. */ | ||
|
|
@@ -1274,19 +1272,19 @@ export type AssetSortDirection = 'ascending' | 'descending' | |
| /** URL query string parameters for the "list directory" endpoint. */ | ||
| export interface ListDirectoryRequestParams { | ||
| readonly parentId: DirectoryId | null | ||
| readonly filterBy: FilterBy | null | ||
| readonly labels: readonly LabelName[] | null | ||
| readonly sortExpression: AssetSortExpression | null | ||
| readonly sortDirection: AssetSortDirection | null | ||
| readonly recentProjects: boolean | ||
| readonly filterBy?: FilterBy | null | ||
| readonly labels?: readonly LabelName[] | null | ||
| readonly sortExpression?: AssetSortExpression | null | ||
| readonly sortDirection?: AssetSortDirection | null | ||
| readonly recentProjects?: boolean | ||
| /** | ||
| * The root path of the directory to list. | ||
| * This is used to list a subdirectory of a local root directory, | ||
| * because a root could be any local folder on the machine. | ||
| */ | ||
| readonly rootPath?: Path | undefined | ||
| readonly from: PaginationToken | null | ||
| readonly pageSize: number | null | ||
| readonly from?: PaginationToken | null | ||
| readonly pageSize?: number | null | ||
| } | ||
|
|
||
| /** URL query string parameters for the "search directory" endpoint. */ | ||
|
|
@@ -1372,6 +1370,10 @@ export interface UploadedProject { | |
| /** A large asset (file or project) that has finished uploading. */ | ||
| export type UploadedAsset = UploadedFile | UploadedArchive | UploadedProject | ||
|
|
||
| export interface UploadedImages { | ||
| files: { assetId: AssetId; title: string }[] | ||
| } | ||
|
|
||
| /** URL query string parameters for the "upload profile picture" endpoint. */ | ||
| export interface UploadPictureRequestParams { | ||
| readonly fileName: string | null | ||
|
|
@@ -1849,7 +1851,7 @@ export default abstract class Backend { | |
| /** Begin uploading a large file. */ | ||
| abstract uploadFileStart( | ||
| params: UploadFileRequestParams, | ||
| file: File, | ||
| file: Blob, | ||
| abort?: AbortSignal, | ||
| ): Promise<UploadLargeFileMetadata> | ||
| /** Upload a chunk of a large file. */ | ||
|
|
@@ -1864,6 +1866,14 @@ export default abstract class Backend { | |
| body: UploadFileEndRequestBody, | ||
| abort?: AbortSignal, | ||
| ): Promise<UploadedAsset> | ||
| /** | ||
| * Upload set of Images, resoliving any possible conflicts. The sum of file sizes may not | ||
| * exceed could message limit. | ||
|
||
| */ | ||
| abstract uploadImage( | ||
| parentDirectoryId: DirectoryId, | ||
| files: { data: Blob; name: string }[], | ||
| ): Promise<UploadedImages> | ||
| /** Change the name of a file. */ | ||
| abstract updateFile(fileId: FileId, body: UpdateFileRequestBody, title: string): Promise<void> | ||
|
|
||
|
|
@@ -2003,6 +2013,16 @@ export default abstract class Backend { | |
| ) | ||
| } | ||
|
|
||
| protected postFormData<T = void>( | ||
| path: string, | ||
| payload: FormData, | ||
| options?: HttpClientPostOptions, | ||
| ) { | ||
| return this.checkForAuthenticationError(() => | ||
| this.client.postFormData<T>(this.resolvePath(path), payload, options), | ||
| ) | ||
| } | ||
|
|
||
| /** Send a JSON HTTP PATCH request to the given path. */ | ||
| protected patch<T = void>(path: string, payload: object) { | ||
| return this.checkForAuthenticationError(() => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,11 +342,11 @@ export default class RemoteBackend extends Backend { | |
| query: backend.ListDirectoryRequestParams, | ||
| title: string, | ||
| ): Promise<backend.ListDirectoryResponseBody> { | ||
| if (query.recentProjects && query.from) { | ||
| if (query.recentProjects === true && query.from) { | ||
|
||
| return { assets: [], paginationToken: null } | ||
| } | ||
| const paramsString = new URLSearchParams( | ||
| query.recentProjects ? | ||
| query.recentProjects === true ? | ||
| [['recent_projects', String(true)]] | ||
| : [ | ||
| ...(query.parentId != null ? [['parent_id', query.parentId]] : []), | ||
|
|
@@ -867,7 +867,7 @@ export default class RemoteBackend extends Backend { | |
| */ | ||
| override async uploadFileStart( | ||
| body: backend.UploadFileRequestParams, | ||
| file: File, | ||
| file: Blob, | ||
| abort?: AbortSignal, | ||
| ): Promise<backend.UploadLargeFileMetadata> { | ||
| const path = remoteBackendPaths.UPLOAD_FILE_START_PATH | ||
|
|
@@ -935,6 +935,28 @@ export default class RemoteBackend extends Backend { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Upload set of Images, resoliving any possible conflicts. The sum of file sizes may not | ||
|
||
| * exceed could message limit. | ||
| */ | ||
| override async uploadImage( | ||
| parentDirectoryId: backend.DirectoryId, | ||
| files: { data: Blob; name: string }[], | ||
| ) { | ||
| const path = remoteBackendPaths.UPLOAD_IMAGE_PATH | ||
| const query = new URLSearchParams({ parentDirectoryId }) | ||
| const data = new FormData() | ||
| for (const file of files) { | ||
| data.append('image', file.data, file.name) | ||
| } | ||
| const response = await this.postFormData<backend.UploadedImages>(`${path}?${query}`, data) | ||
| if (!response.ok) { | ||
| return this.throw(response, 'uploadImageBackendError') | ||
| } else { | ||
| return response.json() | ||
| } | ||
| } | ||
|
|
||
| /** Change the name of a file. */ | ||
| override async updateFile(): Promise<void> { | ||
| await this.throw(null, 'updateFileNotImplementedBackendError') | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.