Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndBear committed Mar 12, 2024
1 parent 3b044fe commit 0cc2f1f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/web-client/src/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export enum MESSAGE_TYPE {
POSTPROCESSING_FINISHED = 'postprocessing-finished',
ITEM_RENAMED = 'item-renamed',
FILE_LOCKED = 'file-locked',
FILE_UNLOCKED = 'file-unlocked'
FILE_UNLOCKED = 'file-unlocked',
ITEM_RENAMED = 'item-renamed',
ITEM_TRASHED = 'item-trashed',
ITEM_RESTORED = 'item-restored'
}

export class RetriableError extends Error {
Expand Down
25 changes: 24 additions & 1 deletion packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ import {
RawConfigSchema,
SentryConfig
} from '@ownclouders/web-pkg/src/composables/piniaStores/config/types'
import { onSSEFileLockingEvent, onSSEItemRenamedEvent, onSSEProcessingFinishedEvent } from './sse'
import {
onSSEFileLockingEvent,
onSSEItemRenamedEvent,
onSSEProcessingFinishedEvent,
onSSEItemRestoredEvent,
onSSEItemTrashedEvent
} from './sse'

const getEmbedConfigFromQuery = (
doesEmbedEnabledOptionExists: boolean
Expand Down Expand Up @@ -707,6 +713,23 @@ export const registerSSEEventListeners = ({
clientService
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_TRASHED, (msg) =>
onSSEItemTrashedEvent({
resourcesStore,
msg
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RESTORED, (msg) =>
onSSEItemRestoredEvent({
resourcesStore,
spacesStore,
msg,
clientService,
previewService
})
)
}

export const setViewOptions = ({ resourcesStore }: { resourcesStore: ResourcesStore }) => {
Expand Down
90 changes: 87 additions & 3 deletions packages/web-runtime/src/container/sse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ClientService,
createFileRouteOptions,
getIndicators,
ImageDimension,
PreviewService,
ResourcesStore,
Expand Down Expand Up @@ -161,7 +160,6 @@ export const onSSEProcessingFinishedEvent = async ({
if (!itemInCurrentFolder({ resourcesStore, parentFolderId: sseData.parentitemid })) {
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
Expand Down Expand Up @@ -200,6 +198,92 @@ export const onSSEProcessingFinishedEvent = async ({
// })
}
} catch (e) {
console.error(`Unable to parse sse event ${topic} data`, e)
console.error('Unable to parse sse event postprocessing-finished data', e)
}
}

export const onSSEItemTrashedEvent = ({
resourcesStore,
msg
}: {
resourcesStore: ResourcesStore
msg: MessageEvent
}) => {
try {
const sseData = fileReadyEventSchema.parse(JSON.parse(msg.data))

console.log(resourcesStore.currentFolder)

const resource = resourcesStore.resources.find((f) => f.id === sseData.itemid)

if (!resource) {
return
}

resourcesStore.removeResources([resource])
} catch (e) {
console.error('Unable to parse sse event item-trashed data', e)
}
}

export const onSSEItemRestoredEvent = async ({
resourcesStore,
spacesStore,
msg,
clientService,
previewService
}: {
resourcesStore: ResourcesStore
spacesStore: SpacesStore
msg: MessageEvent
clientService: ClientService
previewService: PreviewService
}) => {
try {
const sseData = fileReadyEventSchema.parse(JSON.parse(msg.data))

const space = spacesStore.personalSpace

if (!space) {
return
}

const resource = await clientService.webdav.getFileInfo(space, {
fileId: sseData.itemid
})

if (!resource) {
return
}

if (!itemInCurrentFolder({ resourcesStore, parentFolderId: resource.parentFolderId })) {
return false
}

resourcesStore.upsertResource(resource)
resourcesStore.updateResourceField({
id: resource.id,
field: 'indicators',
value: getIndicators({
resource,
ancestorMetaData: resourcesStore.ancestorMetaData
})
})

const preview = await previewService.loadPreview({
resource,
space,
dimensions: ImageDimension.Thumbnail
})

if (preview) {
resourcesStore.updateResourceField({
id: resource.id,
field: 'thumbnail',
value: preview
})
}
} catch (e) {
console.error('Unable to parse sse event item-restored data', e)
}
}

0 comments on commit 0cc2f1f

Please sign in to comment.