Skip to content

Commit

Permalink
Fix relative paths causing issues with attachments
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Haeuslmann <[email protected]>
  • Loading branch information
mihaeu committed Aug 25, 2021
1 parent f7265be commit 97f358d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
84 changes: 62 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,122 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.14.1] - 2021-08-25

### Fixed

- Fixed relative parts in attachments causing issues. Now `../../example.png` will be flattened to `___example.png`.

## [0.14.0] - 2021-03-05

### Added
- Support for rendering `<details>` blocks [as Confluence expand macros](https://confluence.atlassian.com/doc/expand-macro-223222352.html)

- Support for rendering `<details>` blocks [as Confluence expand macros](https://confluence.atlassian.com/doc/expand-macro-223222352.html)

## [0.13.3] - 2021-02-10

## [0.13.2] - 2021-02-10

### Fixed
- Upgrade dependencies in order to fix vulnerabilities
- Write self-closing tags for Confluence compatibility (e.g. `<hr />`)

- Upgrade dependencies in order to fix vulnerabilities
- Write self-closing tags for Confluence compatibility (e.g. `<hr />`)

## [0.13.1] - 2020-07-06

### Fixed
- Moved jest and prettier to dev dependencies

- Moved jest and prettier to dev dependencies

## [0.13.0] - 2020-07-04

### Fixed
- Added retry for a weird confluence bug where the first attempt would result in a 501 response, and the second one works

- Added retry for a weird confluence bug where the first attempt would result in a 501 response, and the second one works

## [0.12.3] - 2019-12-27

### Fixed
- Bug where error was thrown if not language was supplied for language block

- Bug where error was thrown if not language was supplied for language block

## [0.12.2] - 2019-12-23

### Fixed
- Print proper URL after successful upload

- Print proper URL after successful upload

## [0.12.1] - 2019-12-23

### Fixed
- Do not use newline for extracted title (fixes [#1](https://github.com/mihaeu/cosmere/issues/1))

- Do not use newline for extracted title (fixes [#1](https://github.com/mihaeu/cosmere/issues/1))

## [0.12.0] - 2019-12-23

### Added
- Print link to confluence page after successful upload

- Print link to confluence page after successful upload

### Fixed
- Set highlighting for known languages
- Use only first line of title
- Remote diff

- Set highlighting for known languages
- Use only first line of title
- Remote diff

## [0.11.0] - 2019-12-20

### Changed
- renaming to cosmere, all binaries, config entries etc. changed

- renaming to cosmere, all binaries, config entries etc. changed

# [0.10.0] - 2019-12-18

### Changed
- `pageTitle` config item is now optional if a level one header is found in the corresponding document. If neither is available an error is thrown.

- `pageTitle` config item is now optional if a level one header is found in the corresponding document. If neither is available an error is thrown.

## [0.9.0] - 2019-12-07

### Fixed
- Convert to storage representation directly instead of view to upload strings without encoding
- Always load markdown files relative to the config file

- Convert to storage representation directly instead of view to upload strings without encoding
- Always load markdown files relative to the config file

## [0.8.1] - 2019-12-03

### Fixed
- Attachment upload

- Attachment upload

## [0.8.0] - 2019-12-03

### Added
- This changelog file

- This changelog file

### Changed
- Update remote version only if there's an actual change

- Update remote version only if there's an actual change

### Fixed
- Attachment upload

- Attachment upload

## [0.7.0] - 2019-12-02

### Changed
- Add backward compatibility for node 8 (`fs.mkdir`)

[Unreleased]: https://github.com/mihaeu/cosmere/compare/0.14.0...HEAD
- Add backward compatibility for node 8 (`fs.mkdir`)

[unreleased]: https://github.com/mihaeu/cosmere/compare/0.14.1...HEAD
[0.14.1]: https://github.com/mihaeu/cosmere/compare/0.14.0...0.14.1
[0.14.0]: https://github.com/mihaeu/cosmere/compare/0.13.3...0.14.0
[0.13.3]: https://github.com/mihaeu/cosmere/compare/0.13.2...0.13.3
[0.13.2]: https://github.com/mihaeu/cosmere/compare/0.13.1...0.13.2
Expand Down
6 changes: 4 additions & 2 deletions src/UpdatePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ async function updateAttachments(mdWikiData: string, pageData: Page, cachePath:
signale.error(`Attachment "${attachment}" not found.`);
});
for (const attachment of attachments) {
const newFilename = cachePath + "/" + attachment.replace("/..", "_").replace("/", "_");
const newFilename = cachePath + "/" + attachment.replace(/(\.\.|\/)/g, "_");
const absoluteAttachmentPath = path.resolve(path.dirname(pageData.file), attachment);
fs.copyFileSync(absoluteAttachmentPath, newFilename);

signale.await(`Uploading attachment "${attachment}" for "${pageData.title}" ...`);
await confluenceAPI.uploadAttachment(newFilename, pageData.pageId);
}
mdWikiData = mdWikiData.replace(/<ri:attachment ri:filename=".+?"/g, (s: string) => s.replace("/", "_"));
mdWikiData = mdWikiData.replace(/<ri:attachment ri:filename=".+?"/g, (s: string) =>
s.replace(/(\.\.|\/)/g, "_"),
);
}
return mdWikiData;
}
Expand Down

0 comments on commit 97f358d

Please sign in to comment.