Fix getFileDetails and getProjectDetails (#11787)

- Fix https://github.com/enso-org/cloud-v2/issues/1617
- Set `staleTime: 0` to queries to ensure they are always refetched.
- Close https://github.com/enso-org/cloud-v2/issues/1579
- Add `&presigned=true` flag to request server to generate a presigned URL.

# Important Notes
None
This commit is contained in:
somebody1234 2024-12-11 00:45:31 +10:00 committed by GitHub
parent 8749719c19
commit f6a900191a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 6 deletions

View File

@ -1687,6 +1687,7 @@ export default abstract class Backend {
abstract getProjectDetails( abstract getProjectDetails(
projectId: ProjectId, projectId: ProjectId,
directoryId: DirectoryId | null, directoryId: DirectoryId | null,
getPresignedUrl?: boolean,
): Promise<Project> ): Promise<Project>
/** Return Language Server logs for a project session. */ /** Return Language Server logs for a project session. */
abstract getProjectSessionLogs( abstract getProjectSessionLogs(
@ -1723,7 +1724,11 @@ export default abstract class Backend {
/** Change the name of a file. */ /** Change the name of a file. */
abstract updateFile(fileId: FileId, body: UpdateFileRequestBody, title: string): Promise<void> abstract updateFile(fileId: FileId, body: UpdateFileRequestBody, title: string): Promise<void>
/** Return file details. */ /** Return file details. */
abstract getFileDetails(fileId: FileId, title: string): Promise<FileDetails> abstract getFileDetails(
fileId: FileId,
title: string,
getPresignedUrl?: boolean,
): Promise<FileDetails>
/** Create a Datalink. */ /** Create a Datalink. */
abstract createDatalink(body: CreateDatalinkRequestBody): Promise<DatalinkInfo> abstract createDatalink(body: CreateDatalinkRequestBody): Promise<DatalinkInfo>
/** Return a Datalink. */ /** Return a Datalink. */

View File

@ -488,7 +488,12 @@ export function RealAssetInternalRow(props: RealAssetRowInternalProps) {
case backendModule.AssetType.project: { case backendModule.AssetType.project: {
try { try {
const details = await queryClient.fetchQuery( const details = await queryClient.fetchQuery(
backendQueryOptions(backend, 'getProjectDetails', [asset.id, asset.parentId]), backendQueryOptions(
backend,
'getProjectDetails',
[asset.id, asset.parentId, true],
{ staleTime: 0 },
),
) )
if (details.url != null) { if (details.url != null) {
await backend.download(details.url, `${asset.title}.enso-project`) await backend.download(details.url, `${asset.title}.enso-project`)
@ -504,7 +509,9 @@ export function RealAssetInternalRow(props: RealAssetRowInternalProps) {
case backendModule.AssetType.file: { case backendModule.AssetType.file: {
try { try {
const details = await queryClient.fetchQuery( const details = await queryClient.fetchQuery(
backendQueryOptions(backend, 'getFileDetails', [asset.id, asset.title]), backendQueryOptions(backend, 'getFileDetails', [asset.id, asset.title, true], {
staleTime: 0,
}),
) )
if (details.url != null) { if (details.url != null) {
await backend.download(details.url, asset.title) await backend.download(details.url, asset.title)

View File

@ -767,8 +767,15 @@ export default class RemoteBackend extends Backend {
* Return details for a project. * Return details for a project.
* @throws An error if a non-successful status code (not 200-299) was received. * @throws An error if a non-successful status code (not 200-299) was received.
*/ */
override async getProjectDetails(projectId: backend.ProjectId): Promise<backend.Project> { override async getProjectDetails(
const path = remoteBackendPaths.getProjectDetailsPath(projectId) projectId: backend.ProjectId,
_directoryId: null,
getPresignedUrl = false,
): Promise<backend.Project> {
const paramsString = new URLSearchParams({
presigned: `${getPresignedUrl}`,
}).toString()
const path = `${remoteBackendPaths.getProjectDetailsPath(projectId)}?${paramsString}`
const response = await this.get<backend.ProjectRaw>(path) const response = await this.get<backend.ProjectRaw>(path)
if (!responseIsSuccessful(response)) { if (!responseIsSuccessful(response)) {
return await this.throw(response, 'getProjectDetailsBackendError') return await this.throw(response, 'getProjectDetailsBackendError')
@ -959,8 +966,12 @@ export default class RemoteBackend extends Backend {
override async getFileDetails( override async getFileDetails(
fileId: backend.FileId, fileId: backend.FileId,
title: string, title: string,
getPresignedUrl = false,
): Promise<backend.FileDetails> { ): Promise<backend.FileDetails> {
const path = remoteBackendPaths.getFileDetailsPath(fileId) const searchParams = new URLSearchParams({
presigned: `${getPresignedUrl}`,
}).toString()
const path = `${remoteBackendPaths.getFileDetailsPath(fileId)}?${searchParams}`
const response = await this.get<backend.FileDetails>(path) const response = await this.get<backend.FileDetails>(path)
if (!responseIsSuccessful(response)) { if (!responseIsSuccessful(response)) {
return await this.throw(response, 'getFileDetailsBackendError', title) return await this.throw(response, 'getFileDetailsBackendError', title)