viewer icon indicating copy to clipboard operation
viewer copied to clipboard

Fix regression: Use Photos preview API for that webdav collection

Open pulsejet opened this issue 3 years ago • 6 comments

Fixes a regression where the viewer cannot show any photos from collaborative albums, since these previews are not accessible over the core API.

I unfortunately introduced this while fixing another regression in #1409 😩 Any better ideas to do this? Using the source image directly isn't right because it might be huge (plus no support for HEIC/TIFF), so this seems like the better option.

pulsejet avatar Oct 19 '22 02:10 pulsejet

@skjnldsv @szaimen

pulsejet avatar Oct 20 '22 21:10 pulsejet

Sorry, I dont feel capable reviewing this.

szaimen avatar Oct 20 '22 22:10 szaimen

Maybe @ChristophWurst can help?

pulsejet avatar Oct 20 '22 22:10 pulsejet

@pulsejet don't ping random devs please :) I'll review it later

skjnldsv avatar Oct 21 '22 07:10 skjnldsv

Apologies. He authored the commit that got broken (https://github.com/nextcloud/viewer/commit/a05dbf35c05c77efbc273986bcd92c89ee745499) so I thought he might know better.

pulsejet avatar Oct 21 '22 07:10 pulsejet

Would it make sense to address this problem in a way that callers can decide how to provide preview urls for special cases instead of hard-coding the logic?

E.g.:

OCA.Viewer.open({
    ...
    previewUrl: ({ fileid, public, width, height }) => {
        return !public && generateUrl(`/apps/photos/api/v1/preview/${fileid}?x=${width}&y=${height}`)
    },
    ...
})

getPreviewIfAny({ fileid, filename, hasPreview, davPath }) {
    const width = Math.floor(screen.width * devicePixelRatio)
    const height = Math.floor(screen.height * devicePixelRatio)
    const searchParams = `fileId=${fileid}`
        + `&x=${width}`
        + `&y=${height}`
        + '&a=true'

    if (hasPreview) {
        const args = { fileid, filename, width, height, public: isPublic(), token: getToken() }
        const url = typeof this.previewUrl == 'function' && this.previewUrl(args)
        if (typeof url == 'string') {
            return url
        }

        // TODO: find a nicer standard way of doing this?
        if (isPublic()) {
            return generateUrl(`/apps/files_sharing/publicpreview/${getToken()}?file=${encodeFilePath(filename)}&${searchParams}`)
        }
...

jkellerer avatar Oct 26 '22 14:10 jkellerer

Just an update here. Currently nothing is broken, it's just not idea as we load bigger pictures in photos.

I'm still not ok with adding custom app-oriented conditions in Viewer. I'm still thinking about how to better approach this.

skjnldsv avatar Nov 08 '22 14:11 skjnldsv

Currently nothing is broken

Do you mean https://github.com/nextcloud/photos/issues/1440 is fixed? That's what this PR was meant to address.

I'm still not ok with adding custom app-oriented conditions in Viewer. I'm still thinking about how to better approach this.

Yeah it's not ideal at all. I just submitted this patch as a quick fix.

pulsejet avatar Nov 08 '22 23:11 pulsejet

@pulsejet if the source is provided, it should be rendered. We fixed that in photos I think?

@artonge are we providing a source property for collaborative albums?

skjnldsv avatar Nov 09 '22 10:11 skjnldsv

Currently nothing is broken, it's just not idea as we load bigger pictures in photos.

@skjnldsv @artonge I just want to point out that things are broken (this is latest stable25). Everyone doesn't use JPEG :)

ss1

Also closely related, with a lot of upvotes: https://github.com/nextcloud/photos/issues/1452 There's no clean way to fix that one in viewer at all (had a go at it), since the token isn't exposed globally as a variable. So I agree this isn't the correct solution to the problem 👍🏻

ss2

pulsejet avatar Dec 09 '22 16:12 pulsejet

Closing for https://github.com/nextcloud/viewer/pull/1525

skjnldsv avatar Jan 24 '23 16:01 skjnldsv