-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add sse item renamed event (#10567)
* Add sse item renamed event
- web-test-helpers-v11.0.6
- web-test-helpers-v11.0.5
- web-test-helpers-v11.0.4
- web-test-helpers-v11.0.3
- web-test-helpers-v11.0.2
- web-test-helpers-v11.0.1
- web-test-helpers-v11.0.0
- web-test-helpers-v11.0.0-alpha.1
- web-test-helpers-v10.3.0
- web-test-helpers-v0.1.0
- web-pkg-v11.0.6
- web-pkg-v11.0.5
- web-pkg-v11.0.4
- web-pkg-v11.0.3
- web-pkg-v11.0.2
- web-pkg-v11.0.1
- web-pkg-v11.0.0
- web-pkg-v11.0.0-alpha.1
- web-pkg-v10.3.0
- web-pkg-v10.2.0
- web-pkg-v10.1.0
- web-pkg-v10.1.0-alpha.1
- web-pkg-v10.0.0
- web-pkg-v0.0.6
- web-client-v11.0.6
- web-client-v11.0.5
- web-client-v11.0.4
- web-client-v11.0.3
- web-client-v11.0.2
- web-client-v11.0.1
- web-client-v11.0.0
- web-client-v11.0.0-alpha.1
- web-client-v10.3.0
- web-client-v10.2.0
- web-client-v10.1.0
- web-client-v10.1.0-alpha.1
- web-client-v10.0.0
- web-client-v0.0.3
- web-client-v0.0.2
- v11.0.6
- v11.0.5
- v11.0.4
- v11.0.3
- v11.0.2
- v11.0.1
- v11.0.0
- v11.0.0-alpha.1
- v10.3.0
- v10.2.0
- v10.1.0
- v10.0.0
- v9.2.0-alpha.1
- v9.1.0
- v9.1.0-alpha.1
- v9.0.0
- v9.0.0-alpha.7
- v9.0.0-alpha.6
- v9.0.0-alpha.5
- v9.0.0-alpha.4
- v9.0.0-alpha.3
- v9.0.0-alpha.2
- tsconfig-v0.0.6
- extension-sdk-v11.0.6
- extension-sdk-v11.0.5
- extension-sdk-v11.0.4
- extension-sdk-v11.0.3
- extension-sdk-v11.0.2
- extension-sdk-v11.0.1
- extension-sdk-v11.0.0
- extension-sdk-v0.0.7
- extension-sdk-v0.0.6
- eslint-config-v11.0.6
- eslint-config-v11.0.5
- eslint-config-v11.0.4
- eslint-config-v11.0.3
- eslint-config-v11.0.2
- eslint-config-v11.0.1
- eslint-config-v11.0.0
- eslint-config-v11.0.0-alpha.1
- eslint-config-v10.3.0
- design-system-v11.0.6
- design-system-v11.0.5
- design-system-v11.0.4
- design-system-v11.0.3
- design-system-v11.0.2
- design-system-v11.0.1
- design-system-v11.0.0
- design-system-v11.0.0-alpha.1
- design-system-v10.3.0
- 10.1.0-alpha.1
1 parent
befe172
commit a6a9c29
Showing
4 changed files
with
195 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { | ||
ClientService, | ||
createFileRouteOptions, | ||
ImageDimension, | ||
PreviewService, | ||
ResourcesStore, | ||
SpacesStore | ||
} from '@ownclouders/web-pkg' | ||
import PQueue from 'p-queue' | ||
import { extractNodeId, extractStorageId } from '@ownclouders/web-client/src/helpers' | ||
import { z } from 'zod' | ||
import { Router } from 'vue-router' | ||
|
||
const fileReadyEventSchema = z.object({ | ||
itemid: z.string(), | ||
parentitemid: z.string() | ||
}) | ||
|
||
type SSEMessageData = { | ||
itemid?: string | ||
parentitemid?: string | ||
} | ||
|
||
const itemInCurrentFolder = ({ | ||
resourcesStore, | ||
sseData | ||
}: { | ||
resourcesStore: ResourcesStore | ||
sseData: SSEMessageData | ||
}) => { | ||
const currentFolder = resourcesStore.currentFolder | ||
if (!currentFolder) { | ||
return false | ||
} | ||
|
||
if (!extractNodeId(currentFolder.id)) { | ||
// if we don't have a nodeId here, we have a space (root) as current folder and can only check against the storageId | ||
if (currentFolder.id !== extractStorageId(sseData.parentitemid)) { | ||
return false | ||
} | ||
} else { | ||
if (currentFolder.id !== sseData.parentitemid) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
export const onSSEItemRenamedEvent = async ({ | ||
resourcesStore, | ||
spacesStore, | ||
msg, | ||
clientService, | ||
router | ||
}: { | ||
resourcesStore: ResourcesStore | ||
spacesStore: SpacesStore | ||
msg: MessageEvent | ||
clientService: ClientService | ||
router: Router | ||
}) => { | ||
try { | ||
const sseData = fileReadyEventSchema.parse(JSON.parse(msg.data)) | ||
|
||
const currentFolder = resourcesStore.currentFolder | ||
const resourceIsCurrentFolder = currentFolder.id === sseData.itemid | ||
|
||
if (!resourceIsCurrentFolder && !itemInCurrentFolder({ resourcesStore, sseData })) { | ||
return false | ||
} | ||
|
||
const resource = resourceIsCurrentFolder | ||
? currentFolder | ||
: resourcesStore.resources.find((f) => f.id === sseData.itemid) | ||
|
||
const space = spacesStore.spaces.find((s) => s.id === resource.storageId) | ||
|
||
if (!resource || !space) { | ||
return | ||
} | ||
|
||
const updatedResource = await clientService.webdav.getFileInfo(space, { | ||
fileId: sseData.itemid | ||
}) | ||
|
||
if (resourceIsCurrentFolder) { | ||
resourcesStore.setCurrentFolder(updatedResource) | ||
return router.push( | ||
createFileRouteOptions(space, { | ||
path: updatedResource.path, | ||
fileId: updatedResource.fileId | ||
}) | ||
) | ||
} | ||
|
||
resourcesStore.updateResourceField({ | ||
id: sseData.itemid, | ||
field: 'name', | ||
value: updatedResource.name | ||
}) | ||
|
||
resourcesStore.updateResourceField({ | ||
id: sseData.itemid, | ||
field: 'path', | ||
value: updatedResource.path | ||
}) | ||
} catch (e) { | ||
console.error('Unable to parse sse event item renamed data', e) | ||
} | ||
} | ||
export const onSSEProcessingFinishedEvent = async ({ | ||
resourcesStore, | ||
spacesStore, | ||
msg, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
clientService, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
resourceQueue, | ||
previewService | ||
}: { | ||
resourcesStore: ResourcesStore | ||
spacesStore: SpacesStore | ||
msg: MessageEvent | ||
clientService: ClientService | ||
resourceQueue: PQueue | ||
previewService: PreviewService | ||
}) => { | ||
try { | ||
const sseData = fileReadyEventSchema.parse(JSON.parse(msg.data)) | ||
|
||
if (!itemInCurrentFolder({ resourcesStore, sseData })) { | ||
return false | ||
} | ||
|
||
const resource = resourcesStore.resources.find((f) => f.id === sseData.itemid) | ||
const space = spacesStore.spaces.find((s) => s.id === resource.storageId) | ||
const isFileLoaded = !!resource | ||
|
||
if (isFileLoaded) { | ||
resourcesStore.updateResourceField({ | ||
id: sseData.itemid, | ||
field: 'processing', | ||
value: false | ||
}) | ||
|
||
if (space) { | ||
const preview = await previewService.loadPreview({ | ||
resource, | ||
space, | ||
dimensions: ImageDimension.Thumbnail | ||
}) | ||
|
||
if (preview) { | ||
resourcesStore.updateResourceField({ | ||
id: sseData.itemid, | ||
field: 'thumbnail', | ||
value: preview | ||
}) | ||
} | ||
} | ||
} else { | ||
// FIXME: we currently cannot do this, we need to block this for ongoing uploads and copy operations | ||
// when fixing revert the changelog removal | ||
// resourceQueue.add(async () => { | ||
// const { resource } = await clientService.webdav.listFilesById({ | ||
// fileId: sseData.itemid | ||
// }) | ||
// resource.path = urlJoin(currentFolder.path, resource.name) | ||
// resourcesStore.upsertResource(resource) | ||
// }) | ||
} | ||
} catch (e) { | ||
console.error('Unable to parse sse event postprocessing-finished data', e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters