Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/web-client/src/helpers/space/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function buildPublicSpaceResource(
const publicLinkShareDate = data.props?.[DavProperty.PublicLinkShareDate]
const publicLinkShareOwner = data.props?.[DavProperty.PublicLinkShareOwner]
const publicLinkShareOwnerDisplayName = data.props?.[DavProperty.OwnerDisplayName]
const spaceId = data.props?.[DavProperty.SpaceId]

let driveAlias
let webDavPath
Expand Down Expand Up @@ -97,7 +98,8 @@ export function buildPublicSpaceResource(
...(publicLinkExpiration && { publicLinkExpiration }),
...(publicLinkShareDate && { publicLinkShareDate }),
...(publicLinkShareOwner && { publicLinkShareOwner }),
...(publicLinkShareOwnerDisplayName && { publicLinkShareOwnerDisplayName })
...(publicLinkShareOwnerDisplayName && { publicLinkShareOwnerDisplayName }),
...(spaceId && { spaceId })
}
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/web-client/src/helpers/space/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface PublicSpaceResource extends SpaceResource {
publicLinkShareDate?: string
publicLinkShareOwner?: string
publicLinkShareOwnerDisplayName?: string
spaceId?: string
}
export const isPublicSpaceResource = (resource: Resource): resource is PublicSpaceResource => {
return (resource as SpaceResource)?.driveType === 'public'
Expand Down
8 changes: 6 additions & 2 deletions packages/web-client/src/webdav/constants/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ const DavPropertyMapping = {
PublicLinkPermission: defString('public-link-permission' as const),
PublicLinkExpiration: defString('public-link-expiration' as const),
PublicLinkShareDate: defString('public-link-share-datetime' as const),
PublicLinkShareOwner: defString('public-link-share-owner' as const)
PublicLinkShareOwner: defString('public-link-share-owner' as const),
SpaceId: defString('spaceid' as const)
} as const satisfies Record<string, M<unknown, unknown>>

type DavPropertyMappingType = typeof DavPropertyMapping
Expand Down Expand Up @@ -156,7 +157,10 @@ export abstract class DavProperties {
DavProperty.PublicLinkPermission,
DavProperty.PublicLinkExpiration,
DavProperty.PublicLinkShareDate,
DavProperty.PublicLinkShareOwner
DavProperty.PublicLinkShareOwner,
DavProperty.SpaceId,
DavProperty.FileId,
DavProperty.FileParent
])

static readonly Trashbin: DavPropertyValue[] = [
Expand Down
17 changes: 17 additions & 0 deletions packages/web-pkg/src/services/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class ClientService {
'X-Requested-With': 'XMLHttpRequest'
}

public sseUnAuthenticated?: EventSource

constructor(options: ClientServiceOptions) {
this.configStore = options.configStore
this.language = options.language
Expand Down Expand Up @@ -188,4 +190,19 @@ export class ClientService {

return Promise.reject(error)
}

initSseUnAuthenticated(publicLinkToken: string, publicLinkPassword?: string) {
this.sseUnAuthenticated = sse(this.configStore.serverUrl, {
headers: {
'Accept-Language': this.currentLanguage,
'X-Request-ID': uuidV4(),
'X-Requested-With': 'XMLHttpRequest',
'public-token': publicLinkToken,
...(publicLinkPassword && {
Authorization:
'Basic ' + Buffer.from(['public', publicLinkPassword].join(':')).toString('base64')
})
}
})
}
}
53 changes: 33 additions & 20 deletions packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,9 @@ export const registerSSEEventListeners = ({
previewService,
configStore,
userStore,
router
router,
publicLinkToken,
publicLinkPassword
}: {
language: Language
resourcesStore: ResourcesStore
Expand All @@ -752,6 +754,8 @@ export const registerSSEEventListeners = ({
configStore: ConfigStore
userStore: UserStore
router: Router
publicLinkToken?: string
publicLinkPassword?: string
}): void => {
const resourceQueue = new PQueue({
concurrency: configStore.options.concurrentRequests.sse
Expand All @@ -778,7 +782,16 @@ export const registerSSEEventListeners = ({
resourceQueue
} satisfies Partial<SseEventWrapperOptions>

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RENAMED, (msg) =>
let sse: EventSource

if (publicLinkToken) {
clientService.initSseUnAuthenticated(publicLinkToken, publicLinkPassword)
sse = clientService.sseUnAuthenticated
} else {
sse = clientService.sseAuthenticated
}

sse.addEventListener(MESSAGE_TYPE.ITEM_RENAMED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_RENAMED,
msg,
Expand All @@ -787,7 +800,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.POSTPROCESSING_FINISHED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.POSTPROCESSING_FINISHED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.POSTPROCESSING_FINISHED,
msg,
Expand All @@ -796,7 +809,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FILE_LOCKED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.FILE_LOCKED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.FILE_LOCKED,
msg,
Expand All @@ -805,7 +818,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FILE_UNLOCKED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.FILE_UNLOCKED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.FILE_UNLOCKED,
msg,
Expand All @@ -814,7 +827,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_TRASHED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.ITEM_TRASHED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_TRASHED,
msg,
Expand All @@ -823,7 +836,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RESTORED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.ITEM_RESTORED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_RESTORED,
msg,
Expand All @@ -832,7 +845,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_MOVED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.ITEM_MOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.ITEM_MOVED,
msg,
Expand All @@ -841,7 +854,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FOLDER_CREATED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.FOLDER_CREATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.FOLDER_CREATED,
msg,
Expand All @@ -850,7 +863,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.FILE_TOUCHED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.FILE_TOUCHED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.FILE_TOUCHED,
msg,
Expand All @@ -859,7 +872,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SPACE_MEMBER_ADDED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.SPACE_MEMBER_ADDED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SPACE_MEMBER_ADDED,
msg,
Expand All @@ -868,7 +881,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SPACE_MEMBER_REMOVED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.SPACE_MEMBER_REMOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SPACE_MEMBER_REMOVED,
msg,
Expand All @@ -877,7 +890,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SPACE_SHARE_UPDATED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.SPACE_SHARE_UPDATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SPACE_SHARE_UPDATED,
msg,
Expand All @@ -886,7 +899,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SHARE_CREATED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.SHARE_CREATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SHARE_CREATED,
msg,
Expand All @@ -895,7 +908,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SHARE_REMOVED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.SHARE_REMOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SHARE_REMOVED,
msg,
Expand All @@ -904,7 +917,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.SHARE_UPDATED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.SHARE_UPDATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.SHARE_UPDATED,
msg,
Expand All @@ -913,7 +926,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.LINK_CREATED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.LINK_CREATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.LINK_CREATED,
msg,
Expand All @@ -922,7 +935,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.LINK_REMOVED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.LINK_REMOVED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.LINK_REMOVED,
msg,
Expand All @@ -931,7 +944,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.LINK_UPDATED, (msg) =>
sse.addEventListener(MESSAGE_TYPE.LINK_UPDATED, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.LINK_UPDATED,
msg,
Expand All @@ -940,7 +953,7 @@ export const registerSSEEventListeners = ({
})
)

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.BACKCHANNEL_LOGOUT, (msg) =>
sse.addEventListener(MESSAGE_TYPE.BACKCHANNEL_LOGOUT, (msg) =>
sseEventWrapper({
topic: MESSAGE_TYPE.BACKCHANNEL_LOGOUT,
msg,
Expand Down
45 changes: 38 additions & 7 deletions packages/web-runtime/src/container/sse/files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createFileRouteOptions, ImageDimension } from '@ownclouders/web-pkg'
import { SSEEventOptions } from './types'
import { isItemInCurrentFolder } from './helpers'
import { isPublicSpaceResource } from '@ownclouders/web-client'

export const onSSEItemRenamedEvent = async ({
sseData,
Expand All @@ -23,7 +24,13 @@ export const onSSEItemRenamedEvent = async ({
if (!resource) {
return
}
const space = spacesStore.spaces.find((s) => s.id === resource.storageId)
const space = spacesStore.spaces.find((s) => {
if (isPublicSpaceResource(s)) {
return s.spaceId === resource.storageId
}

return s.id === resource.storageId
})

if (!space) {
return
Expand Down Expand Up @@ -54,7 +61,12 @@ export const onSSEFileLockingEvent = async ({
clientService
}: SSEEventOptions) => {
const resource = resourcesStore.resources.find((f) => f.id === sseData.itemid)
const space = spacesStore.spaces.find((s) => s.id === resource?.storageId)
const space = spacesStore.spaces.find((s) => {
if (isPublicSpaceResource(s)) {
return s.spaceId === resource?.storageId
}
return s.id === resource?.storageId
})

if (!resource || !space) {
return
Expand All @@ -80,7 +92,12 @@ export const onSSEProcessingFinishedEvent = async ({
return false
}
const resource = resourcesStore.resources.find((f) => f.id === sseData.itemid)
const space = spacesStore.spaces.find((s) => s.id === sseData.spaceid)
const space = spacesStore.spaces.find((s) => {
if (isPublicSpaceResource(s)) {
return s.spaceId === sseData.spaceid
}
return s.id === sseData.spaceid
})
if (!space) {
return
}
Expand Down Expand Up @@ -187,7 +204,12 @@ export const onSSEItemRestoredEvent = async ({
return
}

const space = spacesStore.spaces.find((space) => space.id === sseData.spaceid)
const space = spacesStore.spaces.find((space) => {
if (isPublicSpaceResource(space)) {
return space.spaceId === sseData.spaceid
}
return space.id === sseData.spaceid
})
if (!space) {
return
}
Expand Down Expand Up @@ -257,7 +279,12 @@ export const onSSEFileTouchedEvent = async ({
return
}

const space = spacesStore.spaces.find((space) => space.id === sseData.spaceid)
const space = spacesStore.spaces.find((space) => {
if (isPublicSpaceResource(space)) {
return space.spaceId === sseData.spaceid
}
return space.id === sseData.spaceid
})
if (!space) {
return
}
Expand Down Expand Up @@ -289,7 +316,12 @@ export const onSSEFolderCreatedEvent = async ({
return
}

const space = spacesStore.spaces.find((space) => space.id === sseData.spaceid)
const space = spacesStore.spaces.find((space) => {
if (isPublicSpaceResource(space)) {
return space.spaceId === sseData.spaceid
}
return space.id === sseData.spaceid
})
if (!space) {
return
}
Expand All @@ -298,7 +330,6 @@ export const onSSEFolderCreatedEvent = async ({
path: '',
fileId: sseData.itemid
})

if (!resource) {
return
}
Expand Down
Loading