-
Notifications
You must be signed in to change notification settings - Fork 30
Fixes attachment handling in client side aasx handling #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6112199
Fixes attachment handling in client side aasx handling
aaronzi d46e67e
Adresses review remarks
aaronzi 698b2ad
Addresses safeSegment remarks
aaronzi 8194357
Fixes supplementaryPart review remark
aaronzi dccc0a2
Addresses fetchThumbnailPart remark
aaronzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import type { Part } from 'aasx-package-ts'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| buildAttachmentSmePath, | ||
| normalizePackagePath, | ||
| packagePathCandidates, | ||
| pickSupplementaryPart, | ||
| } from '@/composables/AAS/AASXImport'; | ||
|
|
||
| type MinimalPart = Pick<Part, 'URI'>; | ||
|
|
||
| function partWithPath(path: string): MinimalPart { | ||
| return { | ||
| URI: new URL(`https://package.local${path}`), | ||
| }; | ||
| } | ||
|
|
||
| describe('AASXImport.ts; pure helper tests', () => { | ||
| it('builds client import SME attachment path with dot-separated idShort segments', () => { | ||
| const smEndpoint = 'https://example.test/submodels/encoded-submodel-id'; | ||
| const idShortPath = ['Documents', 'Manual', 'Pdf File']; | ||
|
|
||
| const path = buildAttachmentSmePath(smEndpoint, idShortPath); | ||
|
|
||
| expect(path).toBe( | ||
| 'https://example.test/submodels/encoded-submodel-id/submodel-elements/Documents.Manual.Pdf%20File' | ||
| ); | ||
| }); | ||
|
|
||
| it('normalizes package path by trimming, removing query, and adding leading slash', () => { | ||
| const normalized = normalizePackagePath(' aasx-suppl/file.png?cache=1 '); | ||
|
|
||
| expect(normalized).toBe('/aasx-suppl/file.png'); | ||
| }); | ||
|
|
||
| it('creates decoded package path candidates for encoded path segments', () => { | ||
| const candidates = packagePathCandidates('/aasx-suppl/Markings%5B0%5D.png'); | ||
|
|
||
| expect(candidates).toContain('/aasx-suppl/Markings%5B0%5D.png'); | ||
| expect(candidates).toContain('/aasx-suppl/Markings[0].png'); | ||
| }); | ||
|
|
||
| it('matches supplementary parts whose filenames were sanitized during packaging', () => { | ||
| const supplementaryMap = new Map<string, Part>(); | ||
| const packagedPart = partWithPath( | ||
| '/aasx-suppl/aHR0cHM6Ly9hZG1pbi1zaGVsbC5pby9pZHRhL1N1Ym1vZGVsVGVtcGxhdGUvRGlnaXRhbE5hbWVwbGF0ZS8zLzA-Markings-0-.MarkingFile-Schwindegg.png' | ||
| ); | ||
| supplementaryMap.set(packagedPart.URI.pathname, packagedPart as Part); | ||
|
|
||
| const foundPart = pickSupplementaryPart( | ||
| 'aHR0cHM6Ly9hZG1pbi1zaGVsbC5pby9pZHRhL1N1Ym1vZGVsVGVtcGxhdGUvRGlnaXRhbE5hbWVwbGF0ZS8zLzA-Markings[0].MarkingFile-Schwindegg.png', | ||
| supplementaryMap | ||
| ); | ||
|
|
||
| expect(foundPart).toBe(packagedPart as Part); | ||
| }); | ||
|
|
||
| it('returns null when filename-only matching would be ambiguous', () => { | ||
| const supplementaryMap = new Map<string, Part>(); | ||
| const firstPart = partWithPath('/aasx-suppl/folderA/shared.png'); | ||
| const secondPart = partWithPath('/aasx-suppl/folderB/shared.png'); | ||
| supplementaryMap.set(firstPart.URI.pathname, firstPart as Part); | ||
| supplementaryMap.set(secondPart.URI.pathname, secondPart as Part); | ||
|
|
||
| const foundPart = pickSupplementaryPart('shared.png', supplementaryMap); | ||
|
|
||
| expect(foundPart).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { resolveAttachmentFetchPath, resolveAttachmentFilename } from '@/composables/AAS/AASXPackaging'; | ||
|
|
||
| describe('AASXPackaging.ts; pure helper tests', () => { | ||
| it('preserves repository attachment fetch path for download packaging', () => { | ||
| const path = ' https://example.test/submodels/abc/submodel-elements/Documents.Manual.Pdf%20File '; | ||
|
|
||
| const fetchPath = resolveAttachmentFetchPath(path); | ||
|
|
||
| expect(fetchPath).toBe('https://example.test/submodels/abc/submodel-elements/Documents.Manual.Pdf%20File'); | ||
| }); | ||
|
|
||
| it('sanitizes filename derived from file.value to match package path rules', () => { | ||
| const file = { | ||
| value: 'aHR0cHM6Ly9hZG1pbi1zaGVsbC5pby9pZHRhL1N1Ym1vZGVsVGVtcGxhdGUvRGlnaXRhbE5hbWVwbGF0ZS8zLzA-Markings[0].MarkingFile-Schwindegg.png', | ||
| idShort: 'MarkingFile', | ||
| }; | ||
|
|
||
| const fileName = resolveAttachmentFilename(file, 0, 'image/png'); | ||
|
|
||
| expect(fileName).toBe( | ||
| 'aHR0cHM6Ly9hZG1pbi1zaGVsbC5pby9pZHRhL1N1Ym1vZGVsVGVtcGxhdGUvRGlnaXRhbE5hbWVwbGF0ZS8zLzA-Markings-0-.MarkingFile-Schwindegg.png' | ||
| ); | ||
| }); | ||
|
|
||
| it('falls back to sanitized idShort and extension when value has no filename extension', () => { | ||
| const file = { | ||
| value: 'urn:example:attachment', | ||
| idShort: 'Manual File', | ||
| }; | ||
|
|
||
| const fileName = resolveAttachmentFilename(file, 1, 'application/pdf'); | ||
|
|
||
| expect(fileName).toBe('Manual-File-2.pdf'); | ||
| }); | ||
|
|
||
| it('falls back to generic file prefix when idShort is empty', () => { | ||
| const file = { | ||
| value: 'urn:example:attachment', | ||
| idShort: '', | ||
| }; | ||
|
|
||
| const fileName = resolveAttachmentFilename(file, 2, 'image/png'); | ||
|
|
||
| expect(fileName).toBe('file-3-3.png'); | ||
| }); | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.