Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
271a59a
refactor(AttachmentService): Some code style cleanup
mejo- Oct 25, 2023
df3e4df
chore(attachments): Remove support for obsolete `text://` format
mejo- Oct 31, 2023
8c1c6e8
feat(attachments): API endpoint to get list of attachments for a docu…
mejo- Oct 25, 2023
73cb49b
chore(attachments): Remove obsolete metadata API endpoint
mejo- Nov 15, 2023
153a85f
feat(attachments): Use getAttachmentList API endpoint in resolver
mejo- Oct 31, 2023
680ca1d
fix(attachment): Remove candidate logic from ImageView node
mejo- Nov 15, 2023
86e2b97
fix(attachments): Fix some issues with the showimage modal
mejo- Nov 21, 2023
b274e37
chore(attachments): Remove obsolete code
mejo- Nov 21, 2023
a2813ae
feat(editor): Allow to pass fileId to MarkdownContentEditor
mejo- Nov 21, 2023
bd54a68
feat(attachments): Allow to get attachments without document session
mejo- Nov 22, 2023
d15781c
chore(attachments): Remove special-handling for preview URLs
mejo- Nov 22, 2023
e4108d4
fix(attachments): Open non-image attachments in viewer or download
mejo- Nov 22, 2023
98ba0de
fix(AttachmentController): Set fileName of returned attachments
mejo- Nov 27, 2023
dade37e
chore(composer): Update autoloader maps
mejo- Nov 27, 2023
7743591
fix(attachments): Fix encoding of attachment URI component
mejo- Nov 27, 2023
ec91074
test(cy): Test to open image in modal and download attachment
mejo- Nov 28, 2023
b01c547
chore(middleware): Rename to RequireDocumentSessionOrUserOrShareToken
mejo- Nov 28, 2023
a1f8308
fix(attachments): use `getRelativePath` from userFolder for `davPath`
mejo- Nov 28, 2023
3ce2e44
test(AttachmentResolver): Refactor jest tests after parent class refa…
mejo- Nov 28, 2023
6796170
fix(attachments): Show all loaded images in ShowImageModal
mejo- Nov 28, 2023
c7e0cf0
fix(SessionMiddleware): Check if user/share have access to document
mejo- Nov 29, 2023
978cbc6
fix(AttachmentResolver): Require either fileId or session
mejo- Nov 29, 2023
77a0d4a
reactor(ImageView): Simplify attachmentType/isMediaAttachment logic
mejo- Nov 29, 2023
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
Prev Previous commit
Next Next commit
chore(attachments): Remove support for obsolete text:// format
This format was only used from 03.01.2022 to 23.05.2022.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Nov 29, 2023
commit df3e4dff7ebea649e9251cd79f9fc290298eb71a
19 changes: 1 addition & 18 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,21 +588,6 @@ public function cleanupAttachments(int $fileId): int {
* @return array
*/
public static function getAttachmentNamesFromContent(string $content, int $fileId): array {
$oldMatches = [];
preg_match_all(
// simple version with .+ between the brackets
// '/\!\[.+\]\(text:\/\/image\?[^)]*imageFileName=([^)&]+)\)/',
// complex version of php-markdown
// matches ![ANY_CONSIDERED_CORRECT_BY_PHP-MARKDOWN](text://image?ANYTHING&imageFileName=FILE_NAME) and captures FILE_NAME
'/\!\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[(?>[^\[\]]+|\[\])*\])*\])*\])*\])*\])*\]\(text:\/\/image\?[^)]*imageFileName=([^)&]+)\)/',
$content,
$oldMatches,
PREG_SET_ORDER
);
$oldNames = array_map(static function (array $match) {
return urldecode($match[1]);
}, $oldMatches);

$matches = [];
// matches ![ANY_CONSIDERED_CORRECT_BY_PHP-MARKDOWN](.attachments.DOCUMENT_ID/ANY_FILE_NAME) and captures FILE_NAME
preg_match_all(
Expand All @@ -611,11 +596,9 @@ public static function getAttachmentNamesFromContent(string $content, int $fileI
$matches,
PREG_SET_ORDER
);
$names = array_map(static function (array $match) {
return array_map(static function (array $match) {
return urldecode($match[1]);
}, $matches);

return array_merge($names, $oldNames);
}

/**
Expand Down
15 changes: 0 additions & 15 deletions src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ export default class AttachmentResolver {
* Currently returns either one or two urls.
*/
async resolve(src, preferRawImage = false) {
if (this.#session && src.startsWith('text://')) {
const imageFileName = getQueryVariable(src, 'imageFileName')
return [{
type: this.ATTACHMENT_TYPE_IMAGE,
url: this.#getImageAttachmentUrl(imageFileName, preferRawImage),
}]
}

// Has session and URL points to attachment from current document
if (this.#session && src.startsWith(`.attachments.${this.#session?.documentId}/`)) {
const imageFileName = decodeURIComponent(src.replace(`.attachments.${this.#session?.documentId}/`, '').split('?')[0])
Expand Down Expand Up @@ -253,13 +245,6 @@ export default class AttachmentResolver {
* @param {string} src - url to extract path from
*/
#relativePath(src) {
if (src.startsWith('text://')) {
return [
this.#attachmentDirectory,
getQueryVariable(src, 'imageFileName'),
].join('/')
}

return decodeURI(src.split('?')[0])
}

Expand Down
56 changes: 0 additions & 56 deletions src/tests/services/AttachmentResolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,6 @@ describe('Image resolver', () => {
expect(resolver).toBeInstanceOf(AttachmentResolver)
})

it('handles text:// urls via Text API', async () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new AttachmentResolver({ session })
const [candidate] = await resolver.resolve(src)
expect(candidate.type).toBe('image')
expect(candidate.url).toBe('/nc-webroot/apps/text/image?documentId=4173&sessionId=456&sessionToken=mySessionToken&imageFileName=group%20pic.jpg&preferRawImage=0')
})

it('handles text:// urls with token via Text API', async () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new AttachmentResolver({
session,
shareToken: 'myShareToken',
})
const [candidate] = await resolver.resolve(src)
expect(candidate.type).toBe('image')
expect(candidate.url).toBe('/nc-webroot/apps/text/image?documentId=4173&sessionId=456&sessionToken=mySessionToken&imageFileName=group%20pic.jpg&shareToken=myShareToken&preferRawImage=0')
})

it('uses user auth over token auth', async () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new AttachmentResolver({
session,
user,
shareToken: 'myShareToken',
})
const [candidate] = await resolver.resolve(src)
expect(candidate.type).toBe('image')
expect(candidate.url).not.toContain('myShareToken')
})

it('handles .attachments urls to own fileId via Text API', async () => {
const src = `.attachments.${session.documentId}/group%20pic.jpg`
const resolver = new AttachmentResolver({ session })
Expand Down Expand Up @@ -146,31 +115,6 @@ describe('Image resolver', () => {
})

describe('missing session', () => {

it('resolves text:// urls as authenticated dav', async () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new AttachmentResolver({
fileId: 4173,
user,
currentDirectory,
})
const [candidate] = await resolver.resolve(src)
expect(candidate.type).toBe('image')
expect(candidate.url).toBe('http://localhost/nc-webroot/remote.php/dav/files/user-uid/parentDir/.attachments.4173/group%20pic.jpg')
})

it('resolves text:// urls as share token download', async () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new AttachmentResolver({
fileId,
shareToken,
currentDirectory,
})
const [candidate] = await resolver.resolve(src)
expect(candidate.type).toBe('image')
expect(candidate.url).toBe('/nc-webroot/s/myShareToken/download?path=%2FparentDir%2F.attachments.4173&files=group%20pic.jpg')
})

it('handles .attachments urls via webdav with mimetype URL fallback', async () => {
const src = `.attachments.${session.documentId + 1}/group%20pic.jpg`
const resolver = new AttachmentResolver({ user, currentDirectory, fileId })
Expand Down
17 changes: 0 additions & 17 deletions tests/unit/Service/AttachmentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,6 @@ public function testDummy() {
$this->assertEquals('text', $app::APP_NAME);
}

public function testGetOldAttachmentNamesFromContent() {
$content = "some content\n";
foreach (self::$attachmentNames as $name) {
// this is how it's generated in MenuBar.vue
$linkText = preg_replace('/[[\]]/', '', $name);
$encodedName = urlencode($name);
$content .= '![' . $linkText . '](text://image?imageFileName=' . $encodedName . ")\n";
}
$content .= 'some content';

$computedNames = AttachmentService::getAttachmentNamesFromContent($content, 33);
foreach (self::$attachmentNames as $contentName) {
$this->assertContains($contentName, $computedNames);
}
}


public function testGetAttachmentNamesFromContent() {
$content = "some content\n";
foreach (self::$attachmentNames as $name) {
Expand Down