Skip to content
Merged
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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/viewer-init.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* extracted by css-entry-points-plugin */
@import './init-Bw8QmU3q.chunk.css';
@import './init-DcwdQ_Lh.chunk.css';
@import './previewUtils-CU5qdRbf.chunk.css';
@import './NcIconSvgWrapper-Bui9PhAS-3xIBDiQU.chunk.css';
@import './NcActionButton-BjaRp7qa.chunk.css';
Expand Down
2 changes: 1 addition & 1 deletion js/viewer-init.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-init.mjs.map

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion playwright/e2e/actions/edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/e2e-test-server'
import type { Page } from '@playwright/test'

import { expect, setupFilesPage, test } from '../../support/fixtures.ts'
import { getRowForFile, openFile } from '../../support/filesUtils.ts'
import { getCloseButton, getEditButton, getViewer, getViewerName } from '../../support/viewerUtils.ts'
import { getFileContents } from '../../support/webdav.ts'

test.describe.serial('Open the new saved as image', () => {
let page: Page
let user: User

test.beforeAll(async ({ browser }) => {
({ page } = await setupFilesPage(browser, [{ fixture: 'image1.jpg', mimeType: 'image/jpeg' }]))
({ page, user } = await setupFilesPage(browser, [
{ fixture: 'image1.jpg', mimeType: 'image/jpeg' },
// Cameras name their files in uppercase
{ fixture: 'image1.jpg', mimeType: 'image/jpeg', target: '/ABC1234.JPG' },
{ fixture: 'image1.jpg', mimeType: 'image/jpeg', target: '/ABC1234.JPEG' },
]))
})

test.afterAll(async () => {
Expand Down Expand Up @@ -51,4 +59,34 @@ test.describe.serial('Open the new saved as image', () => {
test('See the new saved image in the list', async () => {
await expect(getRowForFile(page, 'imageSave.jpg')).toContainText('imageSave .jpg')
})

for (const [sourceName, savedName] of [
['ABC1234.JPG', 'imageSaveUppercase.JPG'],
['ABC1234.JPEG', 'imageSaveUppercase.JPEG'],
] as const) {
test(`Save ${sourceName} as a JPEG`, async () => {
await openFile(page, sourceName)
await getEditButton(page).click()
await page.locator('.FIE_topbar-save-button').click()

const nameInput = page.locator('input[type="text"].SfxInput-Base')
await nameInput.clear()
await nameInput.fill(savedName.slice(0, savedName.lastIndexOf('.')))

const upload = page.waitForResponse((response) => response.request().method() === 'PUT'
&& decodeURIComponent(new URL(response.url()).pathname).endsWith(`/${savedName}`))
await page.locator('.SfxModal-Container button[color="primary"].SfxButton-root')
.filter({ hasText: 'Save' })
.click()

expect((await upload).ok()).toBe(true)

// JPEG magic bytes, not PNG's
const saved = await getFileContents(user, `/${savedName}`)
expect(saved.subarray(0, 2)).toEqual(Buffer.from([0xFF, 0xD8]))

await page.locator('.FIE_topbar-close-button').click()
await getCloseButton(page).click()
})
}
})
17 changes: 17 additions & 0 deletions playwright/support/webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ export async function uploadFile(
}
}

/**
* Download a file from the user's DAV root.
*
* @param user the file owner
* @param target the DAV path relative to the user root
*/
export async function getFileContents(user: User, target: string): Promise<Buffer> {
const api = await getUserApi(user)
try {
const response = await api.get(davPath(user, target))
expect(response.ok(), `download of ${target} expected 2xx, got ${response.status()}`).toBeTruthy()
return await response.body()
} finally {
await api.dispose()
}
}

/**
* Create a folder in the user's DAV root (MKCOL).
*
Expand Down
5 changes: 3 additions & 2 deletions src/components/ImageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ export default {
}
}

// toBlob is not very smart...
mimeType = mimeType.replace('jpg', 'jpeg')
// toBlob is not very smart: it takes neither image/jpg nor an
// uppercase type like image/JPG, and silently falls back to PNG
mimeType = mimeType.toLowerCase().replace('jpg', 'jpeg')

// Sanity check, 0 < quality < 1
quality = Math.max(Math.min(quality, 1), 0) || 1
Expand Down
Loading