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
e903edf
refactor(AttachmentService): Some code style cleanup
mejo- Oct 25, 2023
8682d60
chore(attachments): Remove support for obsolete `text://` format
mejo- Oct 31, 2023
75ec895
feat(attachments): API endpoint to get list of attachments for a docu…
mejo- Oct 25, 2023
264aa76
chore(attachments): Remove obsolete metadata API endpoint
mejo- Nov 15, 2023
2f78829
feat(attachments): Use getAttachmentList API endpoint in resolver
mejo- Oct 31, 2023
b288c85
fix(attachment): Remove candidate logic from ImageView node
mejo- Nov 15, 2023
13cea83
fix(attachments): Fix some issues with the showimage modal
mejo- Nov 21, 2023
d8842a6
chore(attachments): Remove obsolete code
mejo- Nov 21, 2023
0bc3556
feat(editor): Allow to pass fileId to MarkdownContentEditor
mejo- Nov 21, 2023
0f2b874
feat(attachments): Allow to get attachments without document session
mejo- Nov 22, 2023
9b9e876
chore(attachments): Remove special-handling for preview URLs
mejo- Nov 22, 2023
d95d6b2
fix(attachments): Open non-image attachments in viewer or download
mejo- Nov 22, 2023
337724d
fix(AttachmentController): Set fileName of returned attachments
mejo- Nov 27, 2023
7a32d8e
chore(composer): Update autoloader maps
mejo- Nov 27, 2023
597b8d5
fix(attachments): Fix encoding of attachment URI component
mejo- Nov 27, 2023
98a47c3
test(cy): Test to open image in modal and download attachment
mejo- Nov 28, 2023
adf5fe8
chore(middleware): Rename to RequireDocumentSessionOrUserOrShareToken
mejo- Nov 28, 2023
88c8810
fix(attachments): use `getRelativePath` from userFolder for `davPath`
mejo- Nov 28, 2023
6864890
test(AttachmentResolver): Refactor jest tests after parent class refa…
mejo- Nov 28, 2023
6a46001
fix(attachments): Show all loaded images in ShowImageModal
mejo- Nov 28, 2023
e632d72
fix(SessionMiddleware): Check if user/share have access to document
mejo- Nov 29, 2023
b3be90a
fix(AttachmentResolver): Require either fileId or session
mejo- Nov 29, 2023
e391298
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- authored and backportbot-nextcloud[bot] committed Nov 29, 2023
commit 8682d60d0c14e8f643913f14d4c0b9a12d201838
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