Skip to content

Commit c83e3d4

Browse files
committed
Cleanup
1 parent 7191eb0 commit c83e3d4

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

app/common/src/services/Backend.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,10 +1866,13 @@ export default abstract class Backend {
18661866
body: UploadFileEndRequestBody,
18671867
abort?: AbortSignal,
18681868
): Promise<UploadedAsset>
1869+
/**
1870+
* Upload set of Images, resoliving any possible conflicts. The sum of file sizes may not
1871+
* exceed could message limit.
1872+
*/
18691873
abstract uploadImage(
18701874
parentDirectoryId: DirectoryId,
1871-
file: Blob,
1872-
filename: string,
1875+
files: { data: Blob; name: string }[],
18731876
): Promise<UploadedImages>
18741877
/** Change the name of a file. */
18751878
abstract updateFile(fileId: FileId, body: UpdateFileRequestBody, title: string): Promise<void>

app/gui/src/dashboard/layouts/AssetContextMenu.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const AssetContextMenu = React.forwardRef(function AssetContextMenu(
7878
const copyAssets = useMutationCallback(copyAssetsMutationOptions(backend))
7979
const downloadAssets = useMutationCallback(downloadAssetsMutationOptions(backend))
8080
const self = permissions.tryFindSelfPermission(user, asset.permissions)
81-
const encodedEnsoPath = asset.ensoPath ? encodeURI(asset.ensoPath) : undefined
81+
const encodedEnsoPath = encodeURI(asset.ensoPath)
8282
const copyMutation = useCopy()
8383
const uploadFileToCloud = useUploadFileToCloud()
8484
const uploadFileToLocal = useUploadFileToLocal(category)
@@ -116,12 +116,7 @@ export const AssetContextMenu = React.forwardRef(function AssetContextMenu(
116116
})
117117

118118
const canPaste =
119-
(
120-
!pasteDataParent ||
121-
!pasteData ||
122-
!isCloud ||
123-
(pasteDataParent.ensoPath != null && permissions.isTeamPath(pasteDataParent.ensoPath))
124-
) ?
119+
!pasteDataParent || !pasteData || !isCloud || permissions.isTeamPath(pasteDataParent.ensoPath) ?
125120
true
126121
: pasteData.data.assets.every((pasteAsset) => {
127122
const otherAsset = getAsset(pasteAsset.id)
@@ -395,15 +390,14 @@ export const AssetContextMenu = React.forwardRef(function AssetContextMenu(
395390
},
396391
},
397392
!isCloud &&
398-
encodedEnsoPath != null &&
399393
systemApi && {
400394
action: 'openInFileBrowser',
401395
doAction: () => {
402396
void goToDrive()
403397
systemApi.showItemInFolder(encodedEnsoPath)
404398
},
405399
},
406-
encodedEnsoPath != null && {
400+
{
407401
action: 'copyAsPath',
408402
doAction: () => {
409403
void goToDrive()

app/gui/src/dashboard/pages/dashboard/components/AssetRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const AssetRow = React.memo(function AssetRow(props: AssetRowProps) {
230230
// Assume the parent is the root directory.
231231
return true
232232
}
233-
if (parent.ensoPath != null && isTeamPath(parent.ensoPath)) {
233+
if (isTeamPath(parent.ensoPath)) {
234234
return true
235235
}
236236
// Assume user path; check permissions

app/gui/src/dashboard/services/LocalBackend.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,15 @@ export default class LocalBackend extends Backend {
719719
return Promise.resolve(file)
720720
}
721721

722+
/**
723+
* Upload set of Images, resoliving any possible conflicts. The sum of file sizes may not
724+
* exceed could message limit.
725+
*/
722726
override uploadImage(
723727
_parentDirectoryId: backend.DirectoryId,
724-
_file: Blob,
725-
_filename: string,
728+
_files: { data: Blob; name: string }[],
726729
): Promise<backend.UploadedImages> {
727-
throw Error('Not implemented')
730+
this.invalidOperation()
728731
}
729732

730733
/** Change the name of a file. */

app/gui/src/dashboard/services/RemoteBackend.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,11 @@ export default class RemoteBackend extends Backend {
342342
query: backend.ListDirectoryRequestParams,
343343
title: string,
344344
): Promise<backend.ListDirectoryResponseBody> {
345-
if (query.recentProjects && query.from) {
345+
if (query.recentProjects === true && query.from) {
346346
return { assets: [], paginationToken: null }
347347
}
348348
const paramsString = new URLSearchParams(
349-
query.recentProjects ?
349+
query.recentProjects === true ?
350350
[['recent_projects', String(true)]]
351351
: [
352352
...(query.parentId != null ? [['parent_id', query.parentId]] : []),
@@ -935,11 +935,20 @@ export default class RemoteBackend extends Backend {
935935
}
936936
}
937937

938-
override async uploadImage(parentDirectoryId: backend.DirectoryId, file: Blob, filename: string) {
938+
/**
939+
* Upload set of Images, resoliving any possible conflicts. The sum of file sizes may not
940+
* exceed could message limit.
941+
*/
942+
override async uploadImage(
943+
parentDirectoryId: backend.DirectoryId,
944+
files: { data: Blob; name: string }[],
945+
) {
939946
const path = remoteBackendPaths.UPLOAD_IMAGE_PATH
940947
const query = new URLSearchParams({ parentDirectoryId })
941948
const data = new FormData()
942-
data.append('image', file, filename)
949+
for (const file of files) {
950+
data.append('image', file.data, file.name)
951+
}
943952
const response = await this.postFormData<backend.UploadedImages>(`${path}?${query}`, data)
944953
if (!response.ok) {
945954
return this.throw(response, 'uploadImageBackendError')

app/gui/src/project-view/providers/asyncResources/upload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ export function useResourceUpload(
149149
const contents = await data.data
150150
const uploadResult = await uploadImageMutation.mutateAsync([
151151
imagesDir,
152-
contents,
153-
data.filename,
152+
[{ data: contents, name: data.filename }],
154153
])
155154

156155
return Ok({

0 commit comments

Comments
 (0)